-
Notifications
You must be signed in to change notification settings - Fork 23
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
Ensure directives are preserved when serializing subgraph schemas in planner #568
Merged
sachindshinde
merged 6 commits into
router-bridge@v0.6.0-beta.1+v2.9.0-beta.0
from
tninesling/2.9-beta-fix
Aug 26, 2024
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
56fd74c
Ensure directives are preserved when serializing subgraph schemas in …
tninesling bec6cc0
Fix existing test which now has directives preserved
tninesling ac6c6d2
Update remaining snapshots for tests that now have directives preserved
tninesling 4ff041b
Use fed internals schema printer
tninesling 4cf29eb
Fix package version
tninesling 837f731
Use separate snapshots for each subgraph in extract test
tninesling File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
112 changes: 112 additions & 0 deletions
112
router-bridge/src/snapshots/router_bridge__planner__error_display__subgraphWithCost.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,112 @@ | ||
--- | ||
source: router-bridge/src/planner.rs | ||
expression: schema | ||
--- | ||
schema | ||
@link(url: "https://specs.apollo.dev/link/v1.0") | ||
@link(url: "https://specs.apollo.dev/federation/v2.9", import: ["@key", "@requires", "@provides", "@external", "@tag", "@extends", "@shareable", "@inaccessible", "@override", "@composeDirective", "@interfaceObject"]) | ||
{ | ||
query: Query | ||
} | ||
|
||
directive @link(url: String, as: String, for: link__Purpose, import: [link__Import]) repeatable on SCHEMA | ||
|
||
directive @key(fields: federation__FieldSet!, resolvable: Boolean = true) repeatable on OBJECT | INTERFACE | ||
|
||
directive @requires(fields: federation__FieldSet!) on FIELD_DEFINITION | ||
|
||
directive @provides(fields: federation__FieldSet!) on FIELD_DEFINITION | ||
|
||
directive @external(reason: String) on OBJECT | FIELD_DEFINITION | ||
|
||
directive @tag(name: String!) repeatable on FIELD_DEFINITION | OBJECT | INTERFACE | UNION | ARGUMENT_DEFINITION | SCALAR | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION | SCHEMA | ||
|
||
directive @extends on OBJECT | INTERFACE | ||
|
||
directive @shareable repeatable on OBJECT | FIELD_DEFINITION | ||
|
||
directive @inaccessible on FIELD_DEFINITION | OBJECT | INTERFACE | UNION | ARGUMENT_DEFINITION | SCALAR | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION | ||
|
||
directive @override(from: String!, label: String) on FIELD_DEFINITION | ||
|
||
directive @composeDirective(name: String) repeatable on SCHEMA | ||
|
||
directive @interfaceObject on OBJECT | ||
|
||
directive @federation__authenticated on FIELD_DEFINITION | OBJECT | INTERFACE | SCALAR | ENUM | ||
|
||
directive @federation__requiresScopes(scopes: [[federation__Scope!]!]!) on FIELD_DEFINITION | OBJECT | INTERFACE | SCALAR | ENUM | ||
|
||
directive @federation__policy(policies: [[federation__Policy!]!]!) on FIELD_DEFINITION | OBJECT | INTERFACE | SCALAR | ENUM | ||
|
||
directive @federation__sourceAPI repeatable on SCHEMA | ||
|
||
directive @federation__sourceType repeatable on OBJECT | INTERFACE | ||
|
||
directive @federation__sourceField repeatable on FIELD_DEFINITION | ||
|
||
directive @federation__context(name: String!) repeatable on INTERFACE | OBJECT | UNION | ||
|
||
directive @federation__fromContext(field: federation__ContextFieldValue) on ARGUMENT_DEFINITION | ||
|
||
directive @federation__cost(weight: Int!) on ARGUMENT_DEFINITION | ENUM | FIELD_DEFINITION | INPUT_FIELD_DEFINITION | OBJECT | SCALAR | ||
|
||
directive @federation__listSize(assumedSize: Int, slicingArguments: [String!], sizedFields: [String!], requireOneSlicingArgument: Boolean = true) on FIELD_DEFINITION | ||
|
||
enum link__Purpose { | ||
""" | ||
`SECURITY` features provide metadata necessary to securely resolve fields. | ||
""" | ||
SECURITY | ||
|
||
""" | ||
`EXECUTION` features provide metadata necessary for operation execution. | ||
""" | ||
EXECUTION | ||
} | ||
|
||
scalar link__Import | ||
|
||
scalar federation__FieldSet | ||
|
||
scalar federation__Scope | ||
|
||
scalar federation__Policy | ||
|
||
scalar federation__ContextFieldValue | ||
|
||
enum AorB | ||
@federation__cost(weight: 15) | ||
{ | ||
A | ||
B | ||
} | ||
|
||
scalar ExpensiveInt | ||
@federation__cost(weight: 30) | ||
|
||
type ExpensiveObject | ||
@federation__cost(weight: 40) | ||
{ | ||
id: ID | ||
} | ||
|
||
input InputTypeWithCost { | ||
somethingWithCost: Int @federation__cost(weight: 20) | ||
} | ||
|
||
type Query { | ||
fieldWithCost: Int @federation__cost(weight: 5) | ||
argWithCost(arg: Int @federation__cost(weight: 10)): Int | ||
enumWithCost: AorB | ||
inputWithCost(someInput: InputTypeWithCost): Int | ||
scalarWithCost: ExpensiveInt | ||
objectWithCost: ExpensiveObject | ||
_service: _Service! | ||
} | ||
|
||
scalar _Any | ||
|
||
type _Service { | ||
sdl: String | ||
} |
96 changes: 96 additions & 0 deletions
96
router-bridge/src/snapshots/router_bridge__planner__error_display__subgraphWithListSize.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,96 @@ | ||
--- | ||
source: router-bridge/src/planner.rs | ||
expression: schema | ||
--- | ||
schema | ||
@link(url: "https://specs.apollo.dev/link/v1.0") | ||
@link(url: "https://specs.apollo.dev/federation/v2.9", import: ["@key", "@requires", "@provides", "@external", "@tag", "@extends", "@shareable", "@inaccessible", "@override", "@composeDirective", "@interfaceObject"]) | ||
{ | ||
query: Query | ||
} | ||
|
||
directive @link(url: String, as: String, for: link__Purpose, import: [link__Import]) repeatable on SCHEMA | ||
|
||
directive @key(fields: federation__FieldSet!, resolvable: Boolean = true) repeatable on OBJECT | INTERFACE | ||
|
||
directive @requires(fields: federation__FieldSet!) on FIELD_DEFINITION | ||
|
||
directive @provides(fields: federation__FieldSet!) on FIELD_DEFINITION | ||
|
||
directive @external(reason: String) on OBJECT | FIELD_DEFINITION | ||
|
||
directive @tag(name: String!) repeatable on FIELD_DEFINITION | OBJECT | INTERFACE | UNION | ARGUMENT_DEFINITION | SCALAR | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION | SCHEMA | ||
|
||
directive @extends on OBJECT | INTERFACE | ||
|
||
directive @shareable repeatable on OBJECT | FIELD_DEFINITION | ||
|
||
directive @inaccessible on FIELD_DEFINITION | OBJECT | INTERFACE | UNION | ARGUMENT_DEFINITION | SCALAR | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION | ||
|
||
directive @override(from: String!, label: String) on FIELD_DEFINITION | ||
|
||
directive @composeDirective(name: String) repeatable on SCHEMA | ||
|
||
directive @interfaceObject on OBJECT | ||
|
||
directive @federation__authenticated on FIELD_DEFINITION | OBJECT | INTERFACE | SCALAR | ENUM | ||
|
||
directive @federation__requiresScopes(scopes: [[federation__Scope!]!]!) on FIELD_DEFINITION | OBJECT | INTERFACE | SCALAR | ENUM | ||
|
||
directive @federation__policy(policies: [[federation__Policy!]!]!) on FIELD_DEFINITION | OBJECT | INTERFACE | SCALAR | ENUM | ||
|
||
directive @federation__sourceAPI repeatable on SCHEMA | ||
|
||
directive @federation__sourceType repeatable on OBJECT | INTERFACE | ||
|
||
directive @federation__sourceField repeatable on FIELD_DEFINITION | ||
|
||
directive @federation__context(name: String!) repeatable on INTERFACE | OBJECT | UNION | ||
|
||
directive @federation__fromContext(field: federation__ContextFieldValue) on ARGUMENT_DEFINITION | ||
|
||
directive @federation__cost(weight: Int!) on ARGUMENT_DEFINITION | ENUM | FIELD_DEFINITION | INPUT_FIELD_DEFINITION | OBJECT | SCALAR | ||
|
||
directive @federation__listSize(assumedSize: Int, slicingArguments: [String!], sizedFields: [String!], requireOneSlicingArgument: Boolean = true) on FIELD_DEFINITION | ||
|
||
enum link__Purpose { | ||
""" | ||
`SECURITY` features provide metadata necessary to securely resolve fields. | ||
""" | ||
SECURITY | ||
|
||
""" | ||
`EXECUTION` features provide metadata necessary for operation execution. | ||
""" | ||
EXECUTION | ||
} | ||
|
||
scalar link__Import | ||
|
||
scalar federation__FieldSet | ||
|
||
scalar federation__Scope | ||
|
||
scalar federation__Policy | ||
|
||
scalar federation__ContextFieldValue | ||
|
||
type A { | ||
id: ID | ||
} | ||
|
||
type Query { | ||
fieldWithListSize: [String!] @federation__listSize(assumedSize: 2000, requireOneSlicingArgument: false) | ||
fieldWithDynamicListSize(first: Int = 10): SizedField @federation__listSize(slicingArguments: ["first"], sizedFields: ["items"], requireOneSlicingArgument: true) | ||
_service: _Service! | ||
} | ||
|
||
type SizedField { | ||
items: [A] | ||
} | ||
|
||
scalar _Any | ||
|
||
type _Service { | ||
sdl: String | ||
} |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(This comment is more of an FYI, nothing to fix.) Looking at the PR that introduced
subgraphs()
, it seems this method is used to generate subgraph schemas to validate subgraph responses against. Two things here:shouldValidate
when callingSupergraph.build()
in router), so it should be fine (i.e., if there were bugs in how we generated/printed subgraph schemas, they wouldn't suddenly be triggered after this PR).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It shouldn't affect that part of the code. One thing I'm noticing when running the router tests against this change is that it changes the query hash in a few tests because the hash will include directives if they exist. So, this will bust the cache, but that happens anyway when we bump the federation version. I think this will still be correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tninesling
This presumably also would cause cache misses when just a subgraph schema's directive applications change, though if such caches are also keyed by the supergraph schema (which presumably hasn't had directive applications stripped away), then this cache miss was going to happen anyway, so it's fine.
It might be something for @Geal to chime in on once they're available, but it probably shouldn't block a new RC release.