Skip to content

Commit e6d11f6

Browse files
committed
Improved executed types
1 parent 2f6ddd7 commit e6d11f6

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

graphql/execution/executor.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def execute(
6666
allow_subscriptions=False, # type: bool
6767
**options # type: Any
6868
):
69-
# type: (...) -> ExecutionResult
69+
# type: (...) -> Union[ExecutionResult, Promise[ExecutionResult]]
7070

7171
if root is None and "root_value" in options:
7272
warnings.warn(
@@ -120,16 +120,16 @@ def execute(
120120
)
121121

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

126126
def on_rejected(error):
127-
# type: (Exception) -> Optional[Any]
127+
# type: (Exception) -> None
128128
exe_context.errors.append(error)
129129
return None
130130

131131
def on_resolve(data):
132-
# type: (Union[None, OrderedDict, Observable]) -> Union[ExecutionResult, Observable]
132+
# type: (Union[None, Dict, Observable]) -> Union[ExecutionResult, Observable]
133133
if isinstance(data, Observable):
134134
return data
135135

@@ -158,7 +158,7 @@ def execute_operation(
158158
operation, # type: OperationDefinition
159159
root_value, # type: Any
160160
):
161-
# type: (...) -> Union[OrderedDict, Promise]
161+
# type: (...) -> Union[Dict, Promise[Dict]]
162162
type = get_operation_root_type(exe_context.schema, operation)
163163
fields = collect_fields(
164164
exe_context, type, operation.selection_set, DefaultOrderedDict(list), set()
@@ -188,7 +188,7 @@ def execute_fields_serially(
188188
):
189189
# type: (...) -> Promise
190190
def execute_field_callback(results, response_name):
191-
# type: (OrderedDict, str) -> Union[OrderedDict, Promise]
191+
# type: (Dict, str) -> Union[Dict, Promise[Dict]]
192192
field_asts = fields[response_name]
193193
result = resolve_field(
194194
exe_context,
@@ -204,7 +204,7 @@ def execute_field_callback(results, response_name):
204204
if is_thenable(result):
205205

206206
def collect_result(resolved_result):
207-
# type: (OrderedDict) -> OrderedDict
207+
# type: (Dict) -> Dict
208208
results[response_name] = resolved_result
209209
return results
210210

@@ -232,7 +232,7 @@ def execute_fields(
232232
path, # type: List[Union[int, str]]
233233
info, # type: Optional[ResolveInfo]
234234
):
235-
# type: (...) -> Union[OrderedDict, Promise]
235+
# type: (...) -> Union[Dict, Promise[Dict]]
236236
contains_promise = False
237237

238238
final_results = OrderedDict()
@@ -271,10 +271,8 @@ def subscribe_fields(
271271
def on_error(error):
272272
subscriber_exe_context.report_error(error)
273273

274-
def map_result(
275-
data # type: Union[Dict[str, None], Dict[str, OrderedDict], Dict[str, str]]
276-
):
277-
# type: (...) -> ExecutionResult
274+
def map_result(data):
275+
# type: (Dict[str, Any]) -> ExecutionResult
278276
if subscriber_exe_context.errors:
279277
result = ExecutionResult(data=data, errors=subscriber_exe_context.errors)
280278
else:

graphql/graphql.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
# Necessary for static type checking
77
if False: # flake8: noqa
8+
from promise import Promise
89
from rx import Observable
910
from typing import Any, Union, Optional
1011
from .language.ast import Document
@@ -35,7 +36,7 @@
3536

3637

3738
def graphql(*args, **kwargs):
38-
# type: (*Any, **Any) -> Union[ExecutionResult, Observable]
39+
# type: (*Any, **Any) -> Union[ExecutionResult, Observable, Promise[ExecutionResult]]
3940
return_promise = kwargs.get("return_promise", False)
4041
if return_promise:
4142
return execute_graphql_as_promise(*args, **kwargs)
@@ -54,7 +55,7 @@ def execute_graphql(
5455
backend=None, # type: Optional[Any]
5556
**execute_options # type: Any
5657
):
57-
# type: (...) -> Union[ExecutionResult, Observable]
58+
# type: (...) -> Union[ExecutionResult, Observable, Promise[ExecutionResult]]
5859
try:
5960
if backend is None:
6061
backend = get_default_backend()

0 commit comments

Comments
 (0)