Skip to content

Commit 98f4c77

Browse files
committed
extract out to function
1 parent 884f67c commit 98f4c77

File tree

1 file changed

+30
-18
lines changed

1 file changed

+30
-18
lines changed

src/execution/collectFields.ts

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -246,24 +246,12 @@ function collectFieldsImpl(
246246
continue;
247247
}
248248

249-
const fragmentVariableSignatures = fragment.variableSignatures;
250-
let newScopedVariableValues:
251-
| { [variable: string]: unknown }
252-
| undefined;
253-
if (fragmentVariableSignatures) {
254-
newScopedVariableValues = experimentalGetArgumentValues(
255-
selection,
256-
Object.values(fragmentVariableSignatures),
257-
variableValues,
258-
);
259-
for (const [variableName, value] of Object.entries(
260-
operationVariableValues,
261-
)) {
262-
if (!fragment.variableSignatures?.[variableName]) {
263-
newScopedVariableValues[variableName] = value;
264-
}
265-
}
266-
}
249+
const newScopedVariableValues = getScopedVariableValues(
250+
fragment.variableSignatures,
251+
selection,
252+
variableValues,
253+
operationVariableValues,
254+
);
267255

268256
if (!newDeferUsage) {
269257
visitedFragmentNames.add(fragName);
@@ -370,6 +358,30 @@ function doesFragmentConditionMatch(
370358
return false;
371359
}
372360

361+
/**
362+
* Constructs a variableValues map for the given fragment.
363+
*/
364+
function getScopedVariableValues(
365+
fragmentVariableSignatures: ObjMap<GraphQLVariableSignature> | undefined,
366+
fragmentSpreadNode: FragmentSpreadNode,
367+
variableValues: { [variable: string]: unknown },
368+
operationVariableValues: { [variable: string]: unknown },
369+
): { [variable: string]: unknown } | undefined {
370+
if (!fragmentVariableSignatures) {
371+
return;
372+
}
373+
const scopedVariableValues = experimentalGetArgumentValues(
374+
fragmentSpreadNode,
375+
Object.values(fragmentVariableSignatures),
376+
variableValues,
377+
);
378+
for (const [variableName, value] of Object.entries(operationVariableValues)) {
379+
if (fragmentVariableSignatures[variableName] === undefined) {
380+
scopedVariableValues[variableName] = value;
381+
}
382+
}
383+
}
384+
373385
/**
374386
* Implements the logic to compute the key of a given field's entry
375387
*/

0 commit comments

Comments
 (0)