Skip to content

Commit

Permalink
fix(validation): catch OverlappingFieldsCanBeMergedRule violations wi…
Browse files Browse the repository at this point in the history
…th nested fragments (graphql#4168)

Port of graphql#4168 to v17
  • Loading branch information
sachindshinde authored and yaacovCR committed Sep 23, 2024
1 parent 7875552 commit 23e2ba9
Show file tree
Hide file tree
Showing 2 changed files with 150 additions and 45 deletions.
54 changes: 54 additions & 0 deletions src/validation/__tests__/OverlappingFieldsCanBeMergedRule-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,33 @@ describe('Validate: Overlapping fields can be merged', () => {
]);
});

it('reports deep conflict after nested fragments', () => {
expectErrors(`
fragment F on T {
...G
}
fragment G on T {
...H
}
fragment H on T {
x: a
}
{
x: b
...F
}
`).toDeepEqual([
{
message:
'Fields "x" conflict because "b" and "a" are different fields. Use different aliases on the fields to fetch both if this was intentional.',
locations: [
{ line: 12, column: 9 },
{ line: 9, column: 9 },
],
},
]);
});

it('ignores unknown fragments', () => {
expectValid(`
{
Expand Down Expand Up @@ -1265,6 +1292,33 @@ describe('Validate: Overlapping fields can be merged', () => {
]);
});

it('does not infinite loop on recursive fragments separated by fields', () => {
expectValid(`
{
...fragA
...fragB
}
fragment fragA on T {
x {
...fragA
x {
...fragA
}
}
}
fragment fragB on T {
x {
...fragB
x {
...fragB
}
}
}
`);
});

describe('fragment arguments must produce fields that can be merged', () => {
it('allows conflicting spreads at different depths', () => {
expectValid(`
Expand Down
Loading

0 comments on commit 23e2ba9

Please sign in to comment.