@@ -192,6 +192,7 @@ function findConflictsWithinSelectionSet(
192
192
) ;
193
193
194
194
if ( fragmentNames . length !== 0 ) {
195
+ const discoveredFragments : Array < [ string , string ] > = [ ] ;
195
196
// (B) Then collect conflicts between these fields and those represented by
196
197
// each spread fragment name found.
197
198
for ( let i = 0 ; i < fragmentNames . length ; i ++ ) {
@@ -203,7 +204,40 @@ function findConflictsWithinSelectionSet(
203
204
false ,
204
205
fieldMap ,
205
206
fragmentNames [ i ] ,
207
+ discoveredFragments
206
208
) ;
209
+
210
+ // (E) Then collect any conflicts between the provided collection of fields
211
+ // and any fragment names found in the given fragment.
212
+ while ( discoveredFragments . length !== 0 ) {
213
+ const item = discoveredFragments . pop ( ) ;
214
+ if (
215
+ ! item ||
216
+ comparedFragmentPairs . has (
217
+ item [ 1 ] ,
218
+ item [ 0 ] ,
219
+ false ,
220
+ )
221
+ ) {
222
+ continue ;
223
+ }
224
+ const [ fragmentName , referencedFragmentName ] = item ;
225
+ comparedFragmentPairs . add (
226
+ referencedFragmentName ,
227
+ fragmentName ,
228
+ false ,
229
+ ) ;
230
+ collectConflictsBetweenFieldsAndFragment (
231
+ context ,
232
+ conflicts ,
233
+ cachedFieldsAndFragmentNames ,
234
+ comparedFragmentPairs ,
235
+ false ,
236
+ fieldMap ,
237
+ fragmentName ,
238
+ discoveredFragments
239
+ ) ;
240
+ }
207
241
// (C) Then compare this fragment with all other fragments found in this
208
242
// selection set to collect conflicts between fragments spread together.
209
243
// This compares each item in the list of fragment names to every other
@@ -234,6 +268,7 @@ function collectConflictsBetweenFieldsAndFragment(
234
268
areMutuallyExclusive : boolean ,
235
269
fieldMap : NodeAndDefCollection ,
236
270
fragmentName : string ,
271
+ discoveredFragments : Array < Array < string > > ,
237
272
) : void {
238
273
const fragment = context . getFragment ( fragmentName ) ;
239
274
if ( ! fragment ) {
@@ -264,35 +299,7 @@ function collectConflictsBetweenFieldsAndFragment(
264
299
fieldMap2 ,
265
300
) ;
266
301
267
- // (E) Then collect any conflicts between the provided collection of fields
268
- // and any fragment names found in the given fragment.
269
- for ( const referencedFragmentName of referencedFragmentNames ) {
270
- // Memoize so two fragments are not compared for conflicts more than once.
271
- if (
272
- comparedFragmentPairs . has (
273
- referencedFragmentName ,
274
- fragmentName ,
275
- areMutuallyExclusive ,
276
- )
277
- ) {
278
- continue ;
279
- }
280
- comparedFragmentPairs . add (
281
- referencedFragmentName ,
282
- fragmentName ,
283
- areMutuallyExclusive ,
284
- ) ;
285
-
286
- collectConflictsBetweenFieldsAndFragment (
287
- context ,
288
- conflicts ,
289
- cachedFieldsAndFragmentNames ,
290
- comparedFragmentPairs ,
291
- areMutuallyExclusive ,
292
- fieldMap ,
293
- referencedFragmentName ,
294
- ) ;
295
- }
302
+ discoveredFragments . push ( ...referencedFragmentNames . map ( referencedFragmentName => [ fragmentName , referencedFragmentName ] ) ) ;
296
303
}
297
304
298
305
// Collect all conflicts found between two fragments, including via spreading in
@@ -433,6 +440,7 @@ function findConflictsBetweenSubSelectionSets(
433
440
areMutuallyExclusive ,
434
441
fieldMap1 ,
435
442
fragmentName2 ,
443
+ [ ]
436
444
) ;
437
445
}
438
446
@@ -447,6 +455,7 @@ function findConflictsBetweenSubSelectionSets(
447
455
areMutuallyExclusive ,
448
456
fieldMap2 ,
449
457
fragmentName1 ,
458
+ [ ]
450
459
) ;
451
460
}
452
461
0 commit comments