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

WIP: use the sandboxed query-planner for POC #240

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
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
1,023 changes: 569 additions & 454 deletions federation-2/router-bridge/package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions federation-2/router-bridge/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"dependencies": {
"@apollo/core-schema": "^0.3.0",
"@apollo/federation-internals": "^2.3.2",
"@apollo/query-planner": "^2.3.2",
"@apollo/query-planner": "https://pkg.csb.dev/apollographql/federation/commit/ee7f4e4e/@apollo/query-planner",
"@apollo/utils.usagereporting": "^1.0.0",
"apollo-reporting-protobuf": "^3.3.1",
"fast-text-encoding": "1.0.3",
Expand All @@ -53,4 +53,4 @@
"node": "16.13.2",
"npm": "8.3.1"
}
}
}
31 changes: 31 additions & 0 deletions federation-2/router-bridge/src/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1198,6 +1198,37 @@ GraphQL request:4:9

pretty_assertions::assert_eq!(expected_errors, actual_errors);
}

#[tokio::test]
async fn try_to_get_a_plan_for_a_subscription() {
let planner = Planner::<serde_json::Value>::new(
include_str!("testdata/subscription_schema.graphql").to_string(),
QueryPlannerConfig::default(),
)
.await
.unwrap();

let payload = planner
.plan(
r#"subscription Subscription {
aDieWasCreated {
color
roll
sides
}
}"#
.to_string(),
None,
)
.await
.unwrap()
.into_result()
.unwrap();
insta::assert_snapshot!(serde_json::to_string_pretty(&payload.data).unwrap());
insta::with_settings!({sort_maps => true}, {
insta::assert_json_snapshot!(payload.usage_reporting);
});
}
}

#[cfg(test)]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
source: router-bridge/src/planner.rs
expression: payload.usage_reporting
---
{
"statsReportKey": "# Subscription\nsubscription Subscription{aDieWasCreated{color roll sides}}",
"referencedFieldsByType": {
"Die": {
"fieldNames": [
"color",
"roll",
"sides"
],
"isInterface": false
},
"Subscription": {
"fieldNames": [
"aDieWasCreated"
],
"isInterface": false
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
source: router-bridge/src/planner.rs
expression: "serde_json::to_string_pretty(&payload.data).unwrap()"
---
{
"queryPlan": {
"kind": "QueryPlan",
"node": {
"kind": "SubscriptionPlan",
"primary": {
"kind": "Subscription",
"serviceName": "dicefactory",
"variableUsages": [],
"operation": "subscription Subscription__dicefactory__0{aDieWasCreated{__typename sides color}}",
"operationKind": "subscription",
"operationName": "Subscription__dicefactory__0"
},
"rest": {
"kind": "Sequence",
"nodes": [
{
"kind": "Flatten",
"path": [
"aDieWasCreated"
],
"node": {
"kind": "Fetch",
"serviceName": "rng",
"requires": [
{
"kind": "InlineFragment",
"typeCondition": "Die",
"selections": [
{
"kind": "Field",
"name": "__typename"
},
{
"kind": "Field",
"name": "sides"
}
]
}
],
"variableUsages": [],
"operation": "query Subscription__rng__1($representations:[_Any!]!){_entities(representations:$representations){...on Die{roll}}}",
"operationKind": "query",
"operationName": "Subscription__rng__1"
}
}
]
}
}
},
"formattedQueryPlan": "QueryPlan {\n SubscriptionPlan {\n Primary: {\n Subscription(service: \"dicefactory\") {\n {\n aDieWasCreated {\n __typename\n sides\n color\n }\n }\n }\n },\n Rest: {\n Sequence {\n Flatten(path: \"aDieWasCreated\") {\n Fetch(service: \"rng\") {\n {\n ... on Die {\n __typename\n sides\n }\n } =>\n {\n ... on Die {\n roll\n }\n }\n },\n },\n }\n }\n },\n}"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
schema
@link(url: "https://specs.apollo.dev/link/v1.0")
@link(url: "https://specs.apollo.dev/join/v0.2", for: EXECUTION) {
query: Query
subscription: Subscription
}

directive @join__field(
graph: join__Graph!
requires: join__FieldSet
provides: join__FieldSet
type: String
external: Boolean
override: String
usedOverridden: Boolean
) 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
) repeatable on OBJECT | INTERFACE | UNION | ENUM | INPUT_OBJECT | SCALAR

directive @link(
url: String
as: String
for: link__Purpose
import: [link__Import]
) repeatable on SCHEMA

type Die
@join__type(graph: DICEFACTORY, key: "sides")
@join__type(graph: RNG, key: "sides") {
sides: Int!
color: String! @join__field(graph: DICEFACTORY)
roll: Int! @join__field(graph: RNG)
}

scalar join__FieldSet

enum join__Graph {
DICEFACTORY @join__graph(name: "dicefactory", url: "http://localhost:4001")
RNG @join__graph(name: "rng", url: "http://localhost:4002")
}

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: DICEFACTORY) @join__type(graph: RNG) {
die: Die @join__field(graph: DICEFACTORY)
}

type Subscription @join__type(graph: DICEFACTORY) {
aDieWasCreated: Die
}
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.