@@ -32,15 +32,10 @@ export interface DeferUsage {
3232 parentDeferUsage : DeferUsage | undefined ;
3333}
3434
35- export interface FragmentVariables {
36- signatures : ObjMap < GraphQLVariableSignature > ;
37- values : ObjMap < unknown > ;
38- }
39-
4035export interface FieldDetails {
4136 node : FieldNode ;
4237 deferUsage ?: DeferUsage | undefined ;
43- fragmentVariables ?: FragmentVariables | undefined ;
38+ fragmentVariableValues ?: { [ variable : string ] : unknown } | undefined ;
4439}
4540
4641export type FieldGroup = ReadonlyArray < FieldDetails > ;
@@ -136,14 +131,14 @@ export function collectSubfields(
136131 for ( const fieldDetail of fieldGroup ) {
137132 const selectionSet = fieldDetail . node . selectionSet ;
138133 if ( selectionSet ) {
139- const { deferUsage, fragmentVariables } = fieldDetail ;
134+ const { deferUsage, fragmentVariableValues } = fieldDetail ;
140135 collectFieldsImpl (
141136 context ,
142137 selectionSet ,
143138 subGroupedFieldSet ,
144139 newDeferUsages ,
145140 deferUsage ,
146- fragmentVariables ,
141+ fragmentVariableValues ,
147142 ) ;
148143 }
149144 }
@@ -161,7 +156,7 @@ function collectFieldsImpl(
161156 groupedFieldSet : AccumulatorMap < string , FieldDetails > ,
162157 newDeferUsages : Array < DeferUsage > ,
163158 deferUsage ?: DeferUsage ,
164- fragmentVariables ?: FragmentVariables ,
159+ fragmentVariableValues ?: { [ variable : string ] : unknown } ,
165160) : void {
166161 const {
167162 schema,
@@ -172,31 +167,32 @@ function collectFieldsImpl(
172167 visitedFragmentNames,
173168 } = context ;
174169
170+ const scopedVariableValues = fragmentVariableValues ?? variableValues ;
171+
175172 for ( const selection of selectionSet . selections ) {
176173 switch ( selection . kind ) {
177174 case Kind . FIELD : {
178- if ( ! shouldIncludeNode ( selection , variableValues , fragmentVariables ) ) {
175+ if ( ! shouldIncludeNode ( scopedVariableValues , selection ) ) {
179176 continue ;
180177 }
181178 groupedFieldSet . add ( getFieldEntryKey ( selection ) , {
182179 node : selection ,
183180 deferUsage,
184- fragmentVariables ,
181+ fragmentVariableValues ,
185182 } ) ;
186183 break ;
187184 }
188185 case Kind . INLINE_FRAGMENT : {
189186 if (
190- ! shouldIncludeNode ( selection , variableValues , fragmentVariables ) ||
187+ ! shouldIncludeNode ( scopedVariableValues , selection ) ||
191188 ! doesFragmentConditionMatch ( schema , selection , runtimeType )
192189 ) {
193190 continue ;
194191 }
195192
196193 const newDeferUsage = getDeferUsage (
197194 operation ,
198- variableValues ,
199- fragmentVariables ,
195+ fragmentVariableValues ?? variableValues ,
200196 selection ,
201197 deferUsage ,
202198 ) ;
@@ -208,7 +204,7 @@ function collectFieldsImpl(
208204 groupedFieldSet ,
209205 newDeferUsages ,
210206 deferUsage ,
211- fragmentVariables ,
207+ fragmentVariableValues ,
212208 ) ;
213209 } else {
214210 newDeferUsages . push ( newDeferUsage ) ;
@@ -218,7 +214,7 @@ function collectFieldsImpl(
218214 groupedFieldSet ,
219215 newDeferUsages ,
220216 newDeferUsage ,
221- fragmentVariables ,
217+ fragmentVariableValues ,
222218 ) ;
223219 }
224220
@@ -229,16 +225,18 @@ function collectFieldsImpl(
229225
230226 const newDeferUsage = getDeferUsage (
231227 operation ,
232- variableValues ,
233- fragmentVariables ,
228+ scopedVariableValues ,
234229 selection ,
235230 deferUsage ,
236231 ) ;
237232
238233 if (
239234 ! newDeferUsage &&
240235 ( visitedFragmentNames . has ( fragName ) ||
241- ! shouldIncludeNode ( selection , variableValues , fragmentVariables ) )
236+ ! shouldIncludeNode (
237+ fragmentVariableValues ?? variableValues ,
238+ selection ,
239+ ) )
242240 ) {
243241 continue ;
244242 }
@@ -252,17 +250,20 @@ function collectFieldsImpl(
252250 }
253251
254252 const fragmentVariableSignatures = fragment . variableSignatures ;
255- let newFragmentVariables : FragmentVariables | undefined ;
253+ let newFragmentVariableValues :
254+ | { [ variable : string ] : unknown }
255+ | undefined ;
256256 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+ }
266267 }
267268
268269 if ( ! newDeferUsage ) {
@@ -273,7 +274,7 @@ function collectFieldsImpl(
273274 groupedFieldSet ,
274275 newDeferUsages ,
275276 deferUsage ,
276- newFragmentVariables ,
277+ newFragmentVariableValues ,
277278 ) ;
278279 } else {
279280 newDeferUsages . push ( newDeferUsage ) ;
@@ -283,7 +284,7 @@ function collectFieldsImpl(
283284 groupedFieldSet ,
284285 newDeferUsages ,
285286 newDeferUsage ,
286- newFragmentVariables ,
287+ newFragmentVariableValues ,
287288 ) ;
288289 }
289290 break ;
@@ -300,16 +301,10 @@ function collectFieldsImpl(
300301function getDeferUsage (
301302 operation : OperationDefinitionNode ,
302303 variableValues : { [ variable : string ] : unknown } ,
303- fragmentVariables : FragmentVariables | undefined ,
304304 node : FragmentSpreadNode | InlineFragmentNode ,
305305 parentDeferUsage : DeferUsage | undefined ,
306306) : DeferUsage | undefined {
307- const defer = getDirectiveValues (
308- GraphQLDeferDirective ,
309- node ,
310- variableValues ,
311- fragmentVariables ,
312- ) ;
307+ const defer = getDirectiveValues ( GraphQLDeferDirective , node , variableValues ) ;
313308
314309 if ( ! defer ) {
315310 return ;
@@ -335,16 +330,10 @@ function getDeferUsage(
335330 * directives, where `@skip` has higher precedence than `@include`.
336331 */
337332function shouldIncludeNode (
338- node : FragmentSpreadNode | FieldNode | InlineFragmentNode ,
339333 variableValues : { [ variable : string ] : unknown } ,
340- fragmentVariables : FragmentVariables | undefined ,
334+ node : FragmentSpreadNode | FieldNode | InlineFragmentNode ,
341335) : boolean {
342- const skip = getDirectiveValues (
343- GraphQLSkipDirective ,
344- node ,
345- variableValues ,
346- fragmentVariables ,
347- ) ;
336+ const skip = getDirectiveValues ( GraphQLSkipDirective , node , variableValues ) ;
348337 if ( skip ?. if === true ) {
349338 return false ;
350339 }
@@ -353,7 +342,6 @@ function shouldIncludeNode(
353342 GraphQLIncludeDirective ,
354343 node ,
355344 variableValues ,
356- fragmentVariables ,
357345 ) ;
358346 if ( include ?. if === false ) {
359347 return false ;
0 commit comments