Skip to content

Commit 23e2ba9

Browse files
sachindshindeyaacovCR
authored andcommitted
fix(validation): catch OverlappingFieldsCanBeMergedRule violations with nested fragments (graphql#4168)
Port of graphql#4168 to v17
1 parent 7875552 commit 23e2ba9

File tree

2 files changed

+150
-45
lines changed

2 files changed

+150
-45
lines changed

src/validation/__tests__/OverlappingFieldsCanBeMergedRule-test.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,33 @@ describe('Validate: Overlapping fields can be merged', () => {
674674
]);
675675
});
676676

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 },
699+
],
700+
},
701+
]);
702+
});
703+
677704
it('ignores unknown fragments', () => {
678705
expectValid(`
679706
{
@@ -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)