Skip to content

Commit eb0d997

Browse files
committed
small refactor to use context again
1 parent 7c714d9 commit eb0d997

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

src/execution/collectFields.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ interface CollectFieldsContext {
4343
operation: OperationDefinitionNode;
4444
runtimeType: GraphQLObjectType;
4545
visitedFragmentNames: Set<string>;
46+
localVariableValues: { [variable: string]: unknown } | undefined;
4647
variableValues: { [variable: string]: unknown };
4748
}
4849

@@ -69,14 +70,14 @@ export function collectFields(
6970
runtimeType,
7071
variableValues,
7172
operation,
73+
localVariableValues: undefined,
7274
visitedFragmentNames: new Set(),
7375
};
7476

7577
collectFieldsImpl(
7678
context,
7779
operation.selectionSet,
7880
groupedFieldSet,
79-
variableValues,
8081
);
8182
return groupedFieldSet;
8283
}
@@ -104,6 +105,7 @@ export function collectSubfields(
104105
schema,
105106
fragments,
106107
runtimeType: returnType,
108+
localVariableValues: undefined,
107109
variableValues,
108110
operation,
109111
visitedFragmentNames: new Set(),
@@ -117,7 +119,6 @@ export function collectSubfields(
117119
context,
118120
node.selectionSet,
119121
subGroupedFieldSet,
120-
undefined,
121122
fieldDetail.deferUsage,
122123
);
123124
}
@@ -126,12 +127,10 @@ export function collectSubfields(
126127
return subGroupedFieldSet;
127128
}
128129

129-
// eslint-disable-next-line max-params
130130
function collectFieldsImpl(
131131
context: CollectFieldsContext,
132132
selectionSet: SelectionSetNode,
133133
groupedFieldSet: AccumulatorMap<string, FieldDetails>,
134-
fragmentVariableValues?: ObjMap<unknown>,
135134
parentDeferUsage?: DeferUsage,
136135
deferUsage?: DeferUsage,
137136
): void {
@@ -140,21 +139,22 @@ function collectFieldsImpl(
140139
fragments,
141140
runtimeType,
142141
variableValues,
142+
localVariableValues,
143143
operation,
144144
visitedFragmentNames,
145145
} = context;
146146

147147
for (const selection of selectionSet.selections) {
148148
switch (selection.kind) {
149149
case Kind.FIELD: {
150-
const vars = fragmentVariableValues ?? variableValues;
150+
const vars = localVariableValues ?? variableValues;
151151
if (!shouldIncludeNode(vars, selection)) {
152152
continue;
153153
}
154154
groupedFieldSet.add(getFieldEntryKey(selection), {
155155
node: selection,
156156
deferUsage: deferUsage ?? parentDeferUsage,
157-
fragmentVariableValues: fragmentVariableValues ?? undefined,
157+
fragmentVariableValues: localVariableValues ?? undefined,
158158
});
159159
break;
160160
}
@@ -177,7 +177,6 @@ function collectFieldsImpl(
177177
context,
178178
selection.selectionSet,
179179
groupedFieldSet,
180-
fragmentVariableValues,
181180
parentDeferUsage,
182181
newDeferUsage ?? deferUsage,
183182
);
@@ -223,24 +222,24 @@ function collectFieldsImpl(
223222
// scope as that variable can still get used in spreads later on in the selectionSet.
224223
// - when a value is passed in through the fragment-spread we need to copy over the key-value
225224
// into our variable-values.
226-
const fragmentArgValues = fragment.variableDefinitions
225+
context.localVariableValues = fragment.variableDefinitions
227226
? getArgumentValuesFromSpread(
228227
selection,
229228
schema,
230229
fragment.variableDefinitions,
231230
variableValues,
232-
fragmentVariableValues,
231+
context.localVariableValues,
233232
)
234233
: undefined;
235234

236235
collectFieldsImpl(
237236
context,
238237
fragment.selectionSet,
239238
groupedFieldSet,
240-
fragmentArgValues,
241239
parentDeferUsage,
242240
newDeferUsage ?? deferUsage,
243241
);
242+
context.localVariableValues = undefined;
244243

245244
break;
246245
}

0 commit comments

Comments
 (0)