Skip to content

Commit

Permalink
re-add support for reuse fragments for JS QP
Browse files Browse the repository at this point in the history
  • Loading branch information
dariuszkuc committed Dec 2, 2024
1 parent baac260 commit cab4987
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
13 changes: 13 additions & 0 deletions apollo-router/src/configuration/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ impl Metrics {
data.populate_user_plugins_instrument(configuration);
data.populate_query_planner_experimental_parallelism(configuration);
data.populate_deno_or_rust_mode_instruments(configuration);
data.populate_legacy_fragment_usage(configuration);

data.into()
}
Expand Down Expand Up @@ -497,6 +498,18 @@ impl InstrumentData {
);
}

pub(crate) fn populate_legacy_fragment_usage(&mut self, configuration: &Configuration) {
// Fragment generation takes precedence over fragment reuse. Only report when fragment reuse is *actually active*.
if configuration.supergraph.reuse_query_fragments == Some(true)
&& !configuration.supergraph.generate_query_fragments
{
self.data.insert(
"apollo.router.config.reuse_query_fragments".to_string(),
(1, HashMap::new()),
);
}
}

pub(crate) fn populate_query_planner_experimental_parallelism(
&mut self,
configuration: &Configuration,
Expand Down
37 changes: 36 additions & 1 deletion apollo-router/src/configuration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ impl Configuration {

pub(crate) fn js_query_planner_config(&self) -> router_bridge::planner::QueryPlannerConfig {
router_bridge::planner::QueryPlannerConfig {
reuse_query_fragments: None,
reuse_query_fragments: self.supergraph.reuse_query_fragments,
generate_query_fragments: Some(self.supergraph.generate_query_fragments),
incremental_delivery: Some(router_bridge::planner::IncrementalDeliverySupport {
enable_defer: Some(self.supergraph.defer_support),
Expand All @@ -416,6 +416,14 @@ impl Configuration {
pub(crate) fn rust_query_planner_config(
&self,
) -> apollo_federation::query_plan::query_planner::QueryPlannerConfig {
if self
.supergraph
.reuse_query_fragments
.is_some_and(|flag| flag)
{
// warn the user that reuse query fragments is unsupported for RS QP
tracing::warn!("'experimental_reuse_query_fragments' is not supported by the Rust QP and this configuration option will be removed in the next release. Use 'generate_query_fragments' instead.");
}
apollo_federation::query_plan::query_planner::QueryPlannerConfig {
subgraph_graphql_validation: false,
generate_query_fragments: self.supergraph.generate_query_fragments,
Expand Down Expand Up @@ -682,6 +690,13 @@ pub(crate) struct Supergraph {
/// Default: false
pub(crate) introspection: bool,

/// Enable reuse of query fragments
///
/// This feature is deprecated and will be removed in next release. It is only available in JS QP.
/// Use generate_query_fragments instead.
#[serde(rename = "experimental_reuse_query_fragments")]
pub(crate) reuse_query_fragments: Option<bool>,

/// Enable QP generation of fragments for subgraph requests
/// Default: true
pub(crate) generate_query_fragments: bool,
Expand Down Expand Up @@ -739,6 +754,7 @@ impl Supergraph {
introspection: Option<bool>,
defer_support: Option<bool>,
query_planning: Option<QueryPlanning>,
reuse_query_fragments: Option<bool>,
generate_query_fragments: Option<bool>,
early_cancel: Option<bool>,
experimental_log_on_broken_pipe: Option<bool>,
Expand All @@ -749,6 +765,15 @@ impl Supergraph {
introspection: introspection.unwrap_or_else(default_graphql_introspection),
defer_support: defer_support.unwrap_or_else(default_defer_support),
query_planning: query_planning.unwrap_or_default(),
reuse_query_fragments: generate_query_fragments.and_then(|v|
if v {
if reuse_query_fragments.is_some_and(|v| v) {
// warn the user that both are enabled and it's overridden
tracing::warn!("Both 'generate_query_fragments' and 'experimental_reuse_query_fragments' are explicitly enabled, 'experimental_reuse_query_fragments' will be overridden to false");
}
Some(false)
} else { reuse_query_fragments }
),
generate_query_fragments: generate_query_fragments
.unwrap_or_else(default_generate_query_fragments),
early_cancel: early_cancel.unwrap_or_default(),
Expand All @@ -767,6 +792,7 @@ impl Supergraph {
introspection: Option<bool>,
defer_support: Option<bool>,
query_planning: Option<QueryPlanning>,
reuse_query_fragments: Option<bool>,
generate_query_fragments: Option<bool>,
early_cancel: Option<bool>,
experimental_log_on_broken_pipe: Option<bool>,
Expand All @@ -777,6 +803,15 @@ impl Supergraph {
introspection: introspection.unwrap_or_else(default_graphql_introspection),
defer_support: defer_support.unwrap_or_else(default_defer_support),
query_planning: query_planning.unwrap_or_default(),
reuse_query_fragments: generate_query_fragments.and_then(|v|
if v {
if reuse_query_fragments.is_some_and(|v| v) {
// warn the user that both are enabled and it's overridden
tracing::warn!("Both 'generate_query_fragments' and 'experimental_reuse_query_fragments' are explicitly enabled, 'experimental_reuse_query_fragments' will be overridden to false");
}
Some(false)
} else { reuse_query_fragments }
),
generate_query_fragments: generate_query_fragments
.unwrap_or_else(default_generate_query_fragments),
early_cancel: early_cancel.unwrap_or_default(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6617,6 +6617,12 @@ snapshot_kind: text
"description": "Log a message if the client closes the connection before the response is sent. Default: false.",
"type": "boolean"
},
"experimental_reuse_query_fragments": {
"default": null,
"description": "Enable reuse of query fragments\n\nThis feature is deprecated and will be removed in next release. It is only available in JS QP. Use generate_query_fragments instead.",
"nullable": true,
"type": "boolean"
},
"generate_query_fragments": {
"default": true,
"description": "Enable QP generation of fragments for subgraph requests Default: true",
Expand Down

0 comments on commit cab4987

Please sign in to comment.