@@ -43,6 +43,7 @@ interface CollectFieldsContext {
43
43
operation : OperationDefinitionNode ;
44
44
runtimeType : GraphQLObjectType ;
45
45
visitedFragmentNames : Set < string > ;
46
+ localVariableValues : { [ variable : string ] : unknown } | undefined ;
46
47
variableValues : { [ variable : string ] : unknown } ;
47
48
}
48
49
@@ -69,14 +70,14 @@ export function collectFields(
69
70
runtimeType,
70
71
variableValues,
71
72
operation,
73
+ localVariableValues : undefined ,
72
74
visitedFragmentNames : new Set ( ) ,
73
75
} ;
74
76
75
77
collectFieldsImpl (
76
78
context ,
77
79
operation . selectionSet ,
78
80
groupedFieldSet ,
79
- variableValues ,
80
81
) ;
81
82
return groupedFieldSet ;
82
83
}
@@ -104,6 +105,7 @@ export function collectSubfields(
104
105
schema,
105
106
fragments,
106
107
runtimeType : returnType ,
108
+ localVariableValues : undefined ,
107
109
variableValues,
108
110
operation,
109
111
visitedFragmentNames : new Set ( ) ,
@@ -117,7 +119,6 @@ export function collectSubfields(
117
119
context ,
118
120
node . selectionSet ,
119
121
subGroupedFieldSet ,
120
- undefined ,
121
122
fieldDetail . deferUsage ,
122
123
) ;
123
124
}
@@ -126,12 +127,10 @@ export function collectSubfields(
126
127
return subGroupedFieldSet ;
127
128
}
128
129
129
- // eslint-disable-next-line max-params
130
130
function collectFieldsImpl (
131
131
context : CollectFieldsContext ,
132
132
selectionSet : SelectionSetNode ,
133
133
groupedFieldSet : AccumulatorMap < string , FieldDetails > ,
134
- fragmentVariableValues ?: ObjMap < unknown > ,
135
134
parentDeferUsage ?: DeferUsage ,
136
135
deferUsage ?: DeferUsage ,
137
136
) : void {
@@ -140,21 +139,22 @@ function collectFieldsImpl(
140
139
fragments,
141
140
runtimeType,
142
141
variableValues,
142
+ localVariableValues,
143
143
operation,
144
144
visitedFragmentNames,
145
145
} = context ;
146
146
147
147
for ( const selection of selectionSet . selections ) {
148
148
switch ( selection . kind ) {
149
149
case Kind . FIELD : {
150
- const vars = fragmentVariableValues ?? variableValues ;
150
+ const vars = localVariableValues ?? variableValues ;
151
151
if ( ! shouldIncludeNode ( vars , selection ) ) {
152
152
continue ;
153
153
}
154
154
groupedFieldSet . add ( getFieldEntryKey ( selection ) , {
155
155
node : selection ,
156
156
deferUsage : deferUsage ?? parentDeferUsage ,
157
- fragmentVariableValues : fragmentVariableValues ?? undefined ,
157
+ fragmentVariableValues : localVariableValues ?? undefined ,
158
158
} ) ;
159
159
break ;
160
160
}
@@ -177,7 +177,6 @@ function collectFieldsImpl(
177
177
context ,
178
178
selection . selectionSet ,
179
179
groupedFieldSet ,
180
- fragmentVariableValues ,
181
180
parentDeferUsage ,
182
181
newDeferUsage ?? deferUsage ,
183
182
) ;
@@ -223,24 +222,24 @@ function collectFieldsImpl(
223
222
// scope as that variable can still get used in spreads later on in the selectionSet.
224
223
// - when a value is passed in through the fragment-spread we need to copy over the key-value
225
224
// into our variable-values.
226
- const fragmentArgValues = fragment . variableDefinitions
225
+ context . localVariableValues = fragment . variableDefinitions
227
226
? getArgumentValuesFromSpread (
228
227
selection ,
229
228
schema ,
230
229
fragment . variableDefinitions ,
231
230
variableValues ,
232
- fragmentVariableValues ,
231
+ context . localVariableValues ,
233
232
)
234
233
: undefined ;
235
234
236
235
collectFieldsImpl (
237
236
context ,
238
237
fragment . selectionSet ,
239
238
groupedFieldSet ,
240
- fragmentArgValues ,
241
239
parentDeferUsage ,
242
240
newDeferUsage ?? deferUsage ,
243
241
) ;
242
+ context . localVariableValues = undefined ;
244
243
245
244
break ;
246
245
}
0 commit comments