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
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
be83e30
Enable `generate_query_fragments` by default
lrlna Sep 17, 2024
ee0975d
update config snapshot
lrlna Sep 17, 2024
cd3c249
Update docs/source/configuration/overview.mdx
lrlna Sep 17, 2024
1daae5d
use unwrap_or_else for generate_query_fragments defaults
lrlna Sep 17, 2024
51e89cb
update redis cache keys
lrlna Sep 17, 2024
6f43f20
new changelog
goto-bus-stop Oct 16, 2024
a6035eb
Merge branch 'dev' into lrlna/enable-generate-fragments
goto-bus-stop Oct 16, 2024
e807ff6
explain experimental/legacy state of fragment reuse in docs; do not s…
goto-bus-stop Oct 16, 2024
f1f45a7
keep links to the old header name working
goto-bus-stop Oct 16, 2024
0c40214
Update mocks: migrate some to fragment generation, disable fragment g…
goto-bus-stop Oct 16, 2024
544ce20
Merge branch 'dev' into lrlna/enable-generate-fragments
goto-bus-stop Oct 16, 2024
f5e1898
Update more mocks to use frag generation
goto-bus-stop Oct 23, 2024
b395dcc
Update at least one type conditioned fetching mock
goto-bus-stop Oct 23, 2024
592c45c
Fix redis tests
goto-bus-stop Oct 30, 2024
c51d105
Disable fragment generation for setContext integration tests
goto-bus-stop Oct 30, 2024
e638565
fix type condition test mocks
goto-bus-stop Oct 30, 2024
820977e
Update expectations in entity cache invalidation test
goto-bus-stop Oct 31, 2024
d2379fe
Merge branch 'dev' into lrlna/enable-generate-fragments
goto-bus-stop Nov 5, 2024
c734f9b
update mock for entity-cache + defer test
goto-bus-stop Nov 6, 2024
bc2ae12
update redis keys
goto-bus-stop Nov 6, 2024
eef215d
update core/defer mock
goto-bus-stop Nov 7, 2024
bf90de4
Merge branch 'dev' into lrlna/enable-generate-fragments
goto-bus-stop Nov 7, 2024
236fba6
Also swap the defaults inside apollo-federation
goto-bus-stop Nov 8, 2024
c3c86ac
Revert "Also swap the defaults inside apollo-federation"
goto-bus-stop Nov 8, 2024
2e235a8
Disable reuse fragments by default inside apollo-federation
goto-bus-stop Nov 8, 2024
e4190e1
linting once again
goto-bus-stop Nov 8, 2024
45fb226
Merge branch 'dev' into lrlna/enable-generate-fragments
goto-bus-stop Nov 8, 2024
c571242
update mock in benchmarks test
goto-bus-stop Nov 8, 2024
cb539c2
Merge branch 'dev' into lrlna/enable-generate-fragments
goto-bus-stop Nov 11, 2024
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
### Enable query fragment generation by default

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
```

By [@lrlna](https://github.com/lrlna) in https://github.com/apollographql/router/pull/6013
7 changes: 6 additions & 1 deletion apollo-router/src/configuration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,8 @@ pub(crate) struct Supergraph {
pub(crate) reuse_query_fragments: Option<bool>,

/// Enable QP generation of fragments for subgraph requests
/// Default: false
/// Default: true
#[serde(default = "default_generate_query_fragments")]
lrlna marked this conversation as resolved.
Show resolved Hide resolved
pub(crate) generate_query_fragments: bool,

/// Set to false to disable defer support
Expand All @@ -710,6 +711,10 @@ pub(crate) struct Supergraph {
pub(crate) experimental_log_on_broken_pipe: bool,
}

const fn default_generate_query_fragments() -> bool {
true
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, Deserialize, Serialize, JsonSchema)]
#[serde(rename_all = "snake_case", untagged)]
pub(crate) enum AvailableParallelism {
Expand Down
17 changes: 13 additions & 4 deletions docs/source/configuration/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1175,18 +1175,27 @@ example:

### Fragment reuse and generation

By default, the router will attempt to reuse fragments from the original query while forming subgraph requests. This behavior can be disabled by setting the option to `false`:
By default, the router will _generate_ fragments for subgraph requests,
extracting _inline fragments only_ into fragment definitions before sending
queries to subgraphs. In very many cases this significantly reduces the size of
the query sent to subgraphs, but may increase the time it takes for planning.
Note that this option and `experimental_reuse_query_fragments` are mutually
exclusive; if both are explicitly set to `true`, `generate_query_fragments` will
take precedence. This behaviour can be disabled by setting the option to `false`:
lrlna marked this conversation as resolved.
Show resolved Hide resolved

```yaml
supergraph:
experimental_reuse_query_fragments: false
generate_query_fragments: false
```

Alternatively, the router can be configured to _generate_ fragments for subgraph requests. When set to `true`, the router will extract _inline fragments only_ into fragment definitions before sending queries to subgraphs. This can significantly reduce the size of the query sent to subgraphs, but may increase the time it takes for planning. Note that this option and `experimental_reuse_query_fragments` are mutually exclusive; if both are explicitly set to `true`, `generate_query_fragments` will take precedence.
Alternatively, the router can attempt to reuse fragments from the original query
while forming subgraph requests. This often results in largers queries sent to
subgraphs, but it may be decrease planning times. This behavior can be enabled
by setting the option to `true`:

```yaml
supergraph:
generate_query_fragments: true
experimental_reuse_query_fragments: true
```

### Reusing configuration
Expand Down
Loading