Prevent sending union type to wrong service, only query union subselection#231
Merged
JohnStarich merged 3 commits intomasterfrom May 5, 2026
Merged
Conversation
0cefb55 to
de5ea17
Compare
JohnStarich
commented
Apr 28, 2026
Comment on lines
+1906
to
+1919
| for step := range allSteps(plans[0].RootStep) { | ||
| url := step.Queryer.(*graphql.SingleRequestQueryer).URL() | ||
| t.Logf("Found step on %q: %s", url, step.QueryString) | ||
| switch url { | ||
| case location0: | ||
| assert.NotContains(t, step.QueryString, "Foo", "Location 0 must not be called with 'Foo' union type") | ||
| assert.Equal(t, strings.TrimSpace(` | ||
| query($id: ID!) { | ||
| node(id: $id) { | ||
| ... on Bar { | ||
| bar | ||
| } | ||
| } | ||
| }`), strings.TrimSpace(step.QueryString)) |
Member
Author
There was a problem hiding this comment.
Currently failing here with:
--- FAIL: TestPlanQuery_unionShouldNotBeQueriedOnOtherServices (0.00s)
plan_test.go:1908: Found step on "": query {
id
}
plan_test.go:1908: Found step on "url1": query {
foo {
id
}
}
plan_test.go:1908: Found step on "url0": query ($id: ID!) {
node(id: $id) {
... on Foo {
... on Bar {
bar
}
}
}
}
plan_test.go:1911:
Error Trace: plan_test.go:1911
Error: "query ($id: ID!) {\n\tnode(id: $id) {\n\t\t... on Foo {\n\t\t\t... on Bar {\n\t\t\t\tbar\n\t\t\t}\n\t\t}\n\t}\n}\n" should not contain "Foo"
Test: TestPlanQuery_unionShouldNotBeQueriedOnOtherServices
Messages: Location 0 must not be called with 'Foo' union type
plan_test.go:1912:
Error Trace: plan_test.go:1912
Error: Not equal:
expected: "query($id: ID!) {\n\tnode(id: $id) {\n\t\t... on Bar {\n\t\t\tbar\n\t\t}\n\t}\n}"
actual : "query ($id: ID!) {\n\tnode(id: $id) {\n\t\t... on Foo {\n\t\t\t... on Bar {\n\t\t\t\tbar\n\t\t\t}\n\t\t}\n\t}\n}"
Diff:
--- Expected
+++ Actual
@@ -1,5 +1,7 @@
-query($id: ID!) {
+query ($id: ID!) {
node(id: $id) {
- ... on Bar {
- bar
+ ... on Foo {
+ ... on Bar {
+ bar
+ }
}
Collapse union selection set into one flat set of fragment subselections. We can make this assumption because the GraphQL spec requires union types be object types. https://spec.graphql.org/October2021/#sec-Unions
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #230
We can make this assumption because the GraphQL spec requires union types be object types: