@@ -32,15 +32,10 @@ export interface DeferUsage {
32
32
parentDeferUsage : DeferUsage | undefined ;
33
33
}
34
34
35
- export interface FragmentVariables {
36
- signatures : ObjMap < GraphQLVariableSignature > ;
37
- values : ObjMap < unknown > ;
38
- }
39
-
40
35
export interface FieldDetails {
41
36
node : FieldNode ;
42
37
deferUsage ?: DeferUsage | undefined ;
43
- fragmentVariables ?: FragmentVariables | undefined ;
38
+ fragmentVariableValues ?: { [ variable : string ] : unknown } | undefined ;
44
39
}
45
40
46
41
export type FieldGroup = ReadonlyArray < FieldDetails > ;
@@ -136,14 +131,14 @@ export function collectSubfields(
136
131
for ( const fieldDetail of fieldGroup ) {
137
132
const selectionSet = fieldDetail . node . selectionSet ;
138
133
if ( selectionSet ) {
139
- const { deferUsage, fragmentVariables } = fieldDetail ;
134
+ const { deferUsage, fragmentVariableValues } = fieldDetail ;
140
135
collectFieldsImpl (
141
136
context ,
142
137
selectionSet ,
143
138
subGroupedFieldSet ,
144
139
newDeferUsages ,
145
140
deferUsage ,
146
- fragmentVariables ,
141
+ fragmentVariableValues ,
147
142
) ;
148
143
}
149
144
}
@@ -161,7 +156,7 @@ function collectFieldsImpl(
161
156
groupedFieldSet : AccumulatorMap < string , FieldDetails > ,
162
157
newDeferUsages : Array < DeferUsage > ,
163
158
deferUsage ?: DeferUsage ,
164
- fragmentVariables ?: FragmentVariables ,
159
+ fragmentVariableValues ?: { [ variable : string ] : unknown } ,
165
160
) : void {
166
161
const {
167
162
schema,
@@ -172,31 +167,32 @@ function collectFieldsImpl(
172
167
visitedFragmentNames,
173
168
} = context ;
174
169
170
+ const scopedVariableValues = fragmentVariableValues ?? variableValues ;
171
+
175
172
for ( const selection of selectionSet . selections ) {
176
173
switch ( selection . kind ) {
177
174
case Kind . FIELD : {
178
- if ( ! shouldIncludeNode ( selection , variableValues , fragmentVariables ) ) {
175
+ if ( ! shouldIncludeNode ( scopedVariableValues , selection ) ) {
179
176
continue ;
180
177
}
181
178
groupedFieldSet . add ( getFieldEntryKey ( selection ) , {
182
179
node : selection ,
183
180
deferUsage,
184
- fragmentVariables ,
181
+ fragmentVariableValues ,
185
182
} ) ;
186
183
break ;
187
184
}
188
185
case Kind . INLINE_FRAGMENT : {
189
186
if (
190
- ! shouldIncludeNode ( selection , variableValues , fragmentVariables ) ||
187
+ ! shouldIncludeNode ( scopedVariableValues , selection ) ||
191
188
! doesFragmentConditionMatch ( schema , selection , runtimeType )
192
189
) {
193
190
continue ;
194
191
}
195
192
196
193
const newDeferUsage = getDeferUsage (
197
194
operation ,
198
- variableValues ,
199
- fragmentVariables ,
195
+ scopedVariableValues ,
200
196
selection ,
201
197
deferUsage ,
202
198
) ;
@@ -208,7 +204,7 @@ function collectFieldsImpl(
208
204
groupedFieldSet ,
209
205
newDeferUsages ,
210
206
deferUsage ,
211
- fragmentVariables ,
207
+ fragmentVariableValues ,
212
208
) ;
213
209
} else {
214
210
newDeferUsages . push ( newDeferUsage ) ;
@@ -218,7 +214,7 @@ function collectFieldsImpl(
218
214
groupedFieldSet ,
219
215
newDeferUsages ,
220
216
newDeferUsage ,
221
- fragmentVariables ,
217
+ fragmentVariableValues ,
222
218
) ;
223
219
}
224
220
@@ -229,16 +225,15 @@ function collectFieldsImpl(
229
225
230
226
const newDeferUsage = getDeferUsage (
231
227
operation ,
232
- variableValues ,
233
- fragmentVariables ,
228
+ scopedVariableValues ,
234
229
selection ,
235
230
deferUsage ,
236
231
) ;
237
232
238
233
if (
239
234
! newDeferUsage &&
240
235
( visitedFragmentNames . has ( fragName ) ||
241
- ! shouldIncludeNode ( selection , variableValues , fragmentVariables ) )
236
+ ! shouldIncludeNode ( scopedVariableValues , selection ) )
242
237
) {
243
238
continue ;
244
239
}
@@ -252,17 +247,20 @@ function collectFieldsImpl(
252
247
}
253
248
254
249
const fragmentVariableSignatures = fragment . variableSignatures ;
255
- let newFragmentVariables : FragmentVariables | undefined ;
250
+ let newFragmentVariableValues :
251
+ | { [ variable : string ] : unknown }
252
+ | undefined ;
256
253
if ( fragmentVariableSignatures ) {
257
- newFragmentVariables = {
258
- signatures : fragmentVariableSignatures ,
259
- values : experimentalGetArgumentValues (
260
- selection ,
261
- Object . values ( fragmentVariableSignatures ) ,
262
- variableValues ,
263
- fragmentVariables ,
264
- ) ,
265
- } ;
254
+ newFragmentVariableValues = experimentalGetArgumentValues (
255
+ selection ,
256
+ Object . values ( fragmentVariableSignatures ) ,
257
+ scopedVariableValues ,
258
+ ) ;
259
+ for ( const [ variableName , value ] of Object . entries ( variableValues ) ) {
260
+ if ( ! fragment . variableSignatures ?. [ variableName ] ) {
261
+ newFragmentVariableValues [ variableName ] = value ;
262
+ }
263
+ }
266
264
}
267
265
268
266
if ( ! newDeferUsage ) {
@@ -273,7 +271,7 @@ function collectFieldsImpl(
273
271
groupedFieldSet ,
274
272
newDeferUsages ,
275
273
deferUsage ,
276
- newFragmentVariables ,
274
+ newFragmentVariableValues ,
277
275
) ;
278
276
} else {
279
277
newDeferUsages . push ( newDeferUsage ) ;
@@ -283,7 +281,7 @@ function collectFieldsImpl(
283
281
groupedFieldSet ,
284
282
newDeferUsages ,
285
283
newDeferUsage ,
286
- newFragmentVariables ,
284
+ newFragmentVariableValues ,
287
285
) ;
288
286
}
289
287
break ;
@@ -300,16 +298,10 @@ function collectFieldsImpl(
300
298
function getDeferUsage (
301
299
operation : OperationDefinitionNode ,
302
300
variableValues : { [ variable : string ] : unknown } ,
303
- fragmentVariables : FragmentVariables | undefined ,
304
301
node : FragmentSpreadNode | InlineFragmentNode ,
305
302
parentDeferUsage : DeferUsage | undefined ,
306
303
) : DeferUsage | undefined {
307
- const defer = getDirectiveValues (
308
- GraphQLDeferDirective ,
309
- node ,
310
- variableValues ,
311
- fragmentVariables ,
312
- ) ;
304
+ const defer = getDirectiveValues ( GraphQLDeferDirective , node , variableValues ) ;
313
305
314
306
if ( ! defer ) {
315
307
return ;
@@ -335,16 +327,10 @@ function getDeferUsage(
335
327
* directives, where `@skip` has higher precedence than `@include`.
336
328
*/
337
329
function shouldIncludeNode (
338
- node : FragmentSpreadNode | FieldNode | InlineFragmentNode ,
339
330
variableValues : { [ variable : string ] : unknown } ,
340
- fragmentVariables : FragmentVariables | undefined ,
331
+ node : FragmentSpreadNode | FieldNode | InlineFragmentNode ,
341
332
) : boolean {
342
- const skip = getDirectiveValues (
343
- GraphQLSkipDirective ,
344
- node ,
345
- variableValues ,
346
- fragmentVariables ,
347
- ) ;
333
+ const skip = getDirectiveValues ( GraphQLSkipDirective , node , variableValues ) ;
348
334
if ( skip ?. if === true ) {
349
335
return false ;
350
336
}
@@ -353,7 +339,6 @@ function shouldIncludeNode(
353
339
GraphQLIncludeDirective ,
354
340
node ,
355
341
variableValues ,
356
- fragmentVariables ,
357
342
) ;
358
343
if ( include ?. if === false ) {
359
344
return false ;
0 commit comments