diff --git a/Cargo.lock b/Cargo.lock index 7b67b13377..433829c3b2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4472,7 +4472,7 @@ dependencies = [ [[package]] name = "router-bridge" version = "0.1.0" -source = "git+https://github.com/apollographql/federation-rs.git?tag=defer-alpha1#72f1fff5e57a80b4ed4fcbf13ef2ac33b0314b80" +source = "git+https://github.com/apollographql/federation-rs.git?tag=defer-alpha3#91d2bf016edc84866cc072534650548285a612ad" dependencies = [ "anyhow", "async-channel", diff --git a/NEXT_CHANGELOG.md b/NEXT_CHANGELOG.md index a5bfc21957..736fd81bb3 100644 --- a/NEXT_CHANGELOG.md +++ b/NEXT_CHANGELOG.md @@ -472,6 +472,12 @@ will create a separate response for each element of the array. By [@Geal](https://github.com/Geal) in https://github.com/apollographql/router/pull/1529 +### Activate defer support in introspection ([PR #1557](https://github.com/apollographql/router/pull/1557)) + +Introspection queries will now see the `@defer` directive if it was activated in the configuration file. + +By [@Geal](https://github.com/Geal) in https://github.com/apollographql/router/pull/1557 + ## 🛠 Maintenance ### Display licenses.html diff in CI if the check failed ([#1524](https://github.com/apollographql/router/issues/1524)) diff --git a/apollo-router/Cargo.toml b/apollo-router/Cargo.toml index 94b440049b..e9cb1866d6 100644 --- a/apollo-router/Cargo.toml +++ b/apollo-router/Cargo.toml @@ -119,7 +119,7 @@ reqwest = { version = "0.11.11", default-features = false, features = [ "json", "stream", ] } -router-bridge = { git = "https://github.com/apollographql/federation-rs.git", tag = "defer-alpha1" } +router-bridge = { git = "https://github.com/apollographql/federation-rs.git", tag = "defer-alpha3" } schemars = { version = "0.8.10", features = ["url"] } sha2 = "0.10.2" serde = { version = "1.0.143", features = ["derive", "rc"] } diff --git a/apollo-router/src/introspection.rs b/apollo-router/src/introspection.rs index 515a0307e9..aa25f45b19 100644 --- a/apollo-router/src/introspection.rs +++ b/apollo-router/src/introspection.rs @@ -3,31 +3,39 @@ use std::collections::HashMap; use router_bridge::introspect; use router_bridge::introspect::IntrospectionError; +use router_bridge::planner::DeferStreamSupport; +use router_bridge::planner::QueryPlannerConfig; use crate::cache::storage::CacheStorage; use crate::graphql::Response; +use crate::Configuration; const DEFAULT_INTROSPECTION_CACHE_CAPACITY: usize = 5; /// A cache containing our well known introspection queries. pub(crate) struct Introspection { cache: CacheStorage, + defer_support: bool, } impl Introspection { - pub(crate) async fn with_capacity(capacity: usize) -> Self { + pub(crate) async fn with_capacity(configuration: &Configuration, capacity: usize) -> Self { Self { cache: CacheStorage::new(capacity).await, + defer_support: configuration.server.experimental_defer_support, } } - pub(crate) async fn new() -> Self { - Self::with_capacity(DEFAULT_INTROSPECTION_CACHE_CAPACITY).await + pub(crate) async fn new(configuration: &Configuration) -> Self { + Self::with_capacity(configuration, DEFAULT_INTROSPECTION_CACHE_CAPACITY).await } #[cfg(test)] - pub(crate) async fn from_cache(cache: HashMap) -> Self { - let this = Self::with_capacity(cache.len()).await; + pub(crate) async fn from_cache( + configuration: &Configuration, + cache: HashMap, + ) -> Self { + let this = Self::with_capacity(configuration, cache.len()).await; for (query, response) in cache.into_iter() { this.cache.insert(query, response).await; @@ -46,10 +54,18 @@ impl Introspection { } // Do the introspection query and cache it - let mut response = introspect::batch_introspect(schema_sdl, vec![query.to_owned()]) - .map_err(|err| IntrospectionError { - message: format!("Deno runtime error: {:?}", err).into(), - })??; + let mut response = introspect::batch_introspect( + schema_sdl, + vec![query.to_owned()], + QueryPlannerConfig { + defer_stream_support: Some(DeferStreamSupport { + enable_defer: Some(self.defer_support), + }), + }, + ) + .map_err(|err| IntrospectionError { + message: format!("Deno runtime error: {:?}", err).into(), + })??; let introspection_result = response .pop() .ok_or_else(|| IntrospectionError { @@ -89,7 +105,7 @@ mod introspection_tests { .iter() .cloned() .collect(); - let introspection = Introspection::from_cache(cache).await; + let introspection = Introspection::from_cache(&Configuration::default(), cache).await; assert_eq!( expected_data, diff --git a/apollo-router/src/query_planner/bridge_query_planner.rs b/apollo-router/src/query_planner/bridge_query_planner.rs index af997a1fb5..df7f74f2bc 100644 --- a/apollo-router/src/query_planner/bridge_query_planner.rs +++ b/apollo-router/src/query_planner/bridge_query_planner.rs @@ -201,7 +201,9 @@ mod tests { async fn test_plan() { let planner = BridgeQueryPlanner::new( Arc::new(example_schema()), - Some(Arc::new(Introspection::new().await)), + Some(Arc::new( + Introspection::new(&Configuration::default()).await, + )), Default::default(), ) .await @@ -228,7 +230,9 @@ mod tests { async fn test_plan_invalid_query() { let planner = BridgeQueryPlanner::new( Arc::new(example_schema()), - Some(Arc::new(Introspection::new().await)), + Some(Arc::new( + Introspection::new(&Configuration::default()).await, + )), Default::default(), ) .await @@ -272,7 +276,9 @@ mod tests { async fn empty_query_plan_should_be_a_planner_error() { let err = BridgeQueryPlanner::new( Arc::new(example_schema()), - Some(Arc::new(Introspection::new().await)), + Some(Arc::new( + Introspection::new(&Configuration::default()).await, + )), Default::default(), ) .await @@ -306,7 +312,9 @@ mod tests { async fn test_plan_error() { let planner = BridgeQueryPlanner::new( Arc::new(example_schema()), - Some(Arc::new(Introspection::new().await)), + Some(Arc::new( + Introspection::new(&Configuration::default()).await, + )), Default::default(), ) .await diff --git a/apollo-router/src/services/supergraph_service.rs b/apollo-router/src/services/supergraph_service.rs index a78ee62838..26e7acd18b 100644 --- a/apollo-router/src/services/supergraph_service.rs +++ b/apollo-router/src/services/supergraph_service.rs @@ -349,7 +349,7 @@ impl PluggableSupergraphServiceBuilder { .unwrap_or(100); let introspection = if configuration.server.introspection { - Some(Arc::new(Introspection::new().await)) + Some(Arc::new(Introspection::new(&configuration).await)) } else { None };