@@ -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
+ fragmentVariableValues ?? variableValues ,
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,18 @@ 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 (
237
+ fragmentVariableValues ?? variableValues ,
238
+ selection ,
239
+ ) )
242
240
) {
243
241
continue ;
244
242
}
@@ -252,17 +250,20 @@ function collectFieldsImpl(
252
250
}
253
251
254
252
const fragmentVariableSignatures = fragment . variableSignatures ;
255
- let newFragmentVariables : FragmentVariables | undefined ;
253
+ let newFragmentVariableValues :
254
+ | { [ variable : string ] : unknown }
255
+ | undefined ;
256
256
if ( fragmentVariableSignatures ) {
257
- newFragmentVariables = {
258
- signatures : fragmentVariableSignatures ,
259
- values : experimentalGetArgumentValues (
260
- selection ,
261
- Object . values ( fragmentVariableSignatures ) ,
262
- variableValues ,
263
- fragmentVariables ,
264
- ) ,
265
- } ;
257
+ newFragmentVariableValues = experimentalGetArgumentValues (
258
+ selection ,
259
+ Object . values ( fragmentVariableSignatures ) ,
260
+ scopedVariableValues ,
261
+ ) ;
262
+ for ( const [ variableName , value ] of Object . entries ( variableValues ) ) {
263
+ if ( ! fragment . variableSignatures ?. [ variableName ] ) {
264
+ newFragmentVariableValues [ variableName ] = value ;
265
+ }
266
+ }
266
267
}
267
268
268
269
if ( ! newDeferUsage ) {
@@ -273,7 +274,7 @@ function collectFieldsImpl(
273
274
groupedFieldSet ,
274
275
newDeferUsages ,
275
276
deferUsage ,
276
- newFragmentVariables ,
277
+ newFragmentVariableValues ,
277
278
) ;
278
279
} else {
279
280
newDeferUsages . push ( newDeferUsage ) ;
@@ -283,7 +284,7 @@ function collectFieldsImpl(
283
284
groupedFieldSet ,
284
285
newDeferUsages ,
285
286
newDeferUsage ,
286
- newFragmentVariables ,
287
+ newFragmentVariableValues ,
287
288
) ;
288
289
}
289
290
break ;
@@ -300,16 +301,10 @@ function collectFieldsImpl(
300
301
function getDeferUsage (
301
302
operation : OperationDefinitionNode ,
302
303
variableValues : { [ variable : string ] : unknown } ,
303
- fragmentVariables : FragmentVariables | undefined ,
304
304
node : FragmentSpreadNode | InlineFragmentNode ,
305
305
parentDeferUsage : DeferUsage | undefined ,
306
306
) : DeferUsage | undefined {
307
- const defer = getDirectiveValues (
308
- GraphQLDeferDirective ,
309
- node ,
310
- variableValues ,
311
- fragmentVariables ,
312
- ) ;
307
+ const defer = getDirectiveValues ( GraphQLDeferDirective , node , variableValues ) ;
313
308
314
309
if ( ! defer ) {
315
310
return ;
@@ -335,16 +330,10 @@ function getDeferUsage(
335
330
* directives, where `@skip` has higher precedence than `@include`.
336
331
*/
337
332
function shouldIncludeNode (
338
- node : FragmentSpreadNode | FieldNode | InlineFragmentNode ,
339
333
variableValues : { [ variable : string ] : unknown } ,
340
- fragmentVariables : FragmentVariables | undefined ,
334
+ node : FragmentSpreadNode | FieldNode | InlineFragmentNode ,
341
335
) : boolean {
342
- const skip = getDirectiveValues (
343
- GraphQLSkipDirective ,
344
- node ,
345
- variableValues ,
346
- fragmentVariables ,
347
- ) ;
336
+ const skip = getDirectiveValues ( GraphQLSkipDirective , node , variableValues ) ;
348
337
if ( skip ?. if === true ) {
349
338
return false ;
350
339
}
@@ -353,7 +342,6 @@ function shouldIncludeNode(
353
342
GraphQLIncludeDirective ,
354
343
node ,
355
344
variableValues ,
356
- fragmentVariables ,
357
345
) ;
358
346
if ( include ?. if === false ) {
359
347
return false ;
0 commit comments