Skip to content

Commit

Permalink
Improved executed types
Browse files Browse the repository at this point in the history
  • Loading branch information
syrusakbary committed Jul 2, 2018
1 parent 2f6ddd7 commit e6d11f6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
22 changes: 10 additions & 12 deletions graphql/execution/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def execute(
allow_subscriptions=False, # type: bool
**options # type: Any
):
# type: (...) -> ExecutionResult
# type: (...) -> Union[ExecutionResult, Promise[ExecutionResult]]

if root is None and "root_value" in options:
warnings.warn(
Expand Down Expand Up @@ -120,16 +120,16 @@ def execute(
)

def promise_executor(v):
# type: (Optional[Any]) -> Union[OrderedDict, Promise, Observable]
# type: (Optional[Any]) -> Union[Dict, Promise[Dict], Observable]
return execute_operation(exe_context, exe_context.operation, root)

def on_rejected(error):
# type: (Exception) -> Optional[Any]
# type: (Exception) -> None
exe_context.errors.append(error)
return None

def on_resolve(data):
# type: (Union[None, OrderedDict, Observable]) -> Union[ExecutionResult, Observable]
# type: (Union[None, Dict, Observable]) -> Union[ExecutionResult, Observable]
if isinstance(data, Observable):
return data

Expand Down Expand Up @@ -158,7 +158,7 @@ def execute_operation(
operation, # type: OperationDefinition
root_value, # type: Any
):
# type: (...) -> Union[OrderedDict, Promise]
# type: (...) -> Union[Dict, Promise[Dict]]
type = get_operation_root_type(exe_context.schema, operation)
fields = collect_fields(
exe_context, type, operation.selection_set, DefaultOrderedDict(list), set()
Expand Down Expand Up @@ -188,7 +188,7 @@ def execute_fields_serially(
):
# type: (...) -> Promise
def execute_field_callback(results, response_name):
# type: (OrderedDict, str) -> Union[OrderedDict, Promise]
# type: (Dict, str) -> Union[Dict, Promise[Dict]]
field_asts = fields[response_name]
result = resolve_field(
exe_context,
Expand All @@ -204,7 +204,7 @@ def execute_field_callback(results, response_name):
if is_thenable(result):

def collect_result(resolved_result):
# type: (OrderedDict) -> OrderedDict
# type: (Dict) -> Dict
results[response_name] = resolved_result
return results

Expand Down Expand Up @@ -232,7 +232,7 @@ def execute_fields(
path, # type: List[Union[int, str]]
info, # type: Optional[ResolveInfo]
):
# type: (...) -> Union[OrderedDict, Promise]
# type: (...) -> Union[Dict, Promise[Dict]]
contains_promise = False

final_results = OrderedDict()
Expand Down Expand Up @@ -271,10 +271,8 @@ def subscribe_fields(
def on_error(error):
subscriber_exe_context.report_error(error)

def map_result(
data # type: Union[Dict[str, None], Dict[str, OrderedDict], Dict[str, str]]
):
# type: (...) -> ExecutionResult
def map_result(data):
# type: (Dict[str, Any]) -> ExecutionResult
if subscriber_exe_context.errors:
result = ExecutionResult(data=data, errors=subscriber_exe_context.errors)
else:
Expand Down
5 changes: 3 additions & 2 deletions graphql/graphql.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

# Necessary for static type checking
if False: # flake8: noqa
from promise import Promise
from rx import Observable
from typing import Any, Union, Optional
from .language.ast import Document
Expand Down Expand Up @@ -35,7 +36,7 @@


def graphql(*args, **kwargs):
# type: (*Any, **Any) -> Union[ExecutionResult, Observable]
# type: (*Any, **Any) -> Union[ExecutionResult, Observable, Promise[ExecutionResult]]
return_promise = kwargs.get("return_promise", False)
if return_promise:
return execute_graphql_as_promise(*args, **kwargs)
Expand All @@ -54,7 +55,7 @@ def execute_graphql(
backend=None, # type: Optional[Any]
**execute_options # type: Any
):
# type: (...) -> Union[ExecutionResult, Observable]
# type: (...) -> Union[ExecutionResult, Observable, Promise[ExecutionResult]]
try:
if backend is None:
backend = get_default_backend()
Expand Down

0 comments on commit e6d11f6

Please sign in to comment.