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

Open
wants to merge 12 commits into
base: dev
Choose a base branch
from
Open
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