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 (#4168)

In trying to prevent infinite loops, #3442 introduced a bug that causes certain violations of the [Field Selection Merging](https://spec.graphql.org/draft/#sec-Field-Selection-Merging) validation to not be caught (released in `16.3.0`, and backported to `15.9.0`). This PR fixes this bug, while continuing to prevent infinite loops.
  • Loading branch information
sachindshinde authored Sep 23, 2024
1 parent 993d7ce commit 45e28a5
Show file tree
Hide file tree
Showing 2 changed files with 149 additions and 44 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 @@ -548,6 +548,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 @@ -1138,4 +1165,31 @@ 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
}
}
}
`);
});
});
Loading

0 comments on commit 45e28a5

Please sign in to comment.