Skip to content

Commit c1d9693

Browse files
authored
Merge pull request graph-gophers#399 from rudle/fragment-not-used-bug
bugfix: correctly determine fragment usage
2 parents 83ba819 + 96ea6f0 commit c1d9693

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

internal/validation/testdata/tests.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1464,6 +1464,13 @@
14641464
"query": "\n query Foo($a: String, $b: String, $c: String) {\n ... on Type {\n field(a: $a) {\n field(b: $b) {\n ... on Type {\n field(c: $c)\n }\n }\n }\n }\n }\n ",
14651465
"errors": []
14661466
},
1467+
{
1468+
"name": "Validate: fragments are used even when they are nested",
1469+
"rule": "NoUnusedFragments",
1470+
"schema": 1,
1471+
"query": "\n query Foo() {\n ...StringFragment\n stringBox {\n ...StringFragment\n ...StringFragmentPrime\n}\n}\n\n\n fragment StringFragment on StringBox {\n scalar\n}\n\n fragment StringFragmentPrime on StringBox {\n unrelatedField\n}\n",
1472+
"errors": []
1473+
},
14671474
{
14681475
"name": "Validate: No unused variables/uses all variables in fragments",
14691476
"rule": "NoUnusedVariables",
@@ -3853,4 +3860,4 @@
38533860
]
38543861
}
38553862
]
3856-
}
3863+
}

internal/validation/validation.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,8 +418,9 @@ func markUsedFragments(c *context, sels []query.Selection, fragUsed map[*query.F
418418
}
419419

420420
if _, ok := fragUsed[frag]; ok {
421-
return
421+
continue
422422
}
423+
423424
fragUsed[frag] = struct{}{}
424425
markUsedFragments(c, frag.Selections, fragUsed)
425426

0 commit comments

Comments
 (0)