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

feat(federation): add @context support #6310

Merged
merged 39 commits into from
Nov 21, 2024
Merged

Conversation

clenfest
Copy link
Contributor

Brings Rust query planner to parity with JS.

lrlna and others added 30 commits November 20, 2024 18:51
apollo_federation::QueryPlannerConfig is currently missing Serialize implementation that will be eventually needed for the query planner cache once we use only one planner in the Router.
Co-authored-by: TylerBloom <tylerbloom2222@gmail.com>
#6223)

Co-authored-by: Chris Lenfest <clenfest@apollographql.com>
Co-authored-by: Tyler Bloom <tylerbloom2222@gmail.com>
Co-authored-by: Tyler Bloom <tylerbloom2222@gmail.com>
In order to support `@context` during fetch dependency graph processing, this PR refactors `handle_requires()` into two functions: `handle_conditions_tree()` and `create_post_requires_node()` (the first of which gets reused by `@context` logic).
… and miscellaneous bugfixes (#6276)

This PR:
1. Updates `compute_nodes_for_op_path_element()` to handle `@context`/`@fromContext` on fields, using the refactored `handleRequires()` functions created during #6263.
2. Updates `to_plan_node()` to add context variables and usages to the query plan fetch nodes.
3. Fixes a `todo()` in `resolve_condition_plan()` where the `context_map` should be `None`.
4. Changes various typings introduced during the `@context`/`@fromContext` work to be more specific, usually replacing `String` with `Name` or `FetchDataPathElement`.
5. Introduces `FetchDataPathElement::Parent` for specifically representing the "goto parent" element in fetch paths (`".."` is not a valid GraphQL name, and we shouldn't be using it in `FetchDataPathElement::Key`).
    - I did not change this behavior in router's query plan execution, which still currently uses a key with name `".."` (they're also using `String`s instead of `Name`s for keys, so this is a little less bad). 
6. Switches `HashSet` usages to `IndexSet`, as `HashSet`/`HashMap` in the past have shown non-determinism during tests. (We were also seeing non-determinism during debugging.)
7. Switches `context_rewrites` in `FetchNode` to use `Vec<Arc<FetchDataRewrite>>` instead of `Vec<FetchDataRewrite>`, as this fixes a router compilation issue I was having with `convert.rs`.
    - This is mainly meant to quickly unblock, if folks want to de-`Arc` more I'm fine with us updating `convert.rs` later.
8. Switches `context_inputs` in `FetchDependencyGraphNode` to use `Vec<FetchDataKeyRenamer>` instead of `Vec<FetchDataRewrite>`.
    - We currently do not use value setters at all for `@context`/`@fromContext`, and allowing the extra variability for that field doesn't make sense (it's similar to the issue we have today with fragment spreads in selection sets, but we have an easy solution here). If we end up using value setters one day, I'm fine with changing it then.
    - If folks want to use `FetchDataRewrite` instead of `FetchDataKeyRenamer` in `FetchNode` because it simplifies `FetchNode` or router code (or if we want to effectively reserve the ability to use value setters there in the future), I'm more okay with the change to `FetchNode`.
9. Fixes various Rust-only bugs:
    - `FetchDependencyGraphNode::copy_inputs()` wasn't eliminating duplicate context renamers.
    - `FetchDependencyGraphNode::contains()` was using `==` instead of `<` for comparing used contexts.
    - Used contexts in `FetchDependencyGraphNode` should reference the full type instead of just the type position.
10. Fixes a bug present in both JS and Rust (and will need backporting to JS):
    - When a post-`@context` node doesn't need to be created, we weren't creating parent-child relationships with the condition nodes.
Co-authored-by: TylerBloom <tylerbloom2222@gmail.com>
…oups` (#6302)

Added `extra_conditions` argument to to `ConditionResolverCache` which was causing error in a snapshot test.
@lrlna lrlna marked this pull request as ready for review November 21, 2024 10:22
@goto-bus-stop goto-bus-stop changed the title add @context support in the rust query planner feat(federation): add @context support Nov 21, 2024
@goto-bus-stop goto-bus-stop changed the title feat(federation): add @context support feat(federation): add @context support Nov 21, 2024
@goto-bus-stop goto-bus-stop requested a review from a team as a code owner November 21, 2024 10:59
Copy link
Member

@lrlna lrlna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@goto-bus-stop let's run some perf tests and pay attention to these two things in:

  1. rebase
  2. edge conditions in compute_nodes_for_op_path_element

@lrlna lrlna changed the base branch from dev to 1.58.0 November 21, 2024 13:02
@lrlna lrlna merged commit 165bd92 into 1.58.0 Nov 21, 2024
13 checks passed
@lrlna lrlna deleted the router-528-impl-set-context branch November 21, 2024 14:14
@abernix abernix mentioned this pull request Nov 26, 2024
IvanGoncharov added a commit that referenced this pull request Nov 30, 2024
`dev` wasn't merge in #6205 before it was squashed and committed.
Because of that `dev` had some changes in tests that didn't change hash produced by old query hash agorithm but resulted in a hash change once #6205 was merged.
Example: #6310 Added test changes related to @context and #6205 added a special case to handle @context directives
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants