-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix validation stack overflow for fragment cycles inside nested fields
Previously fragment cycle detection only counted fragments that are directly recursive, where the top-level selection for the fragment included a fragment spread of itself. But spreading a fragment anywhere inside a nested field is also problematic and prohibited by spec, because even if the field you're spreading into is nullable, the client can't know how deep that recursion goes, and it could be infinite. Fixes #716
- Loading branch information
1 parent
ef45fd0
commit f7fd841
Showing
4 changed files
with
43 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 14 additions & 3 deletions
17
crates/apollo-compiler/test_data/diagnostics/0092_recursive_fragment_spread.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,23 @@ | ||
Error: `fragA` fragment cannot reference itself | ||
╭─[0092_recursive_fragment_spread.graphql:13:1] | ||
╭─[0092_recursive_fragment_spread.graphql:14:1] | ||
│ | ||
13 │ fragment fragA on Human { name, ...fragB } | ||
14 │ fragment fragA on Human { name, ...fragB } | ||
│ ───────┬────── | ||
│ ╰──────── recursive fragment definition | ||
│ | ||
15 │ fragment fragC on Human { name, ...fragA } | ||
16 │ fragment fragC on Human { name, ...fragA } | ||
│ ────┬─── | ||
│ ╰───── refers to itself here | ||
────╯ | ||
Error: `cycle1` fragment cannot reference itself | ||
╭─[0092_recursive_fragment_spread.graphql:19:1] | ||
│ | ||
19 │ fragment cycle1 on __Type { kind, ...cycle2 } | ||
│ ───────┬─────── | ||
│ ╰───────── recursive fragment definition | ||
│ | ||
23 │ ofType { ...cycle1 } | ||
│ ────┬──── | ||
│ ╰────── refers to itself here | ||
────╯ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters