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

Enable generate_query_fragments by default #6013

Merged
merged 29 commits into from
Nov 13, 2024

Conversation

lrlna
Copy link
Member

@lrlna lrlna commented Sep 17, 2024

The router previously had experimental_reuse_query_fragments enabled by default when trying to optimize fragments before sending operations to subgraphs. While on occasion this algorithm can be more performant, we found that in vast majority of cases the query planner can be just as performant using generate_query_fragments query plan option, which also significantly reduces query size being sent to subgraphs. While the two options will produce correct responses, the queries produced internally by the query planner will differ.

This change enables generate_query_fragments by default, while disabling experimental_reuse_query_fragments. You can change this behavior with the following options:

supergraph:
  generate_query_fragments: false
  experimental_reuse_query_fragments: true

The router previously had `experimental_reuse_query_fragments` enabled by
default when trying to optimize fragments before sending operations to subgraphs.
While on occasion this algorithm can be more performant, we found that in vast
majority of cases the query planner can be just as performant using
`generate_query_fragments` query plan option, which also significantly reduces
query size being sent to subgraphs. While the two options will produce correct
responses, the queries produced internally by the query planner will differ.

This change enables `generate_query_fragments` by default, while disabling
`experimental_reuse_query_fragments`. You can change this behavior with the
following options:

```yaml
supergraph:
  generate_query_fragments: false
  experimental_reuse_query_fragments: true
```
@lrlna lrlna requested review from a team as code owners September 17, 2024 12:54
@lrlna lrlna self-assigned this Sep 17, 2024
@goto-bus-stop goto-bus-stop assigned goto-bus-stop and unassigned lrlna Oct 14, 2024
@svc-apollo-docs
Copy link
Collaborator

svc-apollo-docs commented Oct 16, 2024

✅ Docs Preview Ready

No new or changed pages found.

lennyburdette added a commit that referenced this pull request Oct 16, 2024
once #6013 lands, we'll need the code in connectors that converts fetch node operations to http calls to understand named fragments.
- Disable fragment generation on the tests that use mocks.
- Update the expected cache key on the other tests.
- Change the "update_generate_query_fragments" test to turn the option
  *off*, so it actually tests an update from the default *on*.
@goto-bus-stop
Copy link
Member

Oh there's been some new tests introduced in the mean time that are failing now 😭

@dariuszkuc dariuszkuc self-assigned this Nov 6, 2024
@@ -218,6 +218,10 @@ mod tests {
build_mock_supergraph(serde_json::json! {{
"plugins": {
"experimental.expose_query_plan": true
},
"supergraph": {
// TODO(@goto-bus-stop): need to update the mocks and remove this, #6013
Copy link
Member

Choose a reason for hiding this comment

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

should this be linking to a new issue (6013 is the existing PR#)?

Copy link
Member

Choose a reason for hiding this comment

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

The work would likely be done as part of removing reuse_query_fragments, I linked the PR as a place where you can find context

@@ -7,5 +7,5 @@ supergraph:
urls:
- redis://localhost:6379
ttl: 10s
generate_query_fragments: true
generate_query_fragments: false
Copy link
Member

Choose a reason for hiding this comment

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

was this intentional switch to false? guess the test is to verify non-default?

Copy link
Member

@goto-bus-stop goto-bus-stop Nov 8, 2024

Choose a reason for hiding this comment

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

Yes, it's to make sure the cache key updates when the config is flipped, so this has to use the non-default value

Copy link
Member

@dariuszkuc dariuszkuc left a comment

Choose a reason for hiding this comment

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

Shouldn't we also flip the defaults in the query planner itself? i.e. here -> https://github.com/apollographql/router/blob/dev/apollo-federation/src/query_plan/query_planner.rs#L110

@goto-bus-stop
Copy link
Member

That also requires updating many tests. I've instead disabled both optimizations by default in the planner. We should change the default inside apollo-federation after some improvements to the generation algorithm I think.

@goto-bus-stop goto-bus-stop enabled auto-merge (squash) November 11, 2024 15:16
generate_query_fragments: false,
subgraph_graphql_validation: false,
incremental_delivery: Default::default(),
debug: Default::default(),
type_conditioned_fetching: Default::default(),
type_conditioned_fetching: false,
Copy link
Member

Choose a reason for hiding this comment

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

nit: I believe Default::default() for boolean is false. Should we update other defaults to explicit false as well (for readability)?

Copy link
Member

Choose a reason for hiding this comment

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

Indeed. I wanted to be explicit about this. incremental_delivery and debug are not booleans but structs, so i kept them as Default::default. We could consider manually writing out Default impls for those types.

@goto-bus-stop goto-bus-stop merged commit ec54fb3 into dev Nov 13, 2024
14 checks passed
@goto-bus-stop goto-bus-stop deleted the lrlna/enable-generate-fragments branch November 13, 2024 18:18
@abernix abernix mentioned this pull request Nov 26, 2024
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.

6 participants