Skip to content

Commit d1ab473

Browse files
committed
Fix false positive validation error from fragment cycle when unknown fragment is used
Closes #36.
1 parent 0c67f8f commit d1ab473

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

graphql/core/validation/rules/no_fragment_cycles.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ def enter_FragmentDefinition(self, node, key, parent, path, ancestors):
2222
spread_path = []
2323

2424
def detect_cycle_recursive(fragment_name):
25-
spread_nodes = self.spreads_in_fragment[fragment_name]
25+
spread_nodes = self.spreads_in_fragment.get(fragment_name)
26+
if not spread_nodes:
27+
return
2628

2729
for spread_node in spread_nodes:
2830
if spread_node in self.known_to_lead_to_cycle:

tests/core_validation/test_no_fragment_cycles.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ def test_double_spread_within_abstract_types():
4545
''')
4646

4747

48+
def test_does_not_raise_false_positive_on_unknown_fragment():
49+
expect_passes_rule(NoFragmentCycles, '''
50+
fragment nameFragment on Pet {
51+
...UnknownFragment
52+
}
53+
''')
54+
55+
4856
def test_spreading_recursively_within_field_fails():
4957
expect_fails_rule(NoFragmentCycles, '''
5058
fragment fragA on Human { relatives { ...fragA } },

0 commit comments

Comments
 (0)