2626 OperationType ,
2727 SelectionSetNode ,
2828)
29- from ..pyutils import inspect , is_invalid , is_nullish , AwaitableOrValue , FrozenList
29+ from ..pyutils import (
30+ inspect ,
31+ is_invalid ,
32+ is_nullish ,
33+ AwaitableOrValue ,
34+ FrozenList ,
35+ Path ,
36+ )
3037from ..utilities import get_operation_root_type , type_from_ast
3138from ..type import (
3239 GraphQLAbstractType ,
4249 GraphQLFieldResolver ,
4350 GraphQLTypeResolver ,
4451 GraphQLResolveInfo ,
45- ResponsePath ,
4652 SchemaMetaFieldDef ,
4753 TypeMetaFieldDef ,
4854 TypeNameMetaFieldDef ,
5763from .values import get_argument_values , get_directive_values , get_variable_values
5864
5965__all__ = [
60- "add_path" ,
6166 "assert_valid_execution_arguments" ,
6267 "default_field_resolver" ,
6368 "default_type_resolver" ,
6469 "execute" ,
6570 "get_field_def" ,
66- "response_path_as_list" ,
6771 "ExecutionResult" ,
6872 "ExecutionContext" ,
6973 "Middleware" ,
@@ -100,6 +104,7 @@ class ExecutionResult(NamedTuple):
100104 errors : Optional [List [GraphQLError ]]
101105
102106
107+ # noinspection PyTypeHints
103108ExecutionResult .__new__ .__defaults__ = (None , None ) # type: ignore
104109
105110Middleware = Optional [Union [Tuple , List , MiddlewareManager ]]
@@ -377,7 +382,7 @@ def execute_fields_serially(
377382 self ,
378383 parent_type : GraphQLObjectType ,
379384 source_value : Any ,
380- path : Optional [ResponsePath ],
385+ path : Optional [Path ],
381386 fields : Dict [str , List [FieldNode ]],
382387 ) -> AwaitableOrValue [Dict [str , Any ]]:
383388 """Execute the given fields serially.
@@ -386,7 +391,7 @@ def execute_fields_serially(
386391 """
387392 results : Dict [str , Any ] = {}
388393 for response_name , field_nodes in fields .items ():
389- field_path = add_path (path , response_name )
394+ field_path = Path (path , response_name )
390395 result = self .resolve_field (
391396 parent_type , source_value , field_nodes , field_path
392397 )
@@ -427,7 +432,7 @@ def execute_fields(
427432 self ,
428433 parent_type : GraphQLObjectType ,
429434 source_value : Any ,
430- path : Optional [ResponsePath ],
435+ path : Optional [Path ],
431436 fields : Dict [str , List [FieldNode ]],
432437 ) -> AwaitableOrValue [Dict [str , Any ]]:
433438 """Execute the given fields concurrently.
@@ -438,7 +443,7 @@ def execute_fields(
438443 awaitable_fields : List [str ] = []
439444 append_awaitable = awaitable_fields .append
440445 for response_name , field_nodes in fields .items ():
441- field_path = add_path (path , response_name )
446+ field_path = Path (path , response_name )
442447 result = self .resolve_field (
443448 parent_type , source_value , field_nodes , field_path
444449 )
@@ -559,7 +564,7 @@ def build_resolve_info(
559564 field_def : GraphQLField ,
560565 field_nodes : List [FieldNode ],
561566 parent_type : GraphQLObjectType ,
562- path : ResponsePath ,
567+ path : Path ,
563568 ) -> GraphQLResolveInfo :
564569 # The resolve function's first argument is a collection of information about
565570 # the current execution state.
@@ -582,7 +587,7 @@ def resolve_field(
582587 parent_type : GraphQLObjectType ,
583588 source : Any ,
584589 field_nodes : List [FieldNode ],
585- path : ResponsePath ,
590+ path : Path ,
586591 ) -> AwaitableOrValue [Any ]:
587592 """Resolve the field on the given source object.
588593
@@ -652,7 +657,7 @@ def complete_value_catching_error(
652657 return_type : GraphQLOutputType ,
653658 field_nodes : List [FieldNode ],
654659 info : GraphQLResolveInfo ,
655- path : ResponsePath ,
660+ path : Path ,
656661 result : Any ,
657662 ) -> AwaitableOrValue [Any ]:
658663 """Complete a value while catching an error.
@@ -694,10 +699,10 @@ def handle_field_error(
694699 self ,
695700 raw_error : Exception ,
696701 field_nodes : List [FieldNode ],
697- path : ResponsePath ,
702+ path : Path ,
698703 return_type : GraphQLOutputType ,
699704 ) -> None :
700- error = located_error (raw_error , field_nodes , response_path_as_list ( path ))
705+ error = located_error (raw_error , field_nodes , path . as_list ( ))
701706
702707 # If the field type is non-nullable, then it is resolved without any protection
703708 # from errors, however it still properly locates the error.
@@ -713,7 +718,7 @@ def complete_value(
713718 return_type : GraphQLOutputType ,
714719 field_nodes : List [FieldNode ],
715720 info : GraphQLResolveInfo ,
716- path : ResponsePath ,
721+ path : Path ,
717722 result : Any ,
718723 ) -> AwaitableOrValue [Any ]:
719724 """Complete a value.
@@ -797,7 +802,7 @@ def complete_list_value(
797802 return_type : GraphQLList [GraphQLOutputType ],
798803 field_nodes : List [FieldNode ],
799804 info : GraphQLResolveInfo ,
800- path : ResponsePath ,
805+ path : Path ,
801806 result : Iterable [Any ],
802807 ) -> AwaitableOrValue [Any ]:
803808 """Complete a list value.
@@ -821,7 +826,7 @@ def complete_list_value(
821826 for index , item in enumerate (result ):
822827 # No need to modify the info object containing the path, since from here on
823828 # it is not ever accessed by resolver functions.
824- field_path = add_path ( path , index )
829+ field_path = path . add_key ( index )
825830 completed_item = self .complete_value_catching_error (
826831 item_type , field_nodes , info , field_path , item
827832 )
@@ -866,7 +871,7 @@ def complete_abstract_value(
866871 return_type : GraphQLAbstractType ,
867872 field_nodes : List [FieldNode ],
868873 info : GraphQLResolveInfo ,
869- path : ResponsePath ,
874+ path : Path ,
870875 result : Any ,
871876 ) -> AwaitableOrValue [Any ]:
872877 """Complete an abstract value.
@@ -947,7 +952,7 @@ def complete_object_value(
947952 return_type : GraphQLObjectType ,
948953 field_nodes : List [FieldNode ],
949954 info : GraphQLResolveInfo ,
950- path : ResponsePath ,
955+ path : Path ,
951956 result : Any ,
952957 ) -> AwaitableOrValue [Dict [str , Any ]]:
953958 """Complete an Object value by executing all sub-selections."""
@@ -981,7 +986,7 @@ def collect_and_execute_subfields(
981986 self ,
982987 return_type : GraphQLObjectType ,
983988 field_nodes : List [FieldNode ],
984- path : ResponsePath ,
989+ path : Path ,
985990 result : Any ,
986991 ) -> AwaitableOrValue [Dict [str , Any ]]:
987992 """Collect sub-fields to execute to complete this value."""
@@ -1041,29 +1046,6 @@ def assert_valid_execution_arguments(
10411046 )
10421047
10431048
1044- def response_path_as_list (path : ResponsePath ) -> List [Union [str , int ]]:
1045- """Get response path as a list.
1046-
1047- Given a ResponsePath (found in the `path` entry in the information provided as the
1048- last argument to a field resolver), return a list of the path keys.
1049- """
1050- flattened : List [Union [str , int ]] = []
1051- append = flattened .append
1052- curr : Optional [ResponsePath ] = path
1053- while curr :
1054- append (curr .key )
1055- curr = curr .prev
1056- return flattened [::- 1 ]
1057-
1058-
1059- def add_path (prev : Optional [ResponsePath ], key : Union [str , int ]) -> ResponsePath :
1060- """Add a key to a response path.
1061-
1062- Given a ResponsePath and a key, return a new ResponsePath containing the new key.
1063- """
1064- return ResponsePath (prev , key )
1065-
1066-
10671049def get_field_def (
10681050 schema : GraphQLSchema , parent_type : GraphQLObjectType , field_name : str
10691051) -> GraphQLField :
0 commit comments