-
Notifications
You must be signed in to change notification settings - Fork 1
Query Planner constructor and some strictness improvements #175
Conversation
For QP work, the API schema result needs to be a `FederationSchema`. We also know that the API schema result is valid, so we make it a `ValidFederationSchema`. API schema must also only be called on valid schemas so the input is changed to a `ValidFederationSchema`. Supergraphs are also federation schemas so this changes the constructors to build a `ValidFederationSchema` early. `ValidFederationSchema` contains an `Arc` while `FederationSchema` doesn't, and that is relied upon in a few places. I add some clones of the inner schema to convert from an immutable `ValidFederationSchema` to a mutable `FederationSchema`, it maybe could be done more efficiently, but it's OK.
…ible` if the spec exists in
The actual implementation of subgraph extraction is in the `query_graph` module.
Most of the existing tests on the JS side are checking behaviours in Fed 1 supergraphs. I don't think I can port those over yet as Fed 1 supergraphs are out of scope. I will add some notes/questions to this PR about the differences between JS and Rust data structures |
paths_limit: None, | ||
} | ||
} | ||
} | ||
|
||
pub struct QueryPlanner { | ||
config: Arc<QueryPlannerConfig>, | ||
// TODO(@goto-bus-stop) not convinced that these arcs are all necessary | ||
config: QueryPlannerConfig, | ||
federated_query_graph: Arc<QueryGraph>, | ||
supergraph_schema: ValidFederationSchema, | ||
api_schema: ValidFederationSchema, | ||
subgraph_federation_spec_definitions: Arc<IndexMap<NodeStr, &'static FederationSpecDefinition>>, |
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.
I didn't find this in the JS implementation. I do understand what it needs to do because of the type. But how is it going to be used?
src/lib.rs
Outdated
|
||
pub struct Supergraph { | ||
pub schema: Valid<Schema>, | ||
pub schema: ValidFederationSchema, | ||
} | ||
|
||
impl Supergraph { | ||
pub fn new(schema_str: &str) -> Result<Self, FederationError> { | ||
let schema = Schema::parse_and_validate(schema_str, "schema.graphql")?; | ||
// TODO: federation-specific validation |
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.
Is this TODO still relevant?
src/lib.rs
Outdated
@@ -141,7 +151,7 @@ mod tests { | |||
"#; | |||
|
|||
let supergraph = Supergraph::new(schema).unwrap(); | |||
let _subgraphs = database::extract_subgraphs(&supergraph) | |||
let _subgraphs = crate::query_graph::extract_subgraphs_from_supergraph::extract_subgraphs_from_supergraph(&supergraph.schema, None) | |||
.expect("Should have been able to extract subgraphs"); | |||
// TODO: actual assertions on the subgraph once it's actually implemented. |
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.
Is it time to add assertions there? Does JS have corresponding tests?
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.
AFAICT this test is not directly in JS, but we could add some that just assert the whole subgraph shape is as expected here.
3dc0cb0
to
313f0d2
Compare
I think this must only compare the fields that are selected, not the parent type and the schema it's a part of. That's because the selections are parsed in the context of a subgraph schema, so writing the same `@key()` in subgraph A and B results in selection sets that don't compare equal, but their actual selections do. And that is what key resolution cares about.
…phql/federation-next#175) This implements the constructor `QueryPlanner::new()`, which builds query graphs and does some minor precomputation, and: - fixes a few issues in subgraph extraction, were easy to miss since that code was not used before. also removed an old module that is obsolete. - introduce some use of `ValidFederationSchema` vs. `FederationSchema` in the API schema implementation, so there is less potential for misuse (this requires more cloning than i'd like--i'm not convinced that ValidFederationSchema being an Arc internally is the best thing to do, but understand the usefulness of its `==` implementation!) - move `@inaccessible` related functions onto the spec definition struct: this means you have to look up the inaccessible spec before using it, manually or from the schema, so there's less potential for misuse Closes FED-22 Closes FED-82
This implements the constructor
QueryPlanner::new()
, which builds query graphs and does some minor precomputation, and:ValidFederationSchema
vs.FederationSchema
in the API schema implementation, so there is less potential for misuse (this requires more cloning than i'd like--i'm not convinced that ValidFederationSchema being an Arc internally is the best thing to do, but understand the usefulness of its==
implementation!)@inaccessible
related functions onto the spec definition struct: this means you have to look up the inaccessible spec before using it, manually or from the schema, so there's less potential for misuseCloses FED-22
Closes FED-82