13
13
14
14
import six
15
15
16
- from promise import promisify , is_thenable
16
+ from promise import promisify , is_thenable , Promise
17
17
18
18
from graphql import get_default_backend
19
19
from graphql .error import format_error as default_format_error
@@ -266,6 +266,7 @@ def execute_graphql_request(
266
266
backend = None , # type: GraphQLBackend
267
267
** kwargs # type: Any
268
268
):
269
+ # type: (...) -> ExecutionResult
269
270
"""Execute a GraphQL request and return an ExecutionResult.
270
271
271
272
You need to pass the GraphQL schema and the GraphQLParams that you can get
@@ -318,18 +319,18 @@ def get_response(
318
319
allow_only_query = False , # type: bool
319
320
** kwargs # type: Any
320
321
):
321
- # type: (...) -> Optional[ExecutionResult]
322
+ # type: (...) -> Optional[Union[ ExecutionResult, Promise[ExecutionResult]] ]
322
323
"""Get an individual execution result as response, with option to catch errors.
323
324
324
325
This does the same as execute_graphql_request() except that you can catch errors
325
326
that belong to an exception class that you need to pass as a parameter.
326
327
"""
328
+ # Note: PyCharm will display a error due to the triple dot being used on Callable.
329
+ execute = execute_graphql_request # type: Callable[..., Union[Promise[ExecutionResult], ExecutionResult]]
330
+ if kwargs .get ("return_promise" , False ):
331
+ execute = execute_graphql_request_as_promise
332
+
327
333
# noinspection PyBroadException
328
- execute = (
329
- execute_graphql_request_as_promise
330
- if kwargs .get ("return_promise" , False )
331
- else execute_graphql_request
332
- )
333
334
try :
334
335
execution_result = execute (schema , params , allow_only_query , ** kwargs )
335
336
except catch_exc :
@@ -350,11 +351,10 @@ def format_execution_result(
350
351
"""
351
352
status_code = 200
352
353
354
+ response = None
353
355
if execution_result :
354
356
if execution_result .invalid :
355
357
status_code = 400
356
358
response = execution_result .to_dict (format_error = format_error )
357
- else :
358
- response = None
359
359
360
360
return FormattedResult (response , status_code )
0 commit comments