Skip to content

Commit 6691a7d

Browse files
committed
fix: plan generator ignores the skip/include directives
This allows to print all query nodes, even those that would not be executed because of directives like "skip", "include".
1 parent 589d43b commit 6691a7d

File tree

9 files changed

+55
-9
lines changed

9 files changed

+55
-9
lines changed

router-tests/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ require (
2727
github.com/wundergraph/cosmo/demo/pkg/subgraphs/projects v0.0.0-20250715110703-10f2e5f9c79e
2828
github.com/wundergraph/cosmo/router v0.0.0-20250729121718-5f0a0b8b1804
2929
github.com/wundergraph/cosmo/router-plugin v0.0.0-20250616075713-f2b99c96cec4
30-
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.216
30+
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.216.0.20250806095839-fa127e050872
3131
go.opentelemetry.io/otel v1.28.0
3232
go.opentelemetry.io/otel/sdk v1.28.0
3333
go.opentelemetry.io/otel/sdk/metric v1.28.0

router-tests/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,8 @@ github.com/wundergraph/astjson v0.0.0-20250106123708-be463c97e083 h1:8/D7f8gKxTB
325325
github.com/wundergraph/astjson v0.0.0-20250106123708-be463c97e083/go.mod h1:eOTL6acwctsN4F3b7YE+eE2t8zcJ/doLm9sZzsxxxrE=
326326
github.com/wundergraph/consul/sdk v0.0.0-20250204115147-ed842a8fd301 h1:EzfKHQoTjFDDcgaECCCR2aTePqMu9QBmPbyhqIYOhV0=
327327
github.com/wundergraph/consul/sdk v0.0.0-20250204115147-ed842a8fd301/go.mod h1:wxI0Nak5dI5RvJuzGyiEK4nZj0O9X+Aw6U0tC1wPKq0=
328-
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.216 h1:fmm0e7VSNu4BX094ZJnC9u2AJJ5FnWNDgmxPug/O9LU=
329-
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.216/go.mod h1:DnYY1alnsgzkanSwbFiFIdXKOuf8dHQWQ2P4BzTc6aI=
328+
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.216.0.20250806095839-fa127e050872 h1:IMpyWdecTKARCQurrFZt3fzVaq3l5eP7lU8ZT8ETKiI=
329+
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.216.0.20250806095839-fa127e050872/go.mod h1:DnYY1alnsgzkanSwbFiFIdXKOuf8dHQWQ2P4BzTc6aI=
330330
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 h1:gEOO8jv9F4OT7lGCjxCBTO/36wtF6j2nSip77qHd4x4=
331331
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM=
332332
github.com/yosida95/uritemplate/v3 v3.0.2 h1:Ed3Oyj9yrmi9087+NczuL5BwkIc4wvTb5zIM+UJPGz4=

router/core/plan_generator.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,15 @@ func (pl *Planner) normalizeOperation(operation *ast.Document, operationName []b
125125

126126
report := operationreport.Report{}
127127

128-
astnormalization.NormalizeNamedOperation(operation, pl.definition, operationName, &report)
128+
normalizer := astnormalization.NewWithOpts(
129+
astnormalization.WithRemoveNotMatchingOperationDefinitions(),
130+
astnormalization.WithExtractVariables(),
131+
astnormalization.WithRemoveFragmentDefinitions(),
132+
astnormalization.WithInlineFragmentSpreads(),
133+
astnormalization.WithRemoveUnusedVariables(),
134+
astnormalization.WithIgnoreSkipInclude(),
135+
)
136+
normalizer.NormalizeNamedOperation(operation, pl.definition, operationName, &report)
129137
if report.HasErrors() {
130138
return report
131139
}

router/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ require (
3131
github.com/tidwall/gjson v1.18.0
3232
github.com/tidwall/sjson v1.2.5
3333
github.com/twmb/franz-go v1.16.1
34-
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.216
34+
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.216.0.20250806095839-fa127e050872
3535
// Do not upgrade, it renames attributes we rely on
3636
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.46.1
3737
go.opentelemetry.io/contrib/propagators/b3 v1.23.0

router/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,8 @@ github.com/vektah/gqlparser/v2 v2.5.16 h1:1gcmLTvs3JLKXckwCwlUagVn/IlV2bwqle0vJ0
290290
github.com/vektah/gqlparser/v2 v2.5.16/go.mod h1:1lz1OeCqgQbQepsGxPVywrjdBHW2T08PUS3pJqepRww=
291291
github.com/wundergraph/astjson v0.0.0-20250106123708-be463c97e083 h1:8/D7f8gKxTBjW+SZK4mhxTTBVpxcqeBgWF1Rfmltbfk=
292292
github.com/wundergraph/astjson v0.0.0-20250106123708-be463c97e083/go.mod h1:eOTL6acwctsN4F3b7YE+eE2t8zcJ/doLm9sZzsxxxrE=
293-
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.216 h1:fmm0e7VSNu4BX094ZJnC9u2AJJ5FnWNDgmxPug/O9LU=
294-
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.216/go.mod h1:DnYY1alnsgzkanSwbFiFIdXKOuf8dHQWQ2P4BzTc6aI=
293+
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.216.0.20250806095839-fa127e050872 h1:IMpyWdecTKARCQurrFZt3fzVaq3l5eP7lU8ZT8ETKiI=
294+
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.216.0.20250806095839-fa127e050872/go.mod h1:DnYY1alnsgzkanSwbFiFIdXKOuf8dHQWQ2P4BzTc6aI=
295295
github.com/yosida95/uritemplate/v3 v3.0.2 h1:Ed3Oyj9yrmi9087+NczuL5BwkIc4wvTb5zIM+UJPGz4=
296296
github.com/yosida95/uritemplate/v3 v3.0.2/go.mod h1:ILOh0sOhIJR3+L/8afwt/kE++YT040gmv5BQTMR2HP4=
297297
github.com/yuin/gopher-lua v1.1.1 h1:kYKnWBjvbNP4XLT3+bPEwAXJx262OhaHDWDVOPjL46M=

router/pkg/plan_generator/plan_generator_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func getTestDataDir() string {
2020
}
2121

2222
func TestPlanGenerator(t *testing.T) {
23-
allFiles := []string{"1.graphql", "2.graphql", "3.graphql", "4.graphql"}
23+
allFiles := []string{"1.graphql", "2.graphql", "3.graphql", "4.graphql", "5.graphql"}
2424
filtered := allFiles[0]
2525

2626
t.Run("checks queries path exists", func(t *testing.T) {
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
QueryPlan {
2+
Sequence {
3+
Fetch(service: "employees") {
4+
{
5+
employees {
6+
id
7+
tag
8+
__typename
9+
}
10+
}
11+
}
12+
Fetch(service: "products") {
13+
{
14+
fragment Key on Employee {
15+
__typename
16+
id
17+
}
18+
} =>
19+
{
20+
_entities(representations: $representations){
21+
... on Employee {
22+
__typename
23+
notes
24+
}
25+
}
26+
}
27+
}
28+
}
29+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"plans":[{"file_name":"1.graphql","plan":"QueryPlan {\n Sequence {\n Fetch(service: \"employees\") {\n {\n employees {\n tag\n __typename\n id\n }\n products {\n __typename\n }\n }\n }\n Fetch(service: \"products\") {\n {\n fragment Key on Employee {\n __typename\n id\n }\n } =\u003e\n {\n _entities(representations: $representations){\n ... on Employee {\n __typename\n notes\n }\n }\n }\n }\n }\n}\n"},{"file_name":"2.graphql","warning":"external: unexpected literal - got: UNDEFINED want one of: [ENUM TYPE UNION QUERY INPUT EXTEND SCHEMA SCALAR FRAGMENT INTERFACE DIRECTIVE], locations: [{Line:1 Column:1}], path: []"},{"file_name":"3.graphql","plan":"QueryPlan {\n Subscription {\n Primary: {\n Fetch(service: \"employees\") {\n {\n currentTime {\n __typename\n timeStamp\n }\n }\n }\n },\n }\n}\n"},{"file_name":"4.graphql","plan":"QueryPlan {\n Subscription {\n Primary: {\n Fetch(service: \"2-nats-3\") {\n }\n },\n Rest: {\n Fetch(service: \"employees\") {\n {\n fragment Key on Employee {\n __typename\n id\n }\n } =\u003e\n {\n _entities(representations: $representations){\n ... on Employee {\n __typename\n tag\n }\n }\n }\n }\n },\n }\n}\n"}]}
1+
{"plans":[{"file_name":"1.graphql","plan":"QueryPlan {\n Sequence {\n Fetch(service: \"employees\") {\n {\n employees {\n tag\n __typename\n id\n }\n products {\n __typename\n }\n }\n }\n Fetch(service: \"products\") {\n {\n fragment Key on Employee {\n __typename\n id\n }\n } =\u003e\n {\n _entities(representations: $representations){\n ... on Employee {\n __typename\n notes\n }\n }\n }\n }\n }\n}\n"},{"file_name":"2.graphql","warning":"external: unexpected literal - got: UNDEFINED want one of: [ENUM TYPE UNION QUERY INPUT EXTEND SCHEMA SCALAR FRAGMENT INTERFACE DIRECTIVE], locations: [{Line:1 Column:1}], path: []"},{"file_name":"3.graphql","plan":"QueryPlan {\n Subscription {\n Primary: {\n Fetch(service: \"employees\") {\n {\n currentTime {\n __typename\n timeStamp\n }\n }\n }\n },\n }\n}\n"},{"file_name":"4.graphql","plan":"QueryPlan {\n Subscription {\n Primary: {\n Fetch(service: \"2-nats-3\") {\n }\n },\n Rest: {\n Fetch(service: \"employees\") {\n {\n fragment Key on Employee {\n __typename\n id\n }\n } =\u003e\n {\n _entities(representations: $representations){\n ... on Employee {\n __typename\n tag\n }\n }\n }\n }\n },\n }\n}\n"},{"file_name":"5.graphql","plan":"QueryPlan {\n Sequence {\n Fetch(service: \"employees\") {\n {\n employees {\n id\n tag\n __typename\n }\n }\n }\n Fetch(service: \"products\") {\n {\n fragment Key on Employee {\n __typename\n id\n }\n } =\u003e\n {\n _entities(representations: $representations){\n ... on Employee {\n __typename\n notes\n }\n }\n }\n }\n }\n}\n"}]}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
query SkipIncludeNodesAreNotRemoved($t: Boolean = true, $f: Boolean = false) {
2+
employees {
3+
id @include(if: $f)
4+
... @skip(if: $t) {
5+
tag
6+
}
7+
notes @include(if: $f)
8+
}
9+
}

0 commit comments

Comments
 (0)