Skip to content

Commit e52ed9a

Browse files
authored
fix(validation): catch OverlappingFieldsCanBeMergedRule violations with nested fragments (#4168) (#4199)
1 parent 7875552 commit e52ed9a

File tree

2 files changed

+157
-52
lines changed

2 files changed

+157
-52
lines changed

src/validation/__tests__/OverlappingFieldsCanBeMergedRule-test.ts

Lines changed: 61 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -638,10 +638,10 @@ describe('Validate: Overlapping fields can be merged', () => {
638638
expectErrors(`
639639
{
640640
field {
641-
...F
641+
...I
642642
}
643643
field {
644-
...I
644+
...F
645645
}
646646
}
647647
fragment F on T {
@@ -661,14 +661,41 @@ describe('Validate: Overlapping fields can be merged', () => {
661661
`).toDeepEqual([
662662
{
663663
message:
664-
'Fields "field" conflict because subfields "x" conflict because "a" and "b" are different fields and subfields "y" conflict because "c" and "d" are different fields. Use different aliases on the fields to fetch both if this was intentional.',
664+
'Fields "field" conflict because subfields "y" conflict because "d" and "c" are different fields and subfields "x" conflict because "b" and "a" are different fields. Use different aliases on the fields to fetch both if this was intentional.',
665665
locations: [
666666
{ line: 3, column: 9 },
667-
{ line: 11, column: 9 },
668-
{ line: 15, column: 9 },
669-
{ line: 6, column: 9 },
670-
{ line: 22, column: 9 },
671667
{ line: 18, column: 9 },
668+
{ line: 22, column: 9 },
669+
{ line: 6, column: 9 },
670+
{ line: 15, column: 9 },
671+
{ line: 11, column: 9 },
672+
],
673+
},
674+
]);
675+
});
676+
677+
it('reports deep conflict after nested fragments', () => {
678+
expectErrors(`
679+
fragment F on T {
680+
...G
681+
}
682+
fragment G on T {
683+
...H
684+
}
685+
fragment H on T {
686+
x: a
687+
}
688+
{
689+
x: b
690+
...F
691+
}
692+
`).toDeepEqual([
693+
{
694+
message:
695+
'Fields "x" conflict because "b" and "a" are different fields. Use different aliases on the fields to fetch both if this was intentional.',
696+
locations: [
697+
{ line: 12, column: 9 },
698+
{ line: 9, column: 9 },
672699
],
673700
},
674701
]);
@@ -1265,6 +1292,33 @@ describe('Validate: Overlapping fields can be merged', () => {
12651292
]);
12661293
});
12671294

1295+
it('does not infinite loop on recursive fragments separated by fields', () => {
1296+
expectValid(`
1297+
{
1298+
...fragA
1299+
...fragB
1300+
}
1301+
1302+
fragment fragA on T {
1303+
x {
1304+
...fragA
1305+
x {
1306+
...fragA
1307+
}
1308+
}
1309+
}
1310+
1311+
fragment fragB on T {
1312+
x {
1313+
...fragB
1314+
x {
1315+
...fragB
1316+
}
1317+
}
1318+
}
1319+
`);
1320+
});
1321+
12681322
describe('fragment arguments must produce fields that can be merged', () => {
12691323
it('allows conflicting spreads at different depths', () => {
12701324
expectValid(`

0 commit comments

Comments
 (0)