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 9 commits
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,26 @@
### Compress subgraph operations by generating fragments

The router now compresses operations sent to subgraphs by default by generating fragment
definitions and using them in the operation.

Initially, the router is using a very simple transformation that is implemented in both
the JavaScript and Native query planners. We will improve the algorithm after the JavaScript
planner is no longer supported.

This replaces a previous experimental algorithm that was enabled by default.
`experimental_reuse_query_fragments` attempted to intelligently reuse the fragment definitions
from the original operation. Fragment generation is much faster, and in most cases produces
better outputs too.

If you are relying on the shape of fragments in your subgraph operations or tests, you can opt
out of the new algorithm with the configuration below. Note we strongly recommend against
relying on the shape of planned operations as new router features and optimizations may affect
it, and we intend to remove `experimental_reuse_query_fragments` in a future release.

```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
10 changes: 7 additions & 3 deletions apollo-router/src/configuration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ pub(crate) struct Supergraph {
pub(crate) reuse_query_fragments: Option<bool>,

/// Enable QP generation of fragments for subgraph requests
/// Default: false
/// Default: true
pub(crate) generate_query_fragments: bool,

/// Set to false to disable defer support
Expand All @@ -685,6 +685,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 Expand Up @@ -737,7 +741,7 @@ impl Supergraph {
Some(false)
} else { reuse_query_fragments }
),
generate_query_fragments: generate_query_fragments.unwrap_or_default(),
generate_query_fragments: generate_query_fragments.unwrap_or_else(default_generate_query_fragments),
early_cancel: early_cancel.unwrap_or_default(),
experimental_log_on_broken_pipe: experimental_log_on_broken_pipe.unwrap_or_default(),
}
Expand Down Expand Up @@ -774,7 +778,7 @@ impl Supergraph {
Some(false)
} else { reuse_query_fragments }
),
generate_query_fragments: generate_query_fragments.unwrap_or_default(),
generate_query_fragments: generate_query_fragments.unwrap_or_else(default_generate_query_fragments),
early_cancel: early_cancel.unwrap_or_default(),
experimental_log_on_broken_pipe: experimental_log_on_broken_pipe.unwrap_or_default(),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6526,8 +6526,8 @@ expression: "&schema"
"type": "boolean"
},
"generate_query_fragments": {
"default": false,
"description": "Enable QP generation of fragments for subgraph requests Default: false",
"default": true,
"description": "Enable QP generation of fragments for subgraph requests Default: true",
"type": "boolean"
},
"introspection": {
Expand Down
25 changes: 16 additions & 9 deletions docs/source/configuration/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1191,22 +1191,29 @@ example:
password: "${env.MY_PASSWORD}" #highlight-line
```

### Fragment reuse and generation
<!-- keep links to the old heading name working -->
<a id="fragment-reuse-and-generation"></a>
### Fragment generation and reuse

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 compresses subgraph requests by generating fragment
definitions based on the shape of the subgraph operation. In many cases this
significantly reduces the size of the query sent to subgraphs.

```yaml
supergraph:
experimental_reuse_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.
The router also supports an experimental algorithm that attempts to reuse fragments
from the original operation while forming subgraph requests. This experimental feature
used to be enabled by default, but is still available to support subgraphs that rely
on the specific shape of fragments in an operation:

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

Note that `generate_query_fragments` and `experimental_reuse_query_fragments` are
mutually exclusive; if both are explicitly set to `true`, `generate_query_fragments`
will take precedence.

### Reusing configuration

You can reuse parts of your configuration file in multiple places using standard YAML aliasing syntax:
Expand Down
Loading