@@ -246,24 +246,12 @@ function collectFieldsImpl(
246
246
continue ;
247
247
}
248
248
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
+ ) ;
267
255
268
256
if ( ! newDeferUsage ) {
269
257
visitedFragmentNames . add ( fragName ) ;
@@ -370,6 +358,30 @@ function doesFragmentConditionMatch(
370
358
return false ;
371
359
}
372
360
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
+
373
385
/**
374
386
* Implements the logic to compute the key of a given field's entry
375
387
*/
0 commit comments