Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(router): allow operation name propagation #1394

Merged
merged 5 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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/twmb/franz-go/pkg/kadm v1.11.0
github.com/wundergraph/cosmo/demo v0.0.0-20241118164309-37af7e49ffff
github.com/wundergraph/cosmo/router v0.0.0-20241118164309-37af7e49ffff
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.127
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.128
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 @@ -350,8 +350,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-20241108124845-44485579ffa5 h1:rc+IQxG3rrAXEjBywirkzhKkyCKvXLGQXABVD8GiUtU=
github.com/wundergraph/astjson v0.0.0-20241108124845-44485579ffa5/go.mod h1:eOTL6acwctsN4F3b7YE+eE2t8zcJ/doLm9sZzsxxxrE=
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.127 h1:LSSGHxnLXCmOyS9GLgEbxt5g2mFukywii3v/SFSUxfs=
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.127/go.mod h1:s4r/lhVEU5s0c6tCgpR0hK6FHEmX0cbrKcMU1pMc/ZI=
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.128 h1:0qFNHSFjXLBOEeeaIY8Pa5usEW//yTQY3ahIQnPouG8=
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.128/go.mod h1:s4r/lhVEU5s0c6tCgpR0hK6FHEmX0cbrKcMU1pMc/ZI=
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 h1:+qGGcbkzsfDQNPPe9UDgpxAWQrhbbBXOYJFQDq/dtJw=
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913/go.mod h1:4aEEwZQutDLsQv2Deui4iYQ6DWTxR14g6m8Wv88+Xqk=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down
26 changes: 26 additions & 0 deletions router-tests/query_plans_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,30 @@ func TestQueryPlans(t *testing.T) {
}
})
})
t.Run("include operation name in each request", func(t *testing.T) {
testenv.Run(t, &testenv.Config{
ModifyEngineExecutionConfiguration: func(cfg *config.EngineExecutionConfiguration) {
cfg.Debug.AlwaysIncludeQueryPlan = true
cfg.EnableOperationNameToSubgraphPropagation = true
StarpTech marked this conversation as resolved.
Show resolved Hide resolved
},
}, func(t *testing.T, xEnv *testenv.Environment) {
res := xEnv.MakeGraphQLRequestOK(testenv.GraphQLRequest{
Query: `query Requires {
products {
__typename
... on Consultancy {
lead {
__typename
id
derivedMood
}
isLeadAvailable
}
}
}`,
})

g.Assert(t, "response_with_query_plan_operation_name", prettifyJSON(res.Body))
})
})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
{
"data": {
"products": [
{
"__typename": "Consultancy",
"lead": {
"__typename": "Employee",
"id": 1,
"derivedMood": "HAPPY"
},
"isLeadAvailable": false
},
{
"__typename": "Cosmo"
},
{
"__typename": "SDK"
}
]
},
"extensions": {
"queryPlan": {
"version": "1",
"kind": "Sequence",
"children": [
{
"kind": "Single",
"fetch": {
"kind": "Single",
"subgraphName": "employees",
"subgraphId": "0",
"fetchId": 0,
"query": "query Requires__employees__0 {\n products {\n __typename\n ... on Consultancy {\n lead {\n __typename\n id\n }\n __typename\n upc\n }\n }\n}"
}
},
{
"kind": "Parallel",
"children": [
{
"kind": "Single",
"fetch": {
"kind": "BatchEntity",
"path": "[email protected]",
"subgraphName": "mood",
"subgraphId": "6",
"fetchId": 1,
"dependsOnFetchIds": [
0
],
"representations": [
{
"kind": "@key",
"typeName": "Employee",
"fragment": "fragment Key on Employee {\n __typename\n id\n}"
}
],
"query": "query Requires__mood__1($representations: [_Any!]!){\n _entities(representations: $representations){\n ... on Employee {\n __typename\n currentMood\n }\n }\n}"
}
},
{
"kind": "Single",
"fetch": {
"kind": "BatchEntity",
"path": "[email protected]",
"subgraphName": "availability",
"subgraphId": "5",
"fetchId": 2,
"dependsOnFetchIds": [
0
],
"representations": [
{
"kind": "@key",
"typeName": "Employee",
"fragment": "fragment Key on Employee {\n __typename\n id\n}"
}
],
"query": "query Requires__availability__2($representations: [_Any!]!){\n _entities(representations: $representations){\n ... on Employee {\n __typename\n isAvailable\n }\n }\n}"
}
}
]
},
{
"kind": "Parallel",
"children": [
{
"kind": "Single",
"fetch": {
"kind": "BatchEntity",
"path": "[email protected]",
"subgraphName": "employees",
"subgraphId": "0",
"fetchId": 3,
"dependsOnFetchIds": [
0,
1
],
"representations": [
{
"kind": "@requires",
"typeName": "Employee",
"fieldName": "derivedMood",
"fragment": "fragment Requires_for_derivedMood on Employee {\n currentMood\n}"
},
{
"kind": "@key",
"typeName": "Employee",
"fragment": "fragment Key on Employee {\n __typename\n id\n}"
}
],
"query": "query Requires__employees__3($representations: [_Any!]!){\n _entities(representations: $representations){\n ... on Employee {\n __typename\n derivedMood\n }\n }\n}"
}
},
{
"kind": "Single",
"fetch": {
"kind": "BatchEntity",
"path": "products",
"subgraphName": "employees",
"subgraphId": "0",
"fetchId": 4,
"dependsOnFetchIds": [
0,
2
],
"representations": [
{
"kind": "@requires",
"typeName": "Consultancy",
"fieldName": "isLeadAvailable",
"fragment": "fragment Requires_for_isLeadAvailable on Consultancy {\n lead {\n isAvailable\n }\n}"
},
{
"kind": "@key",
"typeName": "Consultancy",
"fragment": "fragment Key on Consultancy {\n __typename\n upc\n}"
}
],
"query": "query Requires__employees__4($representations: [_Any!]!){\n _entities(representations: $representations){\n ... on Consultancy {\n __typename\n isLeadAvailable\n }\n }\n}"
}
}
]
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
{
"data": {
"products": [
{
"__typename": "Consultancy",
"lead": {
"__typename": "Employee",
"id": 1,
"derivedMood": "HAPPY"
},
"isLeadAvailable": false
},
{
"__typename": "Cosmo"
},
{
"__typename": "SDK"
}
]
},
"extensions": {
"queryPlan": {
"version": "1",
"kind": "Sequence",
"children": [
{
"kind": "Single",
"fetch": {
"kind": "Single",
"subgraphName": "employees",
"subgraphId": "0",
"fetchId": 0,
"query": "query Requires__employees__0__query {\n products {\n __typename\n ... on Consultancy {\n lead {\n __typename\n id\n }\n __typename\n upc\n }\n }\n}"
}
},
{
"kind": "Parallel",
"children": [
{
"kind": "Single",
"fetch": {
"kind": "BatchEntity",
"path": "[email protected]",
"subgraphName": "mood",
"subgraphId": "6",
"fetchId": 1,
"dependsOnFetchIds": [
0
],
"representations": [
{
"kind": "@key",
"typeName": "Employee",
"fragment": "fragment Key on Employee {\n __typename\n id\n}"
}
],
"query": "query Requires__mood__1__query_products_Frag0Consultancy_lead($representations: [_Any!]!){\n _entities(representations: $representations){\n ... on Employee {\n __typename\n currentMood\n }\n }\n}"
}
},
{
"kind": "Single",
"fetch": {
"kind": "BatchEntity",
"path": "[email protected]",
"subgraphName": "availability",
"subgraphId": "5",
"fetchId": 2,
"dependsOnFetchIds": [
0
],
"representations": [
{
"kind": "@key",
"typeName": "Employee",
"fragment": "fragment Key on Employee {\n __typename\n id\n}"
}
],
"query": "query Requires__availability__2__query_products_Frag0Consultancy_lead($representations: [_Any!]!){\n _entities(representations: $representations){\n ... on Employee {\n __typename\n isAvailable\n }\n }\n}"
}
}
]
},
{
"kind": "Parallel",
"children": [
{
"kind": "Single",
"fetch": {
"kind": "BatchEntity",
"path": "[email protected]",
"subgraphName": "employees",
"subgraphId": "0",
"fetchId": 3,
"dependsOnFetchIds": [
0,
1
],
"representations": [
{
"kind": "@requires",
"typeName": "Employee",
"fieldName": "derivedMood",
"fragment": "fragment Requires_for_derivedMood on Employee {\n currentMood\n}"
},
{
"kind": "@key",
"typeName": "Employee",
"fragment": "fragment Key on Employee {\n __typename\n id\n}"
}
],
"query": "query Requires__employees__3__query_products_Frag0Consultancy_lead($representations: [_Any!]!){\n _entities(representations: $representations){\n ... on Employee {\n __typename\n derivedMood\n }\n }\n}"
}
},
{
"kind": "Single",
"fetch": {
"kind": "BatchEntity",
"path": "products",
"subgraphName": "employees",
"subgraphId": "0",
"fetchId": 4,
"dependsOnFetchIds": [
0,
2
],
"representations": [
{
"kind": "@requires",
"typeName": "Consultancy",
"fieldName": "isLeadAvailable",
"fragment": "fragment Requires_for_isLeadAvailable on Consultancy {\n lead {\n isAvailable\n }\n}"
},
{
"kind": "@key",
"typeName": "Consultancy",
"fragment": "fragment Key on Consultancy {\n __typename\n upc\n}"
}
],
"query": "query Requires__employees__4__query_products($representations: [_Any!]!){\n _entities(representations: $representations){\n ... on Consultancy {\n __typename\n isLeadAvailable\n }\n }\n}"
}
}
]
}
]
}
}
}
2 changes: 2 additions & 0 deletions router/core/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,5 +277,7 @@ func (b *ExecutorConfigurationBuilder) buildPlannerConfiguration(ctx context.Con
DatasourceVisitor: debug.DatasourceVisitor,
}
planConfig.MinifySubgraphOperations = routerEngineCfg.Execution.MinifySubgraphOperations

planConfig.EnableOperationNamePropagation = routerEngineCfg.Execution.EnableOperationNameToSubgraphPropagation
return planConfig, nil
}
2 changes: 1 addition & 1 deletion router/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,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.127
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.128
// 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 @@ -268,8 +268,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-20241108124845-44485579ffa5 h1:rc+IQxG3rrAXEjBywirkzhKkyCKvXLGQXABVD8GiUtU=
github.com/wundergraph/astjson v0.0.0-20241108124845-44485579ffa5/go.mod h1:eOTL6acwctsN4F3b7YE+eE2t8zcJ/doLm9sZzsxxxrE=
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.127 h1:LSSGHxnLXCmOyS9GLgEbxt5g2mFukywii3v/SFSUxfs=
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.127/go.mod h1:s4r/lhVEU5s0c6tCgpR0hK6FHEmX0cbrKcMU1pMc/ZI=
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.128 h1:0qFNHSFjXLBOEeeaIY8Pa5usEW//yTQY3ahIQnPouG8=
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.128/go.mod h1:s4r/lhVEU5s0c6tCgpR0hK6FHEmX0cbrKcMU1pMc/ZI=
github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.46.1 h1:aFJWCqJMNjENlcleuuOkGAPH82y0yULBScfXcIEdS24=
Expand Down
Loading
Loading