Skip to content

Commit

Permalink
feat(router): allow operation name propagation (#1394)
Browse files Browse the repository at this point in the history
  • Loading branch information
Noroth authored Nov 25, 2024
1 parent b26f676 commit 7aa6a20
Show file tree
Hide file tree
Showing 13 changed files with 339 additions and 8 deletions.
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.EnableSubgraphFetchOperationName = true
},
}, 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.EnableSubgraphFetchOperationName
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
1 change: 1 addition & 0 deletions router/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ type EngineExecutionConfiguration struct {
EnableValidationCache bool `envDefault:"true" env:"ENGINE_ENABLE_VALIDATION_CACHE" yaml:"enable_validation_cache"`
ValidationCacheSize int64 `envDefault:"10240" env:"ENGINE_VALIDATION_CACHE_SIZE" yaml:"validation_cache_size,omitempty"`
ResolverMaxRecyclableParserSize int `envDefault:"32768" env:"ENGINE_RESOLVER_MAX_RECYCLABLE_PARSER_SIZE" yaml:"resolver_max_recyclable_parser_size,omitempty"`
EnableSubgraphFetchOperationName bool `envDefault:"true" env:"ENGINE_ENABLE_SUBGRAPH_FETCH_OPERATION_NAME" yaml:"enable_subgraph_fetch_operation_name"`
}

type SecurityConfiguration struct {
Expand Down
5 changes: 5 additions & 0 deletions router/pkg/config/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2027,6 +2027,11 @@
"type": "integer",
"default": 10240,
"description": "The size of the validation cache."
},
"enable_subgraph_fetch_operation_name": {
"type": "boolean",
"default": true,
"description": "Enable appending the operation name to subgraph fetches. This will ensure that the operation name will be included the the corresponding subgraph requests in the following format: $operationName__$subgraphName__$sequenceID."
}
}
},
Expand Down
Loading

0 comments on commit 7aa6a20

Please sign in to comment.