-
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 (
#733) * 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 * label every fragment participating in a cycle * use push() instead of repetitive insert(0,x)
- Loading branch information
1 parent
074d599
commit 30731e6
Showing
4 changed files
with
94 additions
and
22 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
31 changes: 24 additions & 7 deletions
31
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,29 @@ | ||
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 } | ||
│ ───────┬────── | ||
│ ╰──────── recursive fragment definition | ||
│ | ||
15 │ fragment fragC on Human { name, ...fragA } | ||
14 │ fragment fragA on Human { name, ...fragB } | ||
│ ───────┬────── ────┬─── | ||
│ ╰────────────────────────────────── recursive fragment definition | ||
│ │ | ||
│ ╰───── `fragA` references `fragB` here... | ||
15 │ fragment fragB on Human { name, ...fragC } | ||
│ ────┬─── | ||
│ ╰───── `fragB` references `fragC` here... | ||
16 │ fragment fragC on Human { name, ...fragA } | ||
│ ────┬─── | ||
│ ╰───── refers to itself here | ||
│ ╰───── `fragC` circularly references `fragA` here | ||
────╯ | ||
Error: `cycle1` fragment cannot reference itself | ||
╭─[0092_recursive_fragment_spread.graphql:19:1] | ||
│ | ||
19 │ fragment cycle1 on __Type { kind, ...cycle2 } | ||
│ ───────┬─────── ────┬──── | ||
│ ╰───────────────────────────────────── recursive fragment definition | ||
│ │ | ||
│ ╰────── `cycle1` references `cycle2` here... | ||
│ | ||
23 │ ofType { ...cycle1 } | ||
│ ────┬──── | ||
│ ╰────── `cycle2` circularly references `cycle1` 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