From 7290a1a79576dad08b89dfc54aea1e79e7ef4c19 Mon Sep 17 00:00:00 2001 From: Geoffroy Couprie Date: Wed, 2 Oct 2024 16:00:35 +0200 Subject: [PATCH 01/11] integration test for progressive override --- .../enterprise/progressive-override/README.md | 3 + .../progressive-override/configuration.yaml | 15 +++ .../enterprise/progressive-override/plan.json | 114 ++++++++++++++++++ .../progressive-override/supergraph.graphql | 98 +++++++++++++++ 4 files changed, 230 insertions(+) create mode 100644 apollo-router/tests/samples/enterprise/progressive-override/README.md create mode 100644 apollo-router/tests/samples/enterprise/progressive-override/configuration.yaml create mode 100644 apollo-router/tests/samples/enterprise/progressive-override/plan.json create mode 100644 apollo-router/tests/samples/enterprise/progressive-override/supergraph.graphql diff --git a/apollo-router/tests/samples/enterprise/progressive-override/README.md b/apollo-router/tests/samples/enterprise/progressive-override/README.md new file mode 100644 index 0000000000..3802c3942d --- /dev/null +++ b/apollo-router/tests/samples/enterprise/progressive-override/README.md @@ -0,0 +1,3 @@ +# Progressive override + +This tests subgraph field migration: https://www.apollographql.com/docs/federation/entities/migrate-fields/ \ No newline at end of file diff --git a/apollo-router/tests/samples/enterprise/progressive-override/configuration.yaml b/apollo-router/tests/samples/enterprise/progressive-override/configuration.yaml new file mode 100644 index 0000000000..bf0e81d461 --- /dev/null +++ b/apollo-router/tests/samples/enterprise/progressive-override/configuration.yaml @@ -0,0 +1,15 @@ +override_subgraph_url: + products: http://localhost:4005 +include_subgraph_errors: + all: true + +telemetry: + exporters: + logging: + stdout: + format: text + +experimental_query_planner_mode: legacy + +plugins: + experimental.expose_query_plan: true \ No newline at end of file diff --git a/apollo-router/tests/samples/enterprise/progressive-override/plan.json b/apollo-router/tests/samples/enterprise/progressive-override/plan.json new file mode 100644 index 0000000000..e980df067a --- /dev/null +++ b/apollo-router/tests/samples/enterprise/progressive-override/plan.json @@ -0,0 +1,114 @@ +{ + "enterprise": true, + "actions": [ + { + "type": "Start", + "schema_path": "./supergraph.graphql", + "configuration_path": "./configuration.yaml", + "subgraphs": { + "Subgraph1": { + "requests": [ + { + "request": { + "body": { + "query": "query progressive1__Subgraph1__0{percent100{__typename id}}", + "operationName": "progressive1__Subgraph1__0" + } + }, + "response": { + "body": { + "data": { + "percent100": { + "__typename": "T", + "id": "1" + } + } + } + } + } + ] + }, + "Subgraph2": { + "requests": [ + { + "request": { + "body": { + "query": "query progressive1__Subgraph2__1($representations:[_Any!]!){_entities(representations:$representations){...on T{foo}}}", + "operationName": "progressive1__Subgraph2__1", + "variables": { + "representations": [ + { + "__typename": "T", + "id": "1" + } + ] + } + } + }, + "response": { + "body": { + "data": { + "_entities": [ + { + "foo": 1 + } + ] + } + } + } + }, + { + "request": { + "body": { + "query": "query progressive2__Subgraph2__0{percent0{foo}}", + "operationName": "progressive2__Subgraph2__0" + } + }, + "response": { + "body": { + "data": { + "percent0": { + "foo": 2 + } + } + } + } + } + ] + } + } + }, + { + "type": "Request", + "request": { + "query": "query progressive1 { percent100 { foo } }" + }, + "headers": { + "apollo-expose-query-plan": "false" + }, + "expected_response": { + "data": { + "percent100": { + "foo": 1 + } + } + } + }, + { + "type": "Request", + "request": { + "query": "query progressive2 { percent0 { foo } }" + }, + "expected_response": { + "data": { + "percent0": { + "foo": 2 + } + } + } + }, + { + "type": "Stop" + } + ] +} \ No newline at end of file diff --git a/apollo-router/tests/samples/enterprise/progressive-override/supergraph.graphql b/apollo-router/tests/samples/enterprise/progressive-override/supergraph.graphql new file mode 100644 index 0000000000..e5ffb347c0 --- /dev/null +++ b/apollo-router/tests/samples/enterprise/progressive-override/supergraph.graphql @@ -0,0 +1,98 @@ +schema + @link(url: "https://specs.apollo.dev/link/v1.0") + @link(url: "https://specs.apollo.dev/join/v0.4", for: EXECUTION) { + query: Query +} + +directive @join__enumValue(graph: join__Graph!) repeatable on ENUM_VALUE + +directive @join__field( + graph: join__Graph + requires: join__FieldSet + provides: join__FieldSet + type: String + external: Boolean + override: String + usedOverridden: Boolean + overrideLabel: String +) repeatable on FIELD_DEFINITION | INPUT_FIELD_DEFINITION + +directive @join__graph(name: String!, url: String!) on ENUM_VALUE + +directive @join__implements( + graph: join__Graph! + interface: String! +) repeatable on OBJECT | INTERFACE + +directive @join__type( + graph: join__Graph! + key: join__FieldSet + extension: Boolean! = false + resolvable: Boolean! = true + isInterfaceObject: Boolean! = false +) repeatable on OBJECT | INTERFACE | UNION | ENUM | INPUT_OBJECT | SCALAR + +directive @join__unionMember( + graph: join__Graph! + member: String! +) repeatable on UNION + +directive @link( + url: String + as: String + for: link__Purpose + import: [link__Import] +) repeatable on SCHEMA + +scalar join__FieldSet + +enum join__Graph { + SUBGRAPH1 @join__graph(name: "Subgraph1", url: "https://Subgraph1") + SUBGRAPH2 @join__graph(name: "Subgraph2", url: "https://Subgraph2") +} + +scalar link__Import + +enum link__Purpose { + """ + \`SECURITY\` features provide metadata necessary to securely resolve fields. + """ + SECURITY + + """ + \`EXECUTION\` features provide metadata necessary for operation execution. + """ + EXECUTION +} + +type Query @join__type(graph: SUBGRAPH1) @join__type(graph: SUBGRAPH2) { + percent100: T + @join__field( + graph: SUBGRAPH1 + override: "Subgraph2" + overrideLabel: "percent(100)" + ) + @join__field(graph: SUBGRAPH2, overrideLabel: "percent(100)") + percent0: T + @join__field( + graph: SUBGRAPH1 + override: "Subgraph2" + overrideLabel: "percent(0)" + ) + @join__field(graph: SUBGRAPH2, overrideLabel: "percent(0)") +} + +type T + @join__type(graph: SUBGRAPH1, key: "id") + @join__type(graph: SUBGRAPH2, key: "id") { + id: ID + foo: Int + @join__field(graph: SUBGRAPH1, override: "Subgraph2", overrideLabel: "foo") + @join__field(graph: SUBGRAPH2, overrideLabel: "foo") + bar: Int + @join__field(graph: SUBGRAPH1, override: "Subgraph2", overrideLabel: "bar") + @join__field(graph: SUBGRAPH2, overrideLabel: "bar") + baz: Int + @join__field(graph: SUBGRAPH1, override: "Subgraph2", overrideLabel: "baz") + @join__field(graph: SUBGRAPH2, overrideLabel: "baz") +} From 0016e2a45e9d829aa3098b8c5850a7c08556065a Mon Sep 17 00:00:00 2001 From: Geoffroy Couprie Date: Thu, 3 Oct 2024 11:55:14 +0200 Subject: [PATCH 02/11] integrate rhai --- .../progressive-override/configuration.yaml | 2 -- .../progressive-override/configuration2.yaml | 17 ++++++++++++++++ .../enterprise/progressive-override/plan.json | 20 +++++++++++++++++++ .../progressive-override/rhai/main.rhai | 15 ++++++++++++++ 4 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 apollo-router/tests/samples/enterprise/progressive-override/configuration2.yaml create mode 100644 apollo-router/tests/samples/enterprise/progressive-override/rhai/main.rhai diff --git a/apollo-router/tests/samples/enterprise/progressive-override/configuration.yaml b/apollo-router/tests/samples/enterprise/progressive-override/configuration.yaml index bf0e81d461..321fd80abd 100644 --- a/apollo-router/tests/samples/enterprise/progressive-override/configuration.yaml +++ b/apollo-router/tests/samples/enterprise/progressive-override/configuration.yaml @@ -1,5 +1,3 @@ -override_subgraph_url: - products: http://localhost:4005 include_subgraph_errors: all: true diff --git a/apollo-router/tests/samples/enterprise/progressive-override/configuration2.yaml b/apollo-router/tests/samples/enterprise/progressive-override/configuration2.yaml new file mode 100644 index 0000000000..70ecd2ba7e --- /dev/null +++ b/apollo-router/tests/samples/enterprise/progressive-override/configuration2.yaml @@ -0,0 +1,17 @@ +include_subgraph_errors: + all: true + +telemetry: + exporters: + logging: + stdout: + format: text + +experimental_query_planner_mode: legacy + +rhai: + scripts: "tests/samples/enterprise/progressive-override/rhai" + main: "main.rhai" + +plugins: + experimental.expose_query_plan: true \ No newline at end of file diff --git a/apollo-router/tests/samples/enterprise/progressive-override/plan.json b/apollo-router/tests/samples/enterprise/progressive-override/plan.json index e980df067a..ba4ee70ced 100644 --- a/apollo-router/tests/samples/enterprise/progressive-override/plan.json +++ b/apollo-router/tests/samples/enterprise/progressive-override/plan.json @@ -107,6 +107,26 @@ } } }, + { + "type": "ReloadConfiguration", + "configuration_path": "./configuration2.yaml" + }, + { + "type": "Request", + "request": { + "query": "query progressive3 { percent100 { foo } }" + }, + "headers": { + "apollo-expose-query-plan": "false" + }, + "expected_response": { + "data": { + "percent100": { + "foo": 1 + } + } + } + }, { "type": "Stop" } diff --git a/apollo-router/tests/samples/enterprise/progressive-override/rhai/main.rhai b/apollo-router/tests/samples/enterprise/progressive-override/rhai/main.rhai new file mode 100644 index 0000000000..b053857d51 --- /dev/null +++ b/apollo-router/tests/samples/enterprise/progressive-override/rhai/main.rhai @@ -0,0 +1,15 @@ +fn supergraph_service(service) { + const request_callback = Fn("process_request"); + service.map_request(request_callback); +} + +// Add a timestamp to context which we'll use in the response. +fn process_request(request) { + request.context["request_start"] = Router.APOLLO_START.elapsed; + let labels = request.context["apollo_override::unresolved_labels"]; + print(`unresolved: ${labels}`); + + let override = request.context["apollo_override::labels_to_override"]; + print(`override: ${override}`); +} + From 82d68b8351d34fa51ce0b526615345dc77553f7a Mon Sep 17 00:00:00 2001 From: Geoffroy Couprie Date: Thu, 3 Oct 2024 13:18:32 +0200 Subject: [PATCH 03/11] test label override --- .../enterprise/progressive-override/plan.json | 96 ++++++++++++++++++- .../progressive-override/rhai/main.rhai | 7 ++ 2 files changed, 101 insertions(+), 2 deletions(-) diff --git a/apollo-router/tests/samples/enterprise/progressive-override/plan.json b/apollo-router/tests/samples/enterprise/progressive-override/plan.json index ba4ee70ced..6cdf9d7b60 100644 --- a/apollo-router/tests/samples/enterprise/progressive-override/plan.json +++ b/apollo-router/tests/samples/enterprise/progressive-override/plan.json @@ -111,10 +111,85 @@ "type": "ReloadConfiguration", "configuration_path": "./configuration2.yaml" }, + { + "type": "ReloadSubgraphs", + "subgraphs": { + "Subgraph1": { + "requests": [ + { + "request": { + "body": { + "query": "query progressive3__Subgraph1__0{percent100{__typename id}}", + "operationName": "progressive3__Subgraph1__0" + } + }, + "response": { + "body": { + "data": { + "percent100": { + "__typename": "T", + "id": "1" + } + } + } + } + }, + { + "request": { + "body": { + "query": "query progressive4__Subgraph1__0{percent100{bar}}", + "operationName": "progressive4__Subgraph1__0" + } + }, + "response": { + "body": { + "data": { + "percent100": { + "bar": 2 + } + } + } + } + } + ] + }, + "Subgraph2": { + "requests": [ + { + "request": { + "body": { + "query": "query progressive3__Subgraph2__1($representations:[_Any!]!){_entities(representations:$representations){...on T{bar}}}", + "operationName": "progressive3__Subgraph2__1", + "variables": { + "representations": [ + { + "__typename": "T", + "id": "1" + } + ] + } + } + }, + "response": { + "body": { + "data": { + "_entities": [ + { + "bar": 1 + } + ] + } + } + } + } + ] + } + } + }, { "type": "Request", "request": { - "query": "query progressive3 { percent100 { foo } }" + "query": "query progressive3 { percent100 { bar } }" }, "headers": { "apollo-expose-query-plan": "false" @@ -122,7 +197,24 @@ "expected_response": { "data": { "percent100": { - "foo": 1 + "bar": 1 + } + } + } + }, + { + "type": "Request", + "request": { + "query": "query progressive4 { percent100 { bar } }" + }, + "headers": { + "apollo-expose-query-plan": "false", + "x-override": "true" + }, + "expected_response": { + "data": { + "percent100": { + "bar": 2 } } } diff --git a/apollo-router/tests/samples/enterprise/progressive-override/rhai/main.rhai b/apollo-router/tests/samples/enterprise/progressive-override/rhai/main.rhai index b053857d51..3ecb55cca9 100644 --- a/apollo-router/tests/samples/enterprise/progressive-override/rhai/main.rhai +++ b/apollo-router/tests/samples/enterprise/progressive-override/rhai/main.rhai @@ -11,5 +11,12 @@ fn process_request(request) { let override = request.context["apollo_override::labels_to_override"]; print(`override: ${override}`); + + + if "x-override" in request.headers { + if request.headers["x-override"] == "true" { + request.context["apollo_override::labels_to_override"] += "bar"; + } + } } From eac41f91bec7b832df0b6182c604188ee8061003 Mon Sep 17 00:00:00 2001 From: Geoffroy Couprie Date: Wed, 23 Oct 2024 11:17:24 +0200 Subject: [PATCH 04/11] move test --- .../samples/enterprise/progressive-override/{ => basic}/README.md | 0 .../progressive-override/{ => basic}/configuration.yaml | 0 .../progressive-override/{ => basic}/configuration2.yaml | 0 .../samples/enterprise/progressive-override/{ => basic}/plan.json | 0 .../enterprise/progressive-override/{ => basic}/rhai/main.rhai | 0 .../progressive-override/{ => basic}/supergraph.graphql | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename apollo-router/tests/samples/enterprise/progressive-override/{ => basic}/README.md (100%) rename apollo-router/tests/samples/enterprise/progressive-override/{ => basic}/configuration.yaml (100%) rename apollo-router/tests/samples/enterprise/progressive-override/{ => basic}/configuration2.yaml (100%) rename apollo-router/tests/samples/enterprise/progressive-override/{ => basic}/plan.json (100%) rename apollo-router/tests/samples/enterprise/progressive-override/{ => basic}/rhai/main.rhai (100%) rename apollo-router/tests/samples/enterprise/progressive-override/{ => basic}/supergraph.graphql (100%) diff --git a/apollo-router/tests/samples/enterprise/progressive-override/README.md b/apollo-router/tests/samples/enterprise/progressive-override/basic/README.md similarity index 100% rename from apollo-router/tests/samples/enterprise/progressive-override/README.md rename to apollo-router/tests/samples/enterprise/progressive-override/basic/README.md diff --git a/apollo-router/tests/samples/enterprise/progressive-override/configuration.yaml b/apollo-router/tests/samples/enterprise/progressive-override/basic/configuration.yaml similarity index 100% rename from apollo-router/tests/samples/enterprise/progressive-override/configuration.yaml rename to apollo-router/tests/samples/enterprise/progressive-override/basic/configuration.yaml diff --git a/apollo-router/tests/samples/enterprise/progressive-override/configuration2.yaml b/apollo-router/tests/samples/enterprise/progressive-override/basic/configuration2.yaml similarity index 100% rename from apollo-router/tests/samples/enterprise/progressive-override/configuration2.yaml rename to apollo-router/tests/samples/enterprise/progressive-override/basic/configuration2.yaml diff --git a/apollo-router/tests/samples/enterprise/progressive-override/plan.json b/apollo-router/tests/samples/enterprise/progressive-override/basic/plan.json similarity index 100% rename from apollo-router/tests/samples/enterprise/progressive-override/plan.json rename to apollo-router/tests/samples/enterprise/progressive-override/basic/plan.json diff --git a/apollo-router/tests/samples/enterprise/progressive-override/rhai/main.rhai b/apollo-router/tests/samples/enterprise/progressive-override/basic/rhai/main.rhai similarity index 100% rename from apollo-router/tests/samples/enterprise/progressive-override/rhai/main.rhai rename to apollo-router/tests/samples/enterprise/progressive-override/basic/rhai/main.rhai diff --git a/apollo-router/tests/samples/enterprise/progressive-override/supergraph.graphql b/apollo-router/tests/samples/enterprise/progressive-override/basic/supergraph.graphql similarity index 100% rename from apollo-router/tests/samples/enterprise/progressive-override/supergraph.graphql rename to apollo-router/tests/samples/enterprise/progressive-override/basic/supergraph.graphql From 7a75530cd2701c134e450c75a999b36772f1167a Mon Sep 17 00:00:00 2001 From: Geoffroy Couprie Date: Wed, 23 Oct 2024 11:18:43 +0200 Subject: [PATCH 05/11] progressive override warmup test --- .../progressive-override/warmup/README.md | 3 + .../warmup/configuration.yaml | 17 ++ .../warmup/configuration2.yaml | 21 ++ .../progressive-override/warmup/plan.json | 212 ++++++++++++++++++ .../warmup/rhai/main.rhai | 22 ++ .../warmup/supergraph.graphql | 98 ++++++++ 6 files changed, 373 insertions(+) create mode 100644 apollo-router/tests/samples/enterprise/progressive-override/warmup/README.md create mode 100644 apollo-router/tests/samples/enterprise/progressive-override/warmup/configuration.yaml create mode 100644 apollo-router/tests/samples/enterprise/progressive-override/warmup/configuration2.yaml create mode 100644 apollo-router/tests/samples/enterprise/progressive-override/warmup/plan.json create mode 100644 apollo-router/tests/samples/enterprise/progressive-override/warmup/rhai/main.rhai create mode 100644 apollo-router/tests/samples/enterprise/progressive-override/warmup/supergraph.graphql diff --git a/apollo-router/tests/samples/enterprise/progressive-override/warmup/README.md b/apollo-router/tests/samples/enterprise/progressive-override/warmup/README.md new file mode 100644 index 0000000000..dfc4a1834c --- /dev/null +++ b/apollo-router/tests/samples/enterprise/progressive-override/warmup/README.md @@ -0,0 +1,3 @@ +# Progressive override warmup + +This checks progrssive override behaviour across router reloads \ No newline at end of file diff --git a/apollo-router/tests/samples/enterprise/progressive-override/warmup/configuration.yaml b/apollo-router/tests/samples/enterprise/progressive-override/warmup/configuration.yaml new file mode 100644 index 0000000000..b069d5af18 --- /dev/null +++ b/apollo-router/tests/samples/enterprise/progressive-override/warmup/configuration.yaml @@ -0,0 +1,17 @@ +include_subgraph_errors: + all: true + +supergraph: + query_planning: + warmed_up_queries: 5 + +telemetry: + exporters: + logging: + stdout: + format: text + +experimental_query_planner_mode: legacy + +plugins: + experimental.expose_query_plan: true \ No newline at end of file diff --git a/apollo-router/tests/samples/enterprise/progressive-override/warmup/configuration2.yaml b/apollo-router/tests/samples/enterprise/progressive-override/warmup/configuration2.yaml new file mode 100644 index 0000000000..413d26aba3 --- /dev/null +++ b/apollo-router/tests/samples/enterprise/progressive-override/warmup/configuration2.yaml @@ -0,0 +1,21 @@ +include_subgraph_errors: + all: true + +supergraph: + query_planning: + warmed_up_queries: 6 + +telemetry: + exporters: + logging: + stdout: + format: text + +experimental_query_planner_mode: legacy + +# rhai: +# scripts: "tests/samples/enterprise/progressive-override/rhai" +# main: "main.rhai" + +plugins: + experimental.expose_query_plan: true \ No newline at end of file diff --git a/apollo-router/tests/samples/enterprise/progressive-override/warmup/plan.json b/apollo-router/tests/samples/enterprise/progressive-override/warmup/plan.json new file mode 100644 index 0000000000..3b86b028ea --- /dev/null +++ b/apollo-router/tests/samples/enterprise/progressive-override/warmup/plan.json @@ -0,0 +1,212 @@ +{ + "enterprise": true, + "actions": [ + { + "type": "Start", + "schema_path": "./supergraph.graphql", + "configuration_path": "./configuration.yaml", + "subgraphs": { + "Subgraph1": { + "requests": [ + { + "request": { + "body": { + "query": "query progressive1__Subgraph1__0{percent100{__typename id}}", + "operationName": "progressive1__Subgraph1__0" + } + }, + "response": { + "body": { + "data": { + "percent100": { + "__typename": "T", + "id": "1" + } + } + } + } + } + ] + }, + "Subgraph2": { + "requests": [ + { + "request": { + "body": { + "query": "query progressive1__Subgraph2__1($representations:[_Any!]!){_entities(representations:$representations){...on T{foo}}}", + "operationName": "progressive1__Subgraph2__1", + "variables": { + "representations": [ + { + "__typename": "T", + "id": "1" + } + ] + } + } + }, + "response": { + "body": { + "data": { + "_entities": [ + { + "foo": 1 + } + ] + } + } + } + }, + { + "request": { + "body": { + "query": "query progressive2__Subgraph2__0{percent0{foo}}", + "operationName": "progressive2__Subgraph2__0" + } + }, + "response": { + "body": { + "data": { + "percent0": { + "foo": 2 + } + } + } + } + } + ] + } + } + }, + { + "type": "Request", + "request": { + "query": "query progressive1 { percent100 { foo } }" + }, + "headers": { + "apollo-expose-query-plan": "false" + }, + "expected_response": { + "data": { + "percent100": { + "foo": 1 + } + } + } + }, + { + "type": "ReloadConfiguration", + "configuration_path": "./configuration2.yaml" + }, + { + "type": "ReloadSubgraphs", + "subgraphs": { + "Subgraph1": { + "requests": [ + { + "request": { + "body": { + "query": "query progressive1__Subgraph1__0{percent100{__typename id}}", + "operationName": "progressive1__Subgraph1__0" + } + }, + "response": { + "body": { + "data": { + "percent100": { + "__typename": "T", + "id": "1" + } + } + } + } + } + ] + }, + "Subgraph2": { + "requests": [ + { + "request": { + "body": { + "query": "query progressive1__Subgraph2__1($representations:[_Any!]!){_entities(representations:$representations){...on T{foo}}}", + "operationName": "progressive1__Subgraph2__1", + "variables": { + "representations": [ + { + "__typename": "T", + "id": "1" + } + ] + } + } + }, + "response": { + "body": { + "data": { + "_entities": [ + { + "foo": 1 + } + ] + } + } + } + }, + { + "request": { + "body": { + "query": "query progressive2__Subgraph2__0{percent0{foo}}", + "operationName": "progressive2__Subgraph2__0" + } + }, + "response": { + "body": { + "data": { + "percent0": { + "foo": 2 + } + } + } + } + } + ] + } + } + }, + { + "type": "Request", + "request": { + "query": "query progressive1 { percent100 { foo } }" + }, + "headers": { + "apollo-expose-query-plan": "false" + }, + "expected_response": { + "data": { + "percent100": { + "foo": 1 + } + } + } + }, + { + "type": "Request", + "request": { + "query": "query progressive3 { percent100 { bar } }" + }, + "headers": { + "apollo-expose-query-plan": "false" + }, + "expected_response": { + "data": { + "percent100": { + "bar": 1 + } + } + } + }, + { + "type": "Stop" + } + ] +} \ No newline at end of file diff --git a/apollo-router/tests/samples/enterprise/progressive-override/warmup/rhai/main.rhai b/apollo-router/tests/samples/enterprise/progressive-override/warmup/rhai/main.rhai new file mode 100644 index 0000000000..3ecb55cca9 --- /dev/null +++ b/apollo-router/tests/samples/enterprise/progressive-override/warmup/rhai/main.rhai @@ -0,0 +1,22 @@ +fn supergraph_service(service) { + const request_callback = Fn("process_request"); + service.map_request(request_callback); +} + +// Add a timestamp to context which we'll use in the response. +fn process_request(request) { + request.context["request_start"] = Router.APOLLO_START.elapsed; + let labels = request.context["apollo_override::unresolved_labels"]; + print(`unresolved: ${labels}`); + + let override = request.context["apollo_override::labels_to_override"]; + print(`override: ${override}`); + + + if "x-override" in request.headers { + if request.headers["x-override"] == "true" { + request.context["apollo_override::labels_to_override"] += "bar"; + } + } +} + diff --git a/apollo-router/tests/samples/enterprise/progressive-override/warmup/supergraph.graphql b/apollo-router/tests/samples/enterprise/progressive-override/warmup/supergraph.graphql new file mode 100644 index 0000000000..e5ffb347c0 --- /dev/null +++ b/apollo-router/tests/samples/enterprise/progressive-override/warmup/supergraph.graphql @@ -0,0 +1,98 @@ +schema + @link(url: "https://specs.apollo.dev/link/v1.0") + @link(url: "https://specs.apollo.dev/join/v0.4", for: EXECUTION) { + query: Query +} + +directive @join__enumValue(graph: join__Graph!) repeatable on ENUM_VALUE + +directive @join__field( + graph: join__Graph + requires: join__FieldSet + provides: join__FieldSet + type: String + external: Boolean + override: String + usedOverridden: Boolean + overrideLabel: String +) repeatable on FIELD_DEFINITION | INPUT_FIELD_DEFINITION + +directive @join__graph(name: String!, url: String!) on ENUM_VALUE + +directive @join__implements( + graph: join__Graph! + interface: String! +) repeatable on OBJECT | INTERFACE + +directive @join__type( + graph: join__Graph! + key: join__FieldSet + extension: Boolean! = false + resolvable: Boolean! = true + isInterfaceObject: Boolean! = false +) repeatable on OBJECT | INTERFACE | UNION | ENUM | INPUT_OBJECT | SCALAR + +directive @join__unionMember( + graph: join__Graph! + member: String! +) repeatable on UNION + +directive @link( + url: String + as: String + for: link__Purpose + import: [link__Import] +) repeatable on SCHEMA + +scalar join__FieldSet + +enum join__Graph { + SUBGRAPH1 @join__graph(name: "Subgraph1", url: "https://Subgraph1") + SUBGRAPH2 @join__graph(name: "Subgraph2", url: "https://Subgraph2") +} + +scalar link__Import + +enum link__Purpose { + """ + \`SECURITY\` features provide metadata necessary to securely resolve fields. + """ + SECURITY + + """ + \`EXECUTION\` features provide metadata necessary for operation execution. + """ + EXECUTION +} + +type Query @join__type(graph: SUBGRAPH1) @join__type(graph: SUBGRAPH2) { + percent100: T + @join__field( + graph: SUBGRAPH1 + override: "Subgraph2" + overrideLabel: "percent(100)" + ) + @join__field(graph: SUBGRAPH2, overrideLabel: "percent(100)") + percent0: T + @join__field( + graph: SUBGRAPH1 + override: "Subgraph2" + overrideLabel: "percent(0)" + ) + @join__field(graph: SUBGRAPH2, overrideLabel: "percent(0)") +} + +type T + @join__type(graph: SUBGRAPH1, key: "id") + @join__type(graph: SUBGRAPH2, key: "id") { + id: ID + foo: Int + @join__field(graph: SUBGRAPH1, override: "Subgraph2", overrideLabel: "foo") + @join__field(graph: SUBGRAPH2, overrideLabel: "foo") + bar: Int + @join__field(graph: SUBGRAPH1, override: "Subgraph2", overrideLabel: "bar") + @join__field(graph: SUBGRAPH2, overrideLabel: "bar") + baz: Int + @join__field(graph: SUBGRAPH1, override: "Subgraph2", overrideLabel: "baz") + @join__field(graph: SUBGRAPH2, overrideLabel: "baz") +} From d006090ecc11ccff64cd5e7143c04b41066627b3 Mon Sep 17 00:00:00 2001 From: Geoffroy Couprie Date: Wed, 23 Oct 2024 11:26:22 +0200 Subject: [PATCH 06/11] cleanup test --- .../progressive-override/warmup/plan.json | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/apollo-router/tests/samples/enterprise/progressive-override/warmup/plan.json b/apollo-router/tests/samples/enterprise/progressive-override/warmup/plan.json index 3b86b028ea..8f913eb5be 100644 --- a/apollo-router/tests/samples/enterprise/progressive-override/warmup/plan.json +++ b/apollo-router/tests/samples/enterprise/progressive-override/warmup/plan.json @@ -189,22 +189,6 @@ } } }, - { - "type": "Request", - "request": { - "query": "query progressive3 { percent100 { bar } }" - }, - "headers": { - "apollo-expose-query-plan": "false" - }, - "expected_response": { - "data": { - "percent100": { - "bar": 1 - } - } - } - }, { "type": "Stop" } From 5aee2ecc98bfe493c85418b6a243599f4087bd59 Mon Sep 17 00:00:00 2001 From: Geoffroy Couprie Date: Wed, 23 Oct 2024 11:26:32 +0200 Subject: [PATCH 07/11] log previously received requests on reload --- apollo-router/tests/samples_tests.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/apollo-router/tests/samples_tests.rs b/apollo-router/tests/samples_tests.rs index 22e3b31e18..cf2e9b99f7 100644 --- a/apollo-router/tests/samples_tests.rs +++ b/apollo-router/tests/samples_tests.rs @@ -231,6 +231,22 @@ impl TestExecution { path: &Path, out: &mut String, ) -> Result<(), Failed> { + if let Some(requests) = self + .subgraphs_server + .as_ref() + .unwrap() + .received_requests() + .await + { + writeln!(out, "Will reload config, subgraphs received requests:").unwrap(); + for request in requests { + writeln!(out, "\tmethod: {}", request.method).unwrap(); + writeln!(out, "\tpath: {}", request.url).unwrap(); + writeln!(out, "\t{}\n", std::str::from_utf8(&request.body).unwrap()).unwrap(); + } + } else { + writeln!(out, "subgraphs received no requests").unwrap(); + } let mut subgraphs_server = match self.subgraphs_server.take() { Some(subgraphs_server) => subgraphs_server, None => self.start_subgraphs(out).await.0, From 38fd1377cdb37dc8fff95391a24ea901e268b0f2 Mon Sep 17 00:00:00 2001 From: Geoffroy Couprie Date: Wed, 23 Oct 2024 11:27:05 +0200 Subject: [PATCH 08/11] set the labels to override in context when warming up the query planner cache --- apollo-router/src/query_planner/caching_query_planner.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/apollo-router/src/query_planner/caching_query_planner.rs b/apollo-router/src/query_planner/caching_query_planner.rs index 1c4e953c05..6ef9a671e8 100644 --- a/apollo-router/src/query_planner/caching_query_planner.rs +++ b/apollo-router/src/query_planner/caching_query_planner.rs @@ -336,6 +336,11 @@ where lock.insert(caching_key.metadata) }); + let _ = context.insert( + LABELS_TO_OVERRIDE_KEY, + caching_key.plan_options.override_conditions.clone(), + ); + let request = QueryPlannerRequest { query, operation_name, From 8b47285d6cee6e8021fa656ceee02059510b7ef0 Mon Sep 17 00:00:00 2001 From: Geoffroy Couprie Date: Wed, 23 Oct 2024 16:18:54 +0200 Subject: [PATCH 09/11] fix test --- .../enterprise/progressive-override/basic/configuration2.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apollo-router/tests/samples/enterprise/progressive-override/basic/configuration2.yaml b/apollo-router/tests/samples/enterprise/progressive-override/basic/configuration2.yaml index 70ecd2ba7e..7c445ce5b2 100644 --- a/apollo-router/tests/samples/enterprise/progressive-override/basic/configuration2.yaml +++ b/apollo-router/tests/samples/enterprise/progressive-override/basic/configuration2.yaml @@ -10,7 +10,7 @@ telemetry: experimental_query_planner_mode: legacy rhai: - scripts: "tests/samples/enterprise/progressive-override/rhai" + scripts: "tests/samples/enterprise/progressive-override/basic/rhai" main: "main.rhai" plugins: From 487bf792c8a6e50cf82a5a308065488b8efcf3d6 Mon Sep 17 00:00:00 2001 From: Jesse Rosenberger Date: Wed, 23 Oct 2024 20:13:10 +0300 Subject: [PATCH 10/11] Bump CircleCI cache key --- .circleci/config.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index eea532b73b..91bce18b05 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,5 +1,7 @@ version: 2.1 +# Cache key bump: 1 + # These "CircleCI Orbs" are reusable bits of configuration that can be shared # across projects. See https://circleci.com/orbs/ for more information. orbs: From 3208d6ef919a659e19dcfdc15815f8687596e3e7 Mon Sep 17 00:00:00 2001 From: Geoffroy Couprie Date: Wed, 30 Oct 2024 11:31:00 +0100 Subject: [PATCH 11/11] changeset --- .changesets/fix_geal_progressive_override_test.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changesets/fix_geal_progressive_override_test.md diff --git a/.changesets/fix_geal_progressive_override_test.md b/.changesets/fix_geal_progressive_override_test.md new file mode 100644 index 0000000000..eea5a214ab --- /dev/null +++ b/.changesets/fix_geal_progressive_override_test.md @@ -0,0 +1,5 @@ +### Progressive override: fix query planner cache warmup ([PR #6108](https://github.com/apollographql/router/pull/6108)) + +This fixes an issue in progressive override where the override labels would not be transmitted to the query planner during cache warmup, resulting in queries correctly using the overridden fields at first, but after an update, would revert to non overridden fields, and could not recover. + +By [@Geal](https://github.com/Geal) in https://github.com/apollographql/router/pull/6108 \ No newline at end of file