@@ -252,7 +252,7 @@ def build_response(
252
252
"""
253
253
if self .is_awaitable (data ):
254
254
255
- async def build_response_async ():
255
+ async def build_response_async () -> ExecutionResult :
256
256
return self .build_response (await data ) # type: ignore
257
257
258
258
return build_response_async ()
@@ -285,6 +285,7 @@ def execute_operation(
285
285
#
286
286
# Similar to complete_value_catching_error.
287
287
try :
288
+ # noinspection PyArgumentList
288
289
result = (
289
290
self .execute_fields_serially
290
291
if operation .operation == OperationType .MUTATION
@@ -296,7 +297,7 @@ def execute_operation(
296
297
else :
297
298
if self .is_awaitable (result ):
298
299
# noinspection PyShadowingNames
299
- async def await_result ():
300
+ async def await_result () -> Any :
300
301
try :
301
302
return await result # type: ignore
302
303
except GraphQLError as error :
@@ -316,7 +317,7 @@ def execute_fields_serially(
316
317
317
318
Implements the "Evaluating selection sets" section of the spec for "write" mode.
318
319
"""
319
- results : Dict [str , Any ] = {}
320
+ results : AwaitableOrValue [ Dict [str , Any ] ] = {}
320
321
is_awaitable = self .is_awaitable
321
322
for response_name , field_nodes in fields .items ():
322
323
field_path = Path (path , response_name )
@@ -327,30 +328,36 @@ def execute_fields_serially(
327
328
continue
328
329
if is_awaitable (results ):
329
330
# noinspection PyShadowingNames
330
- async def await_and_set_result (results , response_name , result ):
331
+ async def await_and_set_result (
332
+ results : Awaitable [Dict [str , Any ]],
333
+ response_name : str ,
334
+ result : AwaitableOrValue [Any ],
335
+ ) -> Dict [str , Any ]:
331
336
awaited_results = await results
332
337
awaited_results [response_name ] = (
333
338
await result if is_awaitable (result ) else result
334
339
)
335
340
return awaited_results
336
341
337
- # noinspection PyTypeChecker
338
342
results = await_and_set_result (
339
343
cast (Awaitable , results ), response_name , result
340
344
)
341
345
elif is_awaitable (result ):
342
346
# noinspection PyShadowingNames
343
- async def set_result (results , response_name , result ):
347
+ async def set_result (
348
+ results : Dict [str , Any ], response_name : str , result : Awaitable ,
349
+ ) -> Dict [str , Any ]:
344
350
results [response_name ] = await result
345
351
return results
346
352
347
- # noinspection PyTypeChecker
348
- results = set_result (results , response_name , result )
353
+ results = set_result (
354
+ cast (Dict [str , Any ], results ), response_name , result
355
+ )
349
356
else :
350
- results [response_name ] = result
357
+ cast ( Dict [ str , Any ], results ) [response_name ] = result
351
358
if is_awaitable (results ):
352
359
# noinspection PyShadowingNames
353
- async def get_results ():
360
+ async def get_results () -> Any :
354
361
return await cast (Awaitable , results )
355
362
356
363
return get_results ()
@@ -389,7 +396,7 @@ def execute_fields(
389
396
# field, which is possibly a coroutine object. Return a coroutine object that
390
397
# will yield this same map, but with any coroutines awaited in parallel and
391
398
# replaced with the values they yielded.
392
- async def get_results ():
399
+ async def get_results () -> Dict [ str , Any ] :
393
400
results .update (
394
401
zip (
395
402
awaitable_fields ,
@@ -579,7 +586,7 @@ def resolve_field_value_or_error(
579
586
result = resolve_fn (source , info , ** args )
580
587
if self .is_awaitable (result ):
581
588
# noinspection PyShadowingNames
582
- async def await_result ():
589
+ async def await_result () -> Any :
583
590
try :
584
591
return await result
585
592
except GraphQLError as error :
@@ -607,10 +614,11 @@ def complete_value_catching_error(
607
614
This is a small wrapper around completeValue which detects and logs errors in
608
615
the execution context.
609
616
"""
617
+ completed : AwaitableOrValue [Any ]
610
618
try :
611
619
if self .is_awaitable (result ):
612
620
613
- async def await_result ():
621
+ async def await_result () -> Any :
614
622
value = self .complete_value (
615
623
return_type , field_nodes , info , path , await result
616
624
)
@@ -625,7 +633,7 @@ async def await_result():
625
633
)
626
634
if self .is_awaitable (completed ):
627
635
# noinspection PyShadowingNames
628
- async def await_completed ():
636
+ async def await_completed () -> Any :
629
637
try :
630
638
return await completed
631
639
except Exception as error :
@@ -783,7 +791,7 @@ def complete_list_value(
783
791
return completed_results
784
792
785
793
# noinspection PyShadowingNames
786
- async def get_completed_results ():
794
+ async def get_completed_results () -> Any :
787
795
for index , result in zip (
788
796
awaitable_indices ,
789
797
await gather (
@@ -828,7 +836,7 @@ def complete_abstract_value(
828
836
829
837
if self .is_awaitable (runtime_type ):
830
838
831
- async def await_complete_object_value ():
839
+ async def await_complete_object_value () -> Any :
832
840
value = self .complete_object_value (
833
841
self .ensure_valid_runtime_type (
834
842
await runtime_type , # type: ignore
@@ -912,14 +920,14 @@ def complete_object_value(
912
920
913
921
if self .is_awaitable (is_type_of ):
914
922
915
- async def collect_and_execute_subfields_async ():
923
+ async def collect_and_execute_subfields_async () -> Dict [ str , Any ] :
916
924
if not await is_type_of : # type: ignore
917
925
raise invalid_return_type_error (
918
926
return_type , result , field_nodes
919
927
)
920
928
return self .collect_and_execute_subfields (
921
929
return_type , field_nodes , path , result
922
- )
930
+ ) # type: ignore
923
931
924
932
return collect_and_execute_subfields_async ()
925
933
@@ -1158,11 +1166,12 @@ def default_type_resolver(
1158
1166
1159
1167
if awaitable_is_type_of_results :
1160
1168
# noinspection PyShadowingNames
1161
- async def get_type ():
1169
+ async def get_type () -> Optional [ Union [ GraphQLObjectType , str ]] :
1162
1170
is_type_of_results = await gather (* awaitable_is_type_of_results )
1163
1171
for is_type_of_result , type_ in zip (is_type_of_results , awaitable_types ):
1164
1172
if is_type_of_result :
1165
1173
return type_
1174
+ return None
1166
1175
1167
1176
return get_type ()
1168
1177
0 commit comments