Skip to content

Commit 03573bf

Browse files
committed
Execute: Remove excessive arguments
1 parent 261b99b commit 03573bf

File tree

2 files changed

+22
-80
lines changed

2 files changed

+22
-80
lines changed

src/execution/execute.js

Lines changed: 21 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -703,9 +703,8 @@ function resolveField(
703703
// Get the resolve function, regardless of if its result is normal
704704
// or abrupt (error).
705705
const result = resolveFieldValueOrError(
706-
exeContext,
706+
exeContext.contextValue,
707707
fieldDef,
708-
fieldNodes,
709708
resolveFn,
710709
source,
711710
info,
@@ -714,7 +713,6 @@ function resolveField(
714713
return completeValueCatchingError(
715714
exeContext,
716715
fieldDef.type,
717-
fieldNodes,
718716
info,
719717
path,
720718
result,
@@ -731,7 +729,7 @@ export function buildResolveInfo(
731729
// The resolve function's optional fourth argument is a collection of
732730
// information about the current execution state.
733731
return {
734-
fieldName: fieldNodes[0].name.value,
732+
fieldName: fieldDef.name,
735733
fieldNodes,
736734
returnType: fieldDef.type,
737735
parentType,
@@ -747,9 +745,8 @@ export function buildResolveInfo(
747745
// Isolates the "ReturnOrAbrupt" behavior to not de-opt the `resolveField`
748746
// function. Returns the result of resolveFn or the abrupt-return Error object.
749747
export function resolveFieldValueOrError<TSource>(
750-
exeContext: ExecutionContext,
748+
contextValue: mixed,
751749
fieldDef: GraphQLField<TSource, *>,
752-
fieldNodes: $ReadOnlyArray<FieldNode>,
753750
resolveFn: GraphQLFieldResolver<TSource, *>,
754751
source: TSource,
755752
info: GraphQLResolveInfo,
@@ -760,16 +757,14 @@ export function resolveFieldValueOrError<TSource>(
760757
// TODO: find a way to memoize, in case this field is within a List type.
761758
const args = getArgumentValues(
762759
fieldDef,
763-
fieldNodes[0],
764-
exeContext.variableValues,
760+
info.fieldNodes[0],
761+
info.variableValues,
765762
);
766763

767764
// The resolve function's optional third argument is a context value that
768765
// is provided to every resolve function within an execution. It is commonly
769766
// 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);
773768
return isPromise(result) ? result.then(undefined, asErrorInstance) : result;
774769
} catch (error) {
775770
return asErrorInstance(error);
@@ -787,7 +782,6 @@ function asErrorInstance(error: mixed): Error {
787782
function completeValueCatchingError(
788783
exeContext: ExecutionContext,
789784
returnType: GraphQLOutputType,
790-
fieldNodes: $ReadOnlyArray<FieldNode>,
791785
info: GraphQLResolveInfo,
792786
path: ResponsePath,
793787
result: mixed,
@@ -798,7 +792,6 @@ function completeValueCatchingError(
798792
return completeValueWithLocatedError(
799793
exeContext,
800794
returnType,
801-
fieldNodes,
802795
info,
803796
path,
804797
result,
@@ -811,7 +804,6 @@ function completeValueCatchingError(
811804
const completed = completeValueWithLocatedError(
812805
exeContext,
813806
returnType,
814-
fieldNodes,
815807
info,
816808
path,
817809
result,
@@ -840,26 +832,18 @@ function completeValueCatchingError(
840832
function completeValueWithLocatedError(
841833
exeContext: ExecutionContext,
842834
returnType: GraphQLOutputType,
843-
fieldNodes: $ReadOnlyArray<FieldNode>,
844835
info: GraphQLResolveInfo,
845836
path: ResponsePath,
846837
result: mixed,
847838
): MaybePromise<mixed> {
848839
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);
857841
if (isPromise(completed)) {
858842
return completed.then(undefined, error =>
859843
Promise.reject(
860844
locatedError(
861845
asErrorInstance(error),
862-
fieldNodes,
846+
info.fieldNodes,
863847
responsePathAsArray(path),
864848
),
865849
),
@@ -869,7 +853,7 @@ function completeValueWithLocatedError(
869853
} catch (error) {
870854
throw locatedError(
871855
asErrorInstance(error),
872-
fieldNodes,
856+
info.fieldNodes,
873857
responsePathAsArray(path),
874858
);
875859
}
@@ -899,15 +883,14 @@ function completeValueWithLocatedError(
899883
function completeValue(
900884
exeContext: ExecutionContext,
901885
returnType: GraphQLOutputType,
902-
fieldNodes: $ReadOnlyArray<FieldNode>,
903886
info: GraphQLResolveInfo,
904887
path: ResponsePath,
905888
result: mixed,
906889
): MaybePromise<mixed> {
907890
// If result is a Promise, apply-lift over completeValue.
908891
if (isPromise(result)) {
909892
return result.then(resolved =>
910-
completeValue(exeContext, returnType, fieldNodes, info, path, resolved),
893+
completeValue(exeContext, returnType, info, path, resolved),
911894
);
912895
}
913896

@@ -922,7 +905,6 @@ function completeValue(
922905
const completed = completeValue(
923906
exeContext,
924907
returnType.ofType,
925-
fieldNodes,
926908
info,
927909
path,
928910
result,
@@ -944,14 +926,7 @@ function completeValue(
944926

945927
// If field type is List, complete each item in the list with the inner type
946928
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);
955930
}
956931

957932
// If field type is a leaf type, Scalar or Enum, serialize to a valid value,
@@ -963,26 +938,12 @@ function completeValue(
963938
// If field type is an abstract type, Interface or Union, determine the
964939
// runtime Object type and complete for that type.
965940
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);
974942
}
975943

976944
// If field type is Object, execute and complete all sub-selections.
977945
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);
986947
}
987948

988949
// Not reachable. All possible output types have been considered.
@@ -1001,7 +962,6 @@ function completeValue(
1001962
function completeListValue(
1002963
exeContext: ExecutionContext,
1003964
returnType: GraphQLList<GraphQLOutputType>,
1004-
fieldNodes: $ReadOnlyArray<FieldNode>,
1005965
info: GraphQLResolveInfo,
1006966
path: ResponsePath,
1007967
result: mixed,
@@ -1025,7 +985,6 @@ function completeListValue(
1025985
const completedItem = completeValueCatchingError(
1026986
exeContext,
1027987
itemType,
1028-
fieldNodes,
1029988
info,
1030989
fieldPath,
1031990
item,
@@ -1063,7 +1022,6 @@ function completeLeafValue(returnType: GraphQLLeafType, result: mixed): mixed {
10631022
function completeAbstractValue(
10641023
exeContext: ExecutionContext,
10651024
returnType: GraphQLAbstractType,
1066-
fieldNodes: $ReadOnlyArray<FieldNode>,
10671025
info: GraphQLResolveInfo,
10681026
path: ResponsePath,
10691027
result: mixed,
@@ -1080,11 +1038,9 @@ function completeAbstractValue(
10801038
resolvedRuntimeType,
10811039
exeContext,
10821040
returnType,
1083-
fieldNodes,
10841041
info,
10851042
result,
10861043
),
1087-
fieldNodes,
10881044
info,
10891045
path,
10901046
result,
@@ -1094,15 +1050,7 @@ function completeAbstractValue(
10941050

10951051
return completeObjectValue(
10961052
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),
11061054
info,
11071055
path,
11081056
result,
@@ -1113,7 +1061,6 @@ function ensureValidRuntimeType(
11131061
runtimeTypeOrName: ?GraphQLObjectType | string,
11141062
exeContext: ExecutionContext,
11151063
returnType: GraphQLAbstractType,
1116-
fieldNodes: $ReadOnlyArray<FieldNode>,
11171064
info: GraphQLResolveInfo,
11181065
result: mixed,
11191066
): GraphQLObjectType {
@@ -1130,15 +1077,15 @@ function ensureValidRuntimeType(
11301077
`Either the ${returnType.name} type should provide a "resolveType" ` +
11311078
'function or each possible types should provide an ' +
11321079
'"isTypeOf" function.',
1133-
fieldNodes,
1080+
info.fieldNodes,
11341081
);
11351082
}
11361083

11371084
if (!exeContext.schema.isPossibleType(returnType, runtimeType)) {
11381085
throw new GraphQLError(
11391086
`Runtime Object type "${runtimeType.name}" is not a possible type ` +
11401087
`for "${returnType.name}".`,
1141-
fieldNodes,
1088+
info.fieldNodes,
11421089
);
11431090
}
11441091

@@ -1151,7 +1098,6 @@ function ensureValidRuntimeType(
11511098
function completeObjectValue(
11521099
exeContext: ExecutionContext,
11531100
returnType: GraphQLObjectType,
1154-
fieldNodes: $ReadOnlyArray<FieldNode>,
11551101
info: GraphQLResolveInfo,
11561102
path: ResponsePath,
11571103
result: mixed,
@@ -1165,29 +1111,27 @@ function completeObjectValue(
11651111
if (isPromise(isTypeOf)) {
11661112
return isTypeOf.then(resolvedIsTypeOf => {
11671113
if (!resolvedIsTypeOf) {
1168-
throw invalidReturnTypeError(returnType, result, fieldNodes);
1114+
throw invalidReturnTypeError(returnType, result, info.fieldNodes);
11691115
}
11701116
return collectAndExecuteSubfields(
11711117
exeContext,
11721118
returnType,
1173-
fieldNodes,
1174-
info,
1119+
info.fieldNodes,
11751120
path,
11761121
result,
11771122
);
11781123
});
11791124
}
11801125

11811126
if (!isTypeOf) {
1182-
throw invalidReturnTypeError(returnType, result, fieldNodes);
1127+
throw invalidReturnTypeError(returnType, result, info.fieldNodes);
11831128
}
11841129
}
11851130

11861131
return collectAndExecuteSubfields(
11871132
exeContext,
11881133
returnType,
1189-
fieldNodes,
1190-
info,
1134+
info.fieldNodes,
11911135
path,
11921136
result,
11931137
);
@@ -1208,7 +1152,6 @@ function collectAndExecuteSubfields(
12081152
exeContext: ExecutionContext,
12091153
returnType: GraphQLObjectType,
12101154
fieldNodes: $ReadOnlyArray<FieldNode>,
1211-
info: GraphQLResolveInfo,
12121155
path: ResponsePath,
12131156
result: mixed,
12141157
): MaybePromise<ObjMap<mixed>> {
@@ -1260,7 +1203,7 @@ function defaultResolveTypeFn(
12601203
context: mixed,
12611204
info: GraphQLResolveInfo,
12621205
abstractType: GraphQLAbstractType,
1263-
): ?GraphQLObjectType | string | Promise<?GraphQLObjectType | string> {
1206+
): MaybePromise<?GraphQLObjectType | string> {
12641207
// First, look for `__typename`.
12651208
if (
12661209
value !== null &&

src/subscription/subscribe.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,8 @@ export function createSourceEventStream(
257257
// algorithm from GraphQL specification. It differs from
258258
// "ResolveFieldValue" due to providing a different `resolveFn`.
259259
const result = resolveFieldValueOrError(
260-
exeContext,
260+
exeContext.contextValue,
261261
fieldDef,
262-
fieldNodes,
263262
resolveFn,
264263
rootValue,
265264
info,

0 commit comments

Comments
 (0)