1313
1414import six
1515
16- from promise import promisify , is_thenable
16+ from promise import promisify , is_thenable , Promise
1717
1818from graphql import get_default_backend
1919from graphql .error import format_error as default_format_error
@@ -266,6 +266,7 @@ def execute_graphql_request(
266266 backend = None , # type: GraphQLBackend
267267 ** kwargs # type: Any
268268):
269+ # type: (...) -> ExecutionResult
269270 """Execute a GraphQL request and return an ExecutionResult.
270271
271272 You need to pass the GraphQL schema and the GraphQLParams that you can get
@@ -318,18 +319,18 @@ def get_response(
318319 allow_only_query = False , # type: bool
319320 ** kwargs # type: Any
320321):
321- # type: (...) -> Optional[ExecutionResult]
322+ # type: (...) -> Optional[Union[ ExecutionResult, Promise[ExecutionResult]] ]
322323 """Get an individual execution result as response, with option to catch errors.
323324
324325 This does the same as execute_graphql_request() except that you can catch errors
325326 that belong to an exception class that you need to pass as a parameter.
326327 """
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+
327333 # noinspection PyBroadException
328- execute = (
329- execute_graphql_request_as_promise
330- if kwargs .get ("return_promise" , False )
331- else execute_graphql_request
332- )
333334 try :
334335 execution_result = execute (schema , params , allow_only_query , ** kwargs )
335336 except catch_exc :
@@ -350,11 +351,10 @@ def format_execution_result(
350351 """
351352 status_code = 200
352353
354+ response = None
353355 if execution_result :
354356 if execution_result .invalid :
355357 status_code = 400
356358 response = execution_result .to_dict (format_error = format_error )
357- else :
358- response = None
359359
360360 return FormattedResult (response , status_code )
0 commit comments