2121 from typing import TypedDict
2222except ImportError : # Python < 3.8
2323 from typing_extensions import TypedDict
24+ try :
25+ from typing import TypeGuard
26+ except ImportError : # Python < 3.10
27+ from typing_extensions import TypeGuard
2428
2529from ..error import GraphQLError , GraphQLFormattedError , located_error
2630from ..language import (
3943 GraphQLFieldResolver ,
4044 GraphQLLeafType ,
4145 GraphQLList ,
42- GraphQLNonNull ,
4346 GraphQLObjectType ,
4447 GraphQLOutputType ,
4548 GraphQLResolveInfo ,
@@ -187,7 +190,9 @@ class ExecutionContext:
187190 errors : List [GraphQLError ]
188191 middleware_manager : Optional [MiddlewareManager ]
189192
190- is_awaitable = staticmethod (default_is_awaitable )
193+ is_awaitable : Callable [[Any ], TypeGuard [Awaitable ]] = staticmethod (
194+ default_is_awaitable # type: ignore
195+ )
191196
192197 def __init__ (
193198 self ,
@@ -607,7 +612,7 @@ def complete_value(
607612 # result is null.
608613 if is_non_null_type (return_type ):
609614 completed = self .complete_value (
610- cast ( GraphQLNonNull , return_type ) .of_type ,
615+ return_type .of_type ,
611616 field_nodes ,
612617 info ,
613618 path ,
@@ -627,25 +632,25 @@ def complete_value(
627632 # If field type is List, complete each item in the list with inner type
628633 if is_list_type (return_type ):
629634 return self .complete_list_value (
630- cast ( GraphQLList , return_type ) , field_nodes , info , path , result
635+ return_type , field_nodes , info , path , result
631636 )
632637
633638 # If field type is a leaf type, Scalar or Enum, serialize to a valid value,
634639 # returning null if serialization is not possible.
635640 if is_leaf_type (return_type ):
636- return self .complete_leaf_value (cast ( GraphQLLeafType , return_type ) , result )
641+ return self .complete_leaf_value (return_type , result )
637642
638643 # If field type is an abstract type, Interface or Union, determine the runtime
639644 # Object type and complete for that type.
640645 if is_abstract_type (return_type ):
641646 return self .complete_abstract_value (
642- cast ( GraphQLAbstractType , return_type ) , field_nodes , info , path , result
647+ return_type , field_nodes , info , path , result
643648 )
644649
645650 # If field type is Object, execute and complete all sub-selections.
646651 if is_object_type (return_type ):
647652 return self .complete_object_value (
648- cast ( GraphQLObjectType , return_type ) , field_nodes , info , path , result
653+ return_type , field_nodes , info , path , result
649654 )
650655
651656 # Not reachable. All possible output types have been considered.
@@ -684,7 +689,6 @@ async def async_iterable_to_list(
684689 "Expected Iterable, but did not find one for field"
685690 f" '{ info .parent_type .name } .{ info .field_name } '."
686691 )
687- result = cast (Iterable [Any ], result )
688692
689693 # This is specified as a simple map, however we're optimizing the path where
690694 # the list contains no coroutine objects by avoiding creating another coroutine
@@ -876,8 +880,6 @@ def ensure_valid_runtime_type(
876880 field_nodes ,
877881 )
878882
879- runtime_type = cast (GraphQLObjectType , runtime_type )
880-
881883 if not self .schema .is_sub_type (return_type , runtime_type ):
882884 raise GraphQLError (
883885 f"Runtime Object type '{ runtime_type .name } ' is not a possible"
0 commit comments