@@ -703,9 +703,8 @@ function resolveField(
703
703
// Get the resolve function, regardless of if its result is normal
704
704
// or abrupt (error).
705
705
const result = resolveFieldValueOrError (
706
- exeContext ,
706
+ exeContext . contextValue ,
707
707
fieldDef ,
708
- fieldNodes ,
709
708
resolveFn ,
710
709
source ,
711
710
info ,
@@ -714,7 +713,6 @@ function resolveField(
714
713
return completeValueCatchingError (
715
714
exeContext ,
716
715
fieldDef . type ,
717
- fieldNodes ,
718
716
info ,
719
717
path ,
720
718
result ,
@@ -731,7 +729,7 @@ export function buildResolveInfo(
731
729
// The resolve function's optional fourth argument is a collection of
732
730
// information about the current execution state.
733
731
return {
734
- fieldName : fieldNodes [ 0 ] . name . value ,
732
+ fieldName : fieldDef . name ,
735
733
fieldNodes,
736
734
returnType : fieldDef . type ,
737
735
parentType,
@@ -747,9 +745,8 @@ export function buildResolveInfo(
747
745
// Isolates the "ReturnOrAbrupt" behavior to not de-opt the `resolveField`
748
746
// function. Returns the result of resolveFn or the abrupt-return Error object.
749
747
export function resolveFieldValueOrError< TSource > (
750
- exeContext: ExecutionContext ,
748
+ contextValue: mixed ,
751
749
fieldDef: GraphQLField< TSource , * > ,
752
- fieldNodes: $ReadOnlyArray< FieldNode > ,
753
750
resolveFn: GraphQLFieldResolver< TSource , * > ,
754
751
source: TSource,
755
752
info: GraphQLResolveInfo,
@@ -760,16 +757,14 @@ export function resolveFieldValueOrError<TSource>(
760
757
// TODO: find a way to memoize, in case this field is within a List type.
761
758
const args = getArgumentValues (
762
759
fieldDef ,
763
- fieldNodes [ 0 ] ,
764
- exeContext . variableValues ,
760
+ info . fieldNodes [ 0 ] ,
761
+ info . variableValues ,
765
762
) ;
766
763
767
764
// The resolve function's optional third argument is a context value that
768
765
// is provided to every resolve function within an execution. It is commonly
769
766
// used to represent an authenticated user, or request-specific caches.
770
- const context = exeContext . contextValue ;
771
-
772
- const result = resolveFn ( source , args , context , info ) ;
767
+ const result = resolveFn ( source , args , contextValue , info ) ;
773
768
return isPromise ( result ) ? result . then ( undefined , asErrorInstance ) : result ;
774
769
} catch ( error ) {
775
770
return asErrorInstance ( error ) ;
@@ -787,7 +782,6 @@ function asErrorInstance(error: mixed): Error {
787
782
function completeValueCatchingError(
788
783
exeContext: ExecutionContext,
789
784
returnType: GraphQLOutputType,
790
- fieldNodes: $ReadOnlyArray< FieldNode > ,
791
785
info: GraphQLResolveInfo,
792
786
path: ResponsePath,
793
787
result: mixed,
@@ -798,7 +792,6 @@ function completeValueCatchingError(
798
792
return completeValueWithLocatedError (
799
793
exeContext ,
800
794
returnType ,
801
- fieldNodes ,
802
795
info ,
803
796
path ,
804
797
result ,
@@ -811,7 +804,6 @@ function completeValueCatchingError(
811
804
const completed = completeValueWithLocatedError (
812
805
exeContext ,
813
806
returnType ,
814
- fieldNodes ,
815
807
info ,
816
808
path ,
817
809
result ,
@@ -840,26 +832,18 @@ function completeValueCatchingError(
840
832
function completeValueWithLocatedError(
841
833
exeContext: ExecutionContext,
842
834
returnType: GraphQLOutputType,
843
- fieldNodes: $ReadOnlyArray< FieldNode > ,
844
835
info: GraphQLResolveInfo,
845
836
path: ResponsePath,
846
837
result: mixed,
847
838
): MaybePromise< mixed > {
848
839
try {
849
- const completed = completeValue (
850
- exeContext ,
851
- returnType ,
852
- fieldNodes ,
853
- info ,
854
- path ,
855
- result ,
856
- ) ;
840
+ const completed = completeValue ( exeContext , returnType , info , path , result ) ;
857
841
if ( isPromise ( completed ) ) {
858
842
return completed . then ( undefined , error =>
859
843
Promise . reject (
860
844
locatedError (
861
845
asErrorInstance ( error ) ,
862
- fieldNodes ,
846
+ info . fieldNodes ,
863
847
responsePathAsArray ( path ) ,
864
848
) ,
865
849
) ,
@@ -869,7 +853,7 @@ function completeValueWithLocatedError(
869
853
} catch ( error ) {
870
854
throw locatedError (
871
855
asErrorInstance ( error ) ,
872
- fieldNodes ,
856
+ info . fieldNodes ,
873
857
responsePathAsArray ( path ) ,
874
858
) ;
875
859
}
@@ -899,15 +883,14 @@ function completeValueWithLocatedError(
899
883
function completeValue (
900
884
exeContext : ExecutionContext ,
901
885
returnType : GraphQLOutputType ,
902
- fieldNodes : $ReadOnlyArray < FieldNode > ,
903
886
info : GraphQLResolveInfo ,
904
887
path : ResponsePath ,
905
888
result : mixed ,
906
889
) : MaybePromise < mixed > {
907
890
// If result is a Promise, apply-lift over completeValue.
908
891
if ( isPromise ( result ) ) {
909
892
return result . then ( resolved =>
910
- completeValue ( exeContext , returnType , fieldNodes , info , path , resolved ) ,
893
+ completeValue ( exeContext , returnType , info , path , resolved ) ,
911
894
) ;
912
895
}
913
896
@@ -922,7 +905,6 @@ function completeValue(
922
905
const completed = completeValue (
923
906
exeContext ,
924
907
returnType . ofType ,
925
- fieldNodes ,
926
908
info ,
927
909
path ,
928
910
result ,
@@ -944,14 +926,7 @@ function completeValue(
944
926
945
927
// If field type is List, complete each item in the list with the inner type
946
928
if ( isListType ( returnType ) ) {
947
- return completeListValue (
948
- exeContext ,
949
- returnType ,
950
- fieldNodes ,
951
- info ,
952
- path ,
953
- result ,
954
- ) ;
929
+ return completeListValue ( exeContext , returnType , info , path , result ) ;
955
930
}
956
931
957
932
// If field type is a leaf type, Scalar or Enum, serialize to a valid value,
@@ -963,26 +938,12 @@ function completeValue(
963
938
// If field type is an abstract type, Interface or Union, determine the
964
939
// runtime Object type and complete for that type.
965
940
if ( isAbstractType ( returnType ) ) {
966
- return completeAbstractValue (
967
- exeContext ,
968
- returnType ,
969
- fieldNodes ,
970
- info ,
971
- path ,
972
- result ,
973
- ) ;
941
+ return completeAbstractValue ( exeContext , returnType , info , path , result ) ;
974
942
}
975
943
976
944
// If field type is Object, execute and complete all sub-selections.
977
945
if ( isObjectType ( returnType ) ) {
978
- return completeObjectValue (
979
- exeContext ,
980
- returnType ,
981
- fieldNodes ,
982
- info ,
983
- path ,
984
- result ,
985
- ) ;
946
+ return completeObjectValue ( exeContext , returnType , info , path , result ) ;
986
947
}
987
948
988
949
// Not reachable. All possible output types have been considered.
@@ -1001,7 +962,6 @@ function completeValue(
1001
962
function completeListValue (
1002
963
exeContext : ExecutionContext ,
1003
964
returnType : GraphQLList < GraphQLOutputType > ,
1004
- fieldNodes: $ReadOnlyArray< FieldNode > ,
1005
965
info : GraphQLResolveInfo ,
1006
966
path : ResponsePath ,
1007
967
result : mixed ,
@@ -1025,7 +985,6 @@ function completeListValue(
1025
985
const completedItem = completeValueCatchingError (
1026
986
exeContext ,
1027
987
itemType ,
1028
- fieldNodes ,
1029
988
info ,
1030
989
fieldPath ,
1031
990
item ,
@@ -1063,7 +1022,6 @@ function completeLeafValue(returnType: GraphQLLeafType, result: mixed): mixed {
1063
1022
function completeAbstractValue (
1064
1023
exeContext : ExecutionContext ,
1065
1024
returnType : GraphQLAbstractType ,
1066
- fieldNodes: $ReadOnlyArray< FieldNode > ,
1067
1025
info : GraphQLResolveInfo ,
1068
1026
path : ResponsePath ,
1069
1027
result : mixed ,
@@ -1080,11 +1038,9 @@ function completeAbstractValue(
1080
1038
resolvedRuntimeType ,
1081
1039
exeContext ,
1082
1040
returnType ,
1083
- fieldNodes ,
1084
1041
info ,
1085
1042
result ,
1086
1043
) ,
1087
- fieldNodes ,
1088
1044
info ,
1089
1045
path ,
1090
1046
result ,
@@ -1094,15 +1050,7 @@ function completeAbstractValue(
1094
1050
1095
1051
return completeObjectValue (
1096
1052
exeContext ,
1097
- ensureValidRuntimeType (
1098
- runtimeType ,
1099
- exeContext ,
1100
- returnType ,
1101
- fieldNodes ,
1102
- info ,
1103
- result ,
1104
- ) ,
1105
- fieldNodes ,
1053
+ ensureValidRuntimeType ( runtimeType , exeContext , returnType , info , result ) ,
1106
1054
info ,
1107
1055
path ,
1108
1056
result ,
@@ -1113,7 +1061,6 @@ function ensureValidRuntimeType(
1113
1061
runtimeTypeOrName : ?GraphQLObjectType | string ,
1114
1062
exeContext : ExecutionContext ,
1115
1063
returnType : GraphQLAbstractType ,
1116
- fieldNodes : $ReadOnlyArray < FieldNode > ,
1117
1064
info : GraphQLResolveInfo ,
1118
1065
result : mixed ,
1119
1066
) : GraphQLObjectType {
@@ -1130,15 +1077,15 @@ function ensureValidRuntimeType(
1130
1077
`Either the ${ returnType . name } type should provide a "resolveType" ` +
1131
1078
'function or each possible types should provide an ' +
1132
1079
'"isTypeOf" function.' ,
1133
- fieldNodes ,
1080
+ info . fieldNodes ,
1134
1081
) ;
1135
1082
}
1136
1083
1137
1084
if ( ! exeContext . schema . isPossibleType ( returnType , runtimeType ) ) {
1138
1085
throw new GraphQLError (
1139
1086
`Runtime Object type "${ runtimeType . name } " is not a possible type ` +
1140
1087
`for "${ returnType . name } ".` ,
1141
- fieldNodes ,
1088
+ info . fieldNodes ,
1142
1089
) ;
1143
1090
}
1144
1091
@@ -1151,7 +1098,6 @@ function ensureValidRuntimeType(
1151
1098
function completeObjectValue (
1152
1099
exeContext : ExecutionContext ,
1153
1100
returnType : GraphQLObjectType ,
1154
- fieldNodes : $ReadOnlyArray < FieldNode > ,
1155
1101
info : GraphQLResolveInfo ,
1156
1102
path : ResponsePath ,
1157
1103
result : mixed ,
@@ -1165,29 +1111,27 @@ function completeObjectValue(
1165
1111
if ( isPromise ( isTypeOf ) ) {
1166
1112
return isTypeOf . then ( resolvedIsTypeOf => {
1167
1113
if ( ! resolvedIsTypeOf ) {
1168
- throw invalidReturnTypeError ( returnType , result , fieldNodes ) ;
1114
+ throw invalidReturnTypeError ( returnType , result , info . fieldNodes ) ;
1169
1115
}
1170
1116
return collectAndExecuteSubfields (
1171
1117
exeContext ,
1172
1118
returnType ,
1173
- fieldNodes ,
1174
- info ,
1119
+ info . fieldNodes ,
1175
1120
path ,
1176
1121
result ,
1177
1122
) ;
1178
1123
} ) ;
1179
1124
}
1180
1125
1181
1126
if ( ! isTypeOf ) {
1182
- throw invalidReturnTypeError ( returnType , result , fieldNodes ) ;
1127
+ throw invalidReturnTypeError ( returnType , result , info . fieldNodes ) ;
1183
1128
}
1184
1129
}
1185
1130
1186
1131
return collectAndExecuteSubfields (
1187
1132
exeContext ,
1188
1133
returnType,
1189
- fieldNodes,
1190
- info,
1134
+ info . fieldNodes,
1191
1135
path,
1192
1136
result,
1193
1137
) ;
@@ -1208,7 +1152,6 @@ function collectAndExecuteSubfields(
1208
1152
exeContext : ExecutionContext ,
1209
1153
returnType : GraphQLObjectType ,
1210
1154
fieldNodes : $ReadOnlyArray < FieldNode > ,
1211
- info : GraphQLResolveInfo ,
1212
1155
path : ResponsePath ,
1213
1156
result : mixed ,
1214
1157
) : MaybePromise < ObjMap < mixed >> {
@@ -1260,7 +1203,7 @@ function defaultResolveTypeFn(
1260
1203
context : mixed ,
1261
1204
info : GraphQLResolveInfo ,
1262
1205
abstractType : GraphQLAbstractType ,
1263
- ) : ? GraphQLObjectType | string | Promise < ?GraphQLObjectType | string > {
1206
+ ) : MaybePromise < ?GraphQLObjectType | string > {
1264
1207
// First, look for `__typename`.
1265
1208
if (
1266
1209
value !== null &&
0 commit comments