@@ -14,6 +14,7 @@ import promiseForObject from '../jsutils/promiseForObject';
14
14
import promiseReduce from '../jsutils/promiseReduce' ;
15
15
import { type ObjMap } from '../jsutils/ObjMap' ;
16
16
import { type PromiseOrValue } from '../jsutils/PromiseOrValue' ;
17
+ import { type Path , addPath , pathToArray } from '../jsutils/Path' ;
17
18
18
19
import { getOperationRootType } from '../utilities/getOperationRootType' ;
19
20
import { typeFromAST } from '../utilities/typeFromAST' ;
@@ -32,7 +33,6 @@ import {
32
33
type GraphQLFieldResolver ,
33
34
type GraphQLResolveInfo ,
34
35
type GraphQLTypeResolver ,
35
- type ResponsePath ,
36
36
type GraphQLList ,
37
37
isObjectType ,
38
38
isAbstractType ,
@@ -235,30 +235,6 @@ function buildResponse(
235
235
: { errors : exeContext . errors , data } ;
236
236
}
237
237
238
- /**
239
- * Given a ResponsePath (found in the `path` entry in the information provided
240
- * as the last argument to a field resolver), return an Array of the path keys.
241
- */
242
- export function responsePathAsArray (
243
- path : ResponsePath ,
244
- ) : $ReadOnlyArray < string | number > {
245
- const flattened = [ ] ;
246
- let curr = path ;
247
- while ( curr ) {
248
- flattened . push ( curr . key ) ;
249
- curr = curr . prev ;
250
- }
251
- return flattened.reverse();
252
- }
253
-
254
- /**
255
- * Given a ResponsePath and a key, return a new ResponsePath containing the
256
- * new key.
257
- */
258
- export function addPath ( prev : ResponsePath | void , key : string | number ) {
259
- return { prev , key } ;
260
- }
261
-
262
238
/**
263
239
* Essential assertions before executing to provide developer feedback for
264
240
* improper use of the GraphQL library.
@@ -420,7 +396,7 @@ function executeFieldsSerially(
420
396
exeContext : ExecutionContext ,
421
397
parentType : GraphQLObjectType ,
422
398
sourceValue : mixed ,
423
- path : ResponsePath | void ,
399
+ path : Path | void ,
424
400
fields : ObjMap < Array < FieldNode > > ,
425
401
) : PromiseOrValue < ObjMap < mixed > > {
426
402
return promiseReduce (
@@ -459,7 +435,7 @@ function executeFields(
459
435
exeContext: ExecutionContext,
460
436
parentType: GraphQLObjectType,
461
437
sourceValue: mixed,
462
- path: ResponsePath | void,
438
+ path: Path | void,
463
439
fields: ObjMap< Array < FieldNode > > ,
464
440
) : PromiseOrValue < ObjMap < mixed > > {
465
441
const results = Object . create ( null ) ;
@@ -639,7 +615,7 @@ function resolveField(
639
615
parentType: GraphQLObjectType,
640
616
source: mixed,
641
617
fieldNodes: $ReadOnlyArray< FieldNode > ,
642
- path: ResponsePath ,
618
+ path: Path ,
643
619
): PromiseOrValue< mixed > {
644
620
const fieldNode = fieldNodes [ 0 ] ;
645
621
const fieldName = fieldNode . name . value ;
@@ -685,7 +661,7 @@ export function buildResolveInfo(
685
661
fieldDef: GraphQLField< mixed , mixed > ,
686
662
fieldNodes: $ReadOnlyArray< FieldNode > ,
687
663
parentType: GraphQLObjectType,
688
- path: ResponsePath ,
664
+ path: Path ,
689
665
): GraphQLResolveInfo {
690
666
// The resolve function's optional fourth argument is a collection of
691
667
// information about the current execution state.
@@ -751,7 +727,7 @@ function completeValueCatchingError(
751
727
returnType : GraphQLOutputType ,
752
728
fieldNodes : $ReadOnlyArray < FieldNode > ,
753
729
info: GraphQLResolveInfo,
754
- path: ResponsePath ,
730
+ path: Path ,
755
731
result: mixed,
756
732
): PromiseOrValue< mixed > {
757
733
try {
@@ -788,7 +764,7 @@ function handleFieldError(rawError, fieldNodes, path, returnType, exeContext) {
788
764
const error = locatedError (
789
765
asErrorInstance ( rawError ) ,
790
766
fieldNodes ,
791
- responsePathAsArray ( path ) ,
767
+ pathToArray ( path ) ,
792
768
) ;
793
769
794
770
// If the field type is non-nullable, then it is resolved without any
@@ -829,7 +805,7 @@ function completeValue(
829
805
returnType : GraphQLOutputType ,
830
806
fieldNodes : $ReadOnlyArray < FieldNode > ,
831
807
info: GraphQLResolveInfo,
832
- path: ResponsePath ,
808
+ path: Path ,
833
809
result: mixed,
834
810
): PromiseOrValue< mixed > {
835
811
// If result is an Error, throw a located error.
@@ -922,7 +898,7 @@ function completeListValue(
922
898
returnType : GraphQLList < GraphQLOutputType > ,
923
899
fieldNodes: $ReadOnlyArray< FieldNode > ,
924
900
info: GraphQLResolveInfo,
925
- path: ResponsePath ,
901
+ path: Path ,
926
902
result: mixed,
927
903
): PromiseOrValue< $ReadOnlyArray < mixed > > {
928
904
invariant (
@@ -982,7 +958,7 @@ function completeAbstractValue(
982
958
returnType: GraphQLAbstractType,
983
959
fieldNodes: $ReadOnlyArray< FieldNode > ,
984
960
info: GraphQLResolveInfo,
985
- path: ResponsePath ,
961
+ path: Path ,
986
962
result: mixed,
987
963
): PromiseOrValue< ObjMap < mixed > > {
988
964
const resolveTypeFn = returnType . resolveType || exeContext . typeResolver ;
@@ -1066,7 +1042,7 @@ function completeObjectValue(
1066
1042
returnType : GraphQLObjectType ,
1067
1043
fieldNodes : $ReadOnlyArray < FieldNode > ,
1068
1044
info : GraphQLResolveInfo ,
1069
- path : ResponsePath ,
1045
+ path : Path ,
1070
1046
result : mixed ,
1071
1047
) : PromiseOrValue < ObjMap < mixed >> {
1072
1048
// If there is an isTypeOf predicate function, call it with the
@@ -1119,7 +1095,7 @@ function collectAndExecuteSubfields(
1119
1095
exeContext : ExecutionContext ,
1120
1096
returnType : GraphQLObjectType ,
1121
1097
fieldNodes : $ReadOnlyArray < FieldNode > ,
1122
- path : ResponsePath ,
1098
+ path : Path ,
1123
1099
result : mixed ,
1124
1100
) : PromiseOrValue < ObjMap < mixed >> {
1125
1101
// Collect sub-fields to execute to complete this value.
0 commit comments