47
47
def subscribe (* args , ** kwargs ):
48
48
# type: (*Any, **Any) -> Union[ExecutionResult, Observable]
49
49
allow_subscriptions = kwargs .pop ("allow_subscriptions" , True )
50
- return execute (* args , allow_subscriptions = allow_subscriptions , ** kwargs )
50
+ return execute ( # type: ignore
51
+ * args , allow_subscriptions = allow_subscriptions , ** kwargs
52
+ )
51
53
52
54
53
55
def execute (
@@ -116,7 +118,7 @@ def execute(
116
118
allow_subscriptions ,
117
119
)
118
120
119
- def executor (v ):
121
+ def promise_executor (v ):
120
122
# type: (Optional[Any]) -> Union[OrderedDict, Promise, Observable]
121
123
return execute_operation (exe_context , exe_context .operation , root )
122
124
@@ -135,7 +137,9 @@ def on_resolve(data):
135
137
136
138
return ExecutionResult (data = data , errors = exe_context .errors )
137
139
138
- promise = Promise .resolve (None ).then (executor ).catch (on_rejected ).then (on_resolve )
140
+ promise = (
141
+ Promise .resolve (None ).then (promise_executor ).catch (on_rejected ).then (on_resolve )
142
+ )
139
143
140
144
if not return_promise :
141
145
exe_context .executor .wait_until_finished ()
@@ -151,7 +155,7 @@ def on_resolve(data):
151
155
def execute_operation (
152
156
exe_context , # type: ExecutionContext
153
157
operation , # type: OperationDefinition
154
- root_value , # type: Union[None, Data, type]
158
+ root_value , # type: Any
155
159
):
156
160
# type: (...) -> Union[OrderedDict, Promise]
157
161
type = get_operation_root_type (exe_context .schema , operation )
@@ -224,7 +228,7 @@ def execute_fields(
224
228
parent_type , # type: GraphQLObjectType
225
229
source_value , # type: Any
226
230
fields , # type: DefaultOrderedDict
227
- path , # type: Union[ List[Union[int, str]], List[ str]]
231
+ path , # type: List[Union[int, str]]
228
232
info , # type: Optional[ResolveInfo]
229
233
):
230
234
# type: (...) -> Union[OrderedDict, Promise]
@@ -257,39 +261,43 @@ def execute_fields(
257
261
def subscribe_fields (
258
262
exe_context , # type: ExecutionContext
259
263
parent_type , # type: GraphQLObjectType
260
- source_value , # type: Union[None, Data, type]
264
+ source_value , # type: Any
261
265
fields , # type: DefaultOrderedDict
262
266
):
263
267
# type: (...) -> Observable
264
- exe_context = SubscriberExecutionContext (exe_context )
268
+ subscriber_exe_context = SubscriberExecutionContext (exe_context )
265
269
266
270
def on_error (error ):
267
- exe_context .report_error (error )
271
+ subscriber_exe_context .report_error (error )
268
272
269
273
def map_result (
270
274
data # type: Union[Dict[str, None], Dict[str, OrderedDict], Dict[str, str]]
271
275
):
272
276
# type: (...) -> ExecutionResult
273
- if exe_context .errors :
274
- result = ExecutionResult (data = data , errors = exe_context .errors )
277
+ if subscriber_exe_context .errors :
278
+ result = ExecutionResult (data = data , errors = subscriber_exe_context .errors )
275
279
else :
276
280
result = ExecutionResult (data = data )
277
- exe_context .reset ()
281
+ subscriber_exe_context .reset ()
278
282
return result
279
283
280
- observables = []
284
+ observables = [] # type: List[Observable]
281
285
282
286
# assert len(fields) == 1, "Can only subscribe one element at a time."
283
287
284
288
for response_name , field_asts in fields .items ():
285
289
result = subscribe_field (
286
- exe_context , parent_type , source_value , field_asts , [response_name ]
290
+ subscriber_exe_context ,
291
+ parent_type ,
292
+ source_value ,
293
+ field_asts ,
294
+ [response_name ],
287
295
)
288
296
if result is Undefined :
289
297
continue
290
298
291
299
def catch_error (error ):
292
- exe_context .errors .append (error )
300
+ subscriber_exe_context .errors .append (error )
293
301
return Observable .just (None )
294
302
295
303
# Map observable results
@@ -305,10 +313,10 @@ def catch_error(error):
305
313
def resolve_field (
306
314
exe_context , # type: ExecutionContext
307
315
parent_type , # type: GraphQLObjectType
308
- source , # type: Union[None, Cat, Dog]
316
+ source , # type: Any
309
317
field_asts , # type: List[Field]
310
318
parent_info , # type: Optional[ResolveInfo]
311
- field_path , # type: Union[ List[Union[int, str]], List[ str]]
319
+ field_path , # type: List[Union[int, str]]
312
320
):
313
321
# type: (...) -> Any
314
322
field_ast = field_asts [0 ]
@@ -360,7 +368,7 @@ def resolve_field(
360
368
def subscribe_field (
361
369
exe_context , # type: SubscriberExecutionContext
362
370
parent_type , # type: GraphQLObjectType
363
- source , # type: Union[None, Data, type]
371
+ source , # type: Any
364
372
field_asts , # type: List[Field]
365
373
path , # type: List[str]
366
374
):
@@ -430,12 +438,12 @@ def subscribe_field(
430
438
431
439
def resolve_or_error (
432
440
resolve_fn , # type: Callable
433
- source , # type: Union[None, Cat, Dog]
441
+ source , # type: Any
434
442
info , # type: ResolveInfo
435
443
args , # type: Dict
436
- executor , # type: Union[BaseExecutor, SyncExecutor]
444
+ executor , # type: Any
437
445
):
438
- # type: (...) -> Union[List[Union[Cat, Dog]], bool, str]
446
+ # type: (...) -> Any
439
447
try :
440
448
return executor .execute (resolve_fn , source , info , ** args )
441
449
except Exception as e :
@@ -444,7 +452,7 @@ def resolve_or_error(
444
452
info .parent_type .name , info .field_name
445
453
)
446
454
)
447
- e .stack = sys .exc_info ()[2 ]
455
+ e .stack = sys .exc_info ()[2 ] # type: ignore
448
456
return e
449
457
450
458
@@ -453,10 +461,10 @@ def complete_value_catching_error(
453
461
return_type , # type: Any
454
462
field_asts , # type: List[Field]
455
463
info , # type: ResolveInfo
456
- path , # type: Union[ List[Union[int, str]], List[ str]]
464
+ path , # type: List[Union[int, str]]
457
465
result , # type: Any
458
466
):
459
- # type: (...) -> Union[bool, str]
467
+ # type: (...) -> Any
460
468
# If the field type is non-nullable, then it is resolved without any
461
469
# protection from errors.
462
470
if isinstance (return_type , GraphQLNonNull ):
@@ -472,7 +480,7 @@ def complete_value_catching_error(
472
480
473
481
def handle_error (error ):
474
482
# type: (Union[GraphQLError, GraphQLLocatedError]) -> Optional[Any]
475
- traceback = completed ._traceback
483
+ traceback = completed ._traceback # type: ignore
476
484
exe_context .report_error (error , traceback )
477
485
return None
478
486
@@ -490,10 +498,10 @@ def complete_value(
490
498
return_type , # type: Any
491
499
field_asts , # type: List[Field]
492
500
info , # type: ResolveInfo
493
- path , # type: Union[ List[Union[int, str]], List[ str]]
501
+ path , # type: List[Union[int, str]]
494
502
result , # type: Any
495
503
):
496
- # type: (...) -> Union[bool, str]
504
+ # type: (...) -> Any
497
505
"""
498
506
Implements the instructions for completeValue as defined in the
499
507
"Field entries" section of the spec.
@@ -566,10 +574,10 @@ def complete_list_value(
566
574
return_type , # type: GraphQLList
567
575
field_asts , # type: List[Field]
568
576
info , # type: ResolveInfo
569
- path , # type: List[str]
577
+ path , # type: List[Union[int, str] ]
570
578
result , # type: Any
571
579
):
572
- # type: (...) -> Any
580
+ # type: (...) -> List[ Any]
573
581
"""
574
582
Complete a list value by completing each item in the list with the inner type
575
583
"""
@@ -597,10 +605,10 @@ def complete_list_value(
597
605
598
606
def complete_leaf_value (
599
607
return_type , # type: Union[GraphQLEnumType, GraphQLScalarType]
600
- path , # type: Union[ List[Union[int, str]], List[ str]]
601
- result , # type: Union[int, str]
608
+ path , # type: List[Union[int, str]]
609
+ result , # type: Any
602
610
):
603
- # type: (...) -> Union[int, str]
611
+ # type: (...) -> Union[int, str, float, bool ]
604
612
"""
605
613
Complete a Scalar or Enum by serializing to a valid value, returning null if serialization is not possible.
606
614
"""
@@ -625,12 +633,12 @@ def complete_abstract_value(
625
633
path , # type: List[Union[int, str]]
626
634
result , # type: Any
627
635
):
628
- # type: (...) -> OrderedDict
636
+ # type: (...) -> Dict[str, Any]
629
637
"""
630
638
Complete an value of an abstract type by determining the runtime type of that value, then completing based
631
639
on that type.
632
640
"""
633
- runtime_type = None
641
+ runtime_type = None # type: Union[str, GraphQLObjectType, None]
634
642
635
643
# Field type must be Object, Interface or Union and expect sub-selections.
636
644
if isinstance (return_type , (GraphQLInterfaceType , GraphQLUnionType )):
@@ -640,7 +648,7 @@ def complete_abstract_value(
640
648
runtime_type = get_default_resolve_type_fn (result , info , return_type )
641
649
642
650
if isinstance (runtime_type , string_types ):
643
- runtime_type = info .schema .get_type (runtime_type )
651
+ runtime_type = info .schema .get_type (runtime_type ) # type: ignore
644
652
645
653
if not isinstance (runtime_type , GraphQLObjectType ):
646
654
raise GraphQLError (
@@ -671,22 +679,23 @@ def get_default_resolve_type_fn(
671
679
info , # type: ResolveInfo
672
680
abstract_type , # type: Union[GraphQLInterfaceType, GraphQLUnionType]
673
681
):
674
- # type: (...) -> GraphQLObjectType
682
+ # type: (...) -> Optional[ GraphQLObjectType]
675
683
possible_types = info .schema .get_possible_types (abstract_type )
676
684
for type in possible_types :
677
685
if callable (type .is_type_of ) and type .is_type_of (value , info ):
678
686
return type
687
+ return None
679
688
680
689
681
690
def complete_object_value (
682
691
exe_context , # type: ExecutionContext
683
692
return_type , # type: GraphQLObjectType
684
693
field_asts , # type: List[Field]
685
694
info , # type: ResolveInfo
686
- path , # type: Union[ List[Union[int, str]], List[ str]]
695
+ path , # type: List[Union[int, str]]
687
696
result , # type: Any
688
697
):
689
- # type: (...) -> Union[OrderedDict, Promise ]
698
+ # type: (...) -> Dict[str, Any ]
690
699
"""
691
700
Complete an Object value by evaluating all sub-selections.
692
701
"""
@@ -708,7 +717,7 @@ def complete_nonnull_value(
708
717
return_type , # type: GraphQLNonNull
709
718
field_asts , # type: List[Field]
710
719
info , # type: ResolveInfo
711
- path , # type: Union[ List[Union[int, str]], List[ str]]
720
+ path , # type: List[Union[int, str]]
712
721
result , # type: Any
713
722
):
714
723
# type: (...) -> Any
0 commit comments