-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add query planner configuration option
generate_query_fragments
(#460)
Ref: apollographql/federation#2958 Adopting this in router should take into consideration that both `reuse_query_fragments` and `generate_query_fragments` should not both be set to true. Since `reuse_` currently defaults to true, it should be disabled when `generate_` is enabled. --------- Co-authored-by: apollo-bot2 <apollo-bot2@users.noreply.github.com>
- Loading branch information
1 parent
e222c0a
commit 640dc3a
Showing
7 changed files
with
251 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
.../snapshots/router_bridge__planner__tests__generate_query_fragments_defaults_to_false.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--- | ||
source: router-bridge/src/planner.rs | ||
assertion_line: 1003 | ||
expression: "serde_json::to_string_pretty(&payload.data).unwrap()" | ||
--- | ||
{ | ||
"queryPlan": { | ||
"kind": "QueryPlan", | ||
"node": { | ||
"kind": "Fetch", | ||
"serviceName": "Subgraph1", | ||
"variableUsages": [], | ||
"operation": "{t{__typename ...on A{x y t{__typename ...on A{x y}...on B{z}}}}}", | ||
"operationKind": "query" | ||
} | ||
}, | ||
"formattedQueryPlan": "QueryPlan {\n Fetch(service: \"Subgraph1\") {\n {\n t {\n __typename\n ... on A {\n x\n y\n t {\n __typename\n ... on A {\n x\n y\n }\n ... on B {\n z\n }\n }\n }\n }\n }\n },\n}" | ||
} |
18 changes: 18 additions & 0 deletions
18
...src/snapshots/router_bridge__planner__tests__generate_query_fragments_explicit_false.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--- | ||
source: router-bridge/src/planner.rs | ||
assertion_line: 1028 | ||
expression: "serde_json::to_string_pretty(&payload.data).unwrap()" | ||
--- | ||
{ | ||
"queryPlan": { | ||
"kind": "QueryPlan", | ||
"node": { | ||
"kind": "Fetch", | ||
"serviceName": "Subgraph1", | ||
"variableUsages": [], | ||
"operation": "{t{__typename ...on A{x y t{__typename ...on A{x y}...on B{z}}}}}", | ||
"operationKind": "query" | ||
} | ||
}, | ||
"formattedQueryPlan": "QueryPlan {\n Fetch(service: \"Subgraph1\") {\n {\n t {\n __typename\n ... on A {\n x\n y\n t {\n __typename\n ... on A {\n x\n y\n }\n ... on B {\n z\n }\n }\n }\n }\n }\n },\n}" | ||
} |
18 changes: 18 additions & 0 deletions
18
...er-bridge/src/snapshots/router_bridge__planner__tests__generate_query_fragments_true.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--- | ||
source: router-bridge/src/planner.rs | ||
assertion_line: 1054 | ||
expression: "serde_json::to_string_pretty(&payload.data).unwrap()" | ||
--- | ||
{ | ||
"queryPlan": { | ||
"kind": "QueryPlan", | ||
"node": { | ||
"kind": "Fetch", | ||
"serviceName": "Subgraph1", | ||
"variableUsages": [], | ||
"operation": "{t{__typename ..._generated_onA3_0}}fragment _generated_onA2_0 on A{x y}fragment _generated_onA3_0 on A{x y t{__typename ..._generated_onA2_0 ...on B{z}}}", | ||
"operationKind": "query" | ||
} | ||
}, | ||
"formattedQueryPlan": "QueryPlan {\n Fetch(service: \"Subgraph1\") {\n {\n t {\n __typename\n ..._generated_onA3_0\n }\n }\n \n fragment _generated_onA2_0 on A {\n x\n y\n }\n \n fragment _generated_onA3_0 on A {\n x\n y\n t {\n __typename\n ..._generated_onA2_0\n ... on B {\n z\n }\n }\n }\n },\n}" | ||
} |
17 changes: 17 additions & 0 deletions
17
federation-2/router-bridge/src/testdata/query_generate_query_fragments.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
query { | ||
t { | ||
... on A { | ||
x | ||
y | ||
t { | ||
... on A { | ||
x | ||
y | ||
} | ||
... on B { | ||
z | ||
} | ||
} | ||
} | ||
} | ||
} |
94 changes: 94 additions & 0 deletions
94
federation-2/router-bridge/src/testdata/schema_generate_query_fragments.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
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__directive( | ||
graphs: [join__Graph!] | ||
name: String! | ||
args: join__DirectiveArguments | ||
) repeatable on SCHEMA | OBJECT | INTERFACE | FIELD_DEFINITION | ||
|
||
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 | ||
|
||
type A @join__type(graph: SUBGRAPH1) { | ||
x: Int | ||
y: Int | ||
t: T | ||
} | ||
|
||
type B @join__type(graph: SUBGRAPH1) { | ||
z: Int | ||
} | ||
|
||
scalar join__DirectiveArguments | ||
|
||
scalar join__FieldSet | ||
|
||
enum join__Graph { | ||
SUBGRAPH1 @join__graph(name: "Subgraph1", url: "") | ||
} | ||
|
||
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) { | ||
t: T | ||
t2: T | ||
} | ||
|
||
union T | ||
@join__type(graph: SUBGRAPH1) | ||
@join__unionMember(graph: SUBGRAPH1, member: "A") | ||
@join__unionMember(graph: SUBGRAPH1, member: "B") = | ||
A | ||
| B |