Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion router-tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ require (
github.com/wundergraph/cosmo/demo/pkg/subgraphs/projects v0.0.0-20250715110703-10f2e5f9c79e
github.com/wundergraph/cosmo/router v0.0.0-20250729121718-5f0a0b8b1804
github.com/wundergraph/cosmo/router-plugin v0.0.0-20250616075713-f2b99c96cec4
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.216
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.217
go.opentelemetry.io/otel v1.28.0
go.opentelemetry.io/otel/sdk v1.28.0
go.opentelemetry.io/otel/sdk/metric v1.28.0
Expand Down
4 changes: 2 additions & 2 deletions router-tests/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,8 @@ github.com/wundergraph/astjson v0.0.0-20250106123708-be463c97e083 h1:8/D7f8gKxTB
github.com/wundergraph/astjson v0.0.0-20250106123708-be463c97e083/go.mod h1:eOTL6acwctsN4F3b7YE+eE2t8zcJ/doLm9sZzsxxxrE=
github.com/wundergraph/consul/sdk v0.0.0-20250204115147-ed842a8fd301 h1:EzfKHQoTjFDDcgaECCCR2aTePqMu9QBmPbyhqIYOhV0=
github.com/wundergraph/consul/sdk v0.0.0-20250204115147-ed842a8fd301/go.mod h1:wxI0Nak5dI5RvJuzGyiEK4nZj0O9X+Aw6U0tC1wPKq0=
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.216 h1:fmm0e7VSNu4BX094ZJnC9u2AJJ5FnWNDgmxPug/O9LU=
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.216/go.mod h1:DnYY1alnsgzkanSwbFiFIdXKOuf8dHQWQ2P4BzTc6aI=
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.217 h1:/yi6IC+Ei4i8QEOQS+qjETG4per2pa6cluzoa1dyLtw=
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.217/go.mod h1:DnYY1alnsgzkanSwbFiFIdXKOuf8dHQWQ2P4BzTc6aI=
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 h1:gEOO8jv9F4OT7lGCjxCBTO/36wtF6j2nSip77qHd4x4=
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM=
github.com/yosida95/uritemplate/v3 v3.0.2 h1:Ed3Oyj9yrmi9087+NczuL5BwkIc4wvTb5zIM+UJPGz4=
Expand Down
10 changes: 9 additions & 1 deletion router/core/plan_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,15 @@ func (pl *Planner) normalizeOperation(operation *ast.Document, operationName []b

report := operationreport.Report{}

astnormalization.NormalizeNamedOperation(operation, pl.definition, operationName, &report)
normalizer := astnormalization.NewWithOpts(
astnormalization.WithRemoveNotMatchingOperationDefinitions(),
astnormalization.WithExtractVariables(),
astnormalization.WithRemoveFragmentDefinitions(),
astnormalization.WithInlineFragmentSpreads(),
astnormalization.WithRemoveUnusedVariables(),
astnormalization.WithIgnoreSkipInclude(),
)
normalizer.NormalizeNamedOperation(operation, pl.definition, operationName, &report)
if report.HasErrors() {
return report
}
Expand Down
2 changes: 1 addition & 1 deletion router/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ require (
github.com/tidwall/gjson v1.18.0
github.com/tidwall/sjson v1.2.5
github.com/twmb/franz-go v1.16.1
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.216
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.217
// Do not upgrade, it renames attributes we rely on
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.46.1
go.opentelemetry.io/contrib/propagators/b3 v1.23.0
Expand Down
4 changes: 2 additions & 2 deletions router/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,8 @@ github.com/vektah/gqlparser/v2 v2.5.16 h1:1gcmLTvs3JLKXckwCwlUagVn/IlV2bwqle0vJ0
github.com/vektah/gqlparser/v2 v2.5.16/go.mod h1:1lz1OeCqgQbQepsGxPVywrjdBHW2T08PUS3pJqepRww=
github.com/wundergraph/astjson v0.0.0-20250106123708-be463c97e083 h1:8/D7f8gKxTBjW+SZK4mhxTTBVpxcqeBgWF1Rfmltbfk=
github.com/wundergraph/astjson v0.0.0-20250106123708-be463c97e083/go.mod h1:eOTL6acwctsN4F3b7YE+eE2t8zcJ/doLm9sZzsxxxrE=
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.216 h1:fmm0e7VSNu4BX094ZJnC9u2AJJ5FnWNDgmxPug/O9LU=
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.216/go.mod h1:DnYY1alnsgzkanSwbFiFIdXKOuf8dHQWQ2P4BzTc6aI=
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.217 h1:/yi6IC+Ei4i8QEOQS+qjETG4per2pa6cluzoa1dyLtw=
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.217/go.mod h1:DnYY1alnsgzkanSwbFiFIdXKOuf8dHQWQ2P4BzTc6aI=
github.com/yosida95/uritemplate/v3 v3.0.2 h1:Ed3Oyj9yrmi9087+NczuL5BwkIc4wvTb5zIM+UJPGz4=
github.com/yosida95/uritemplate/v3 v3.0.2/go.mod h1:ILOh0sOhIJR3+L/8afwt/kE++YT040gmv5BQTMR2HP4=
github.com/yuin/gopher-lua v1.1.1 h1:kYKnWBjvbNP4XLT3+bPEwAXJx262OhaHDWDVOPjL46M=
Expand Down
11 changes: 9 additions & 2 deletions router/pkg/plan_generator/plan_generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"path"
"path/filepath"
"runtime"
"strings"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -20,8 +21,14 @@ func getTestDataDir() string {
}

func TestPlanGenerator(t *testing.T) {
allFiles := []string{"1.graphql", "2.graphql", "3.graphql", "4.graphql"}
filtered := allFiles[0]
entries, _ := os.ReadDir(path.Join(getTestDataDir(), "queries", "base"))
allFiles := make([]string, 0, len(entries))
for _, e := range entries {
if !e.IsDir() && strings.HasSuffix(e.Name(), ".graphql") {
allFiles = append(allFiles, e.Name())
}
}
filtered := "1.graphql"

t.Run("checks queries path exists", func(t *testing.T) {
tempDir, err := os.MkdirTemp("", "plans-")
Expand Down
29 changes: 29 additions & 0 deletions router/pkg/plan_generator/testdata/plans/base/5.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
QueryPlan {
Sequence {
Fetch(service: "employees") {
{
employees {
id
tag
__typename
}
}
}
Fetch(service: "products") {
{
fragment Key on Employee {
__typename
id
}
} =>
{
_entities(representations: $representations){
... on Employee {
__typename
notes
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -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"}]}
{"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"}]}
9 changes: 9 additions & 0 deletions router/pkg/plan_generator/testdata/queries/base/5.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
query SkipIncludeNodesAreNotRemoved($t: Boolean = true, $f: Boolean = false) {
employees {
id @include(if: $f)
... @skip(if: $t) {
tag
}
notes @include(if: $f)
}
}
Loading