@@ -230,7 +230,18 @@ export class ValidationContext {
230
230
let spreads = this . _fragmentSpreads . get ( node ) ;
231
231
if ( ! spreads ) {
232
232
spreads = [ ] ;
233
- gatherSpreads ( spreads , node . selectionSet ) ;
233
+ const setsToVisit : Array < SelectionSet > = [ node . selectionSet ] ;
234
+ while ( setsToVisit . length !== 0 ) {
235
+ const set = setsToVisit . pop ( ) ;
236
+ for ( let i = 0 ; i < set . selections . length ; i ++ ) {
237
+ const selection = set . selections [ i ] ;
238
+ if ( selection . kind === Kind . FRAGMENT_SPREAD ) {
239
+ spreads . push ( selection ) ;
240
+ } else if ( selection . selectionSet ) {
241
+ setsToVisit . push ( selection . selectionSet ) ;
242
+ }
243
+ }
244
+ }
234
245
this . _fragmentSpreads . set ( node , spreads ) ;
235
246
}
236
247
return spreads ;
@@ -329,17 +340,3 @@ export class ValidationContext {
329
340
return this . _typeInfo . getArgument ( ) ;
330
341
}
331
342
}
332
-
333
- /**
334
- * Given a selection set, gather all the named spreads defined within.
335
- */
336
- function gatherSpreads ( spreads : Array < FragmentSpread > , node : SelectionSet ) {
337
- for ( let i = 0 ; i < node . selections . length ; i ++ ) {
338
- const selection = node . selections [ i ] ;
339
- if ( selection . kind === Kind . FRAGMENT_SPREAD ) {
340
- spreads . push ( selection ) ;
341
- } else if ( selection . selectionSet ) {
342
- gatherSpreads ( spreads , selection . selectionSet ) ;
343
- }
344
- }
345
- }
0 commit comments