Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions NEXT_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion apollo-router/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
36 changes: 26 additions & 10 deletions apollo-router/src/introspection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Response>,
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<String, Response>) -> Self {
let this = Self::with_capacity(cache.len()).await;
pub(crate) async fn from_cache(
configuration: &Configuration,
cache: HashMap<String, Response>,
) -> Self {
let this = Self::with_capacity(configuration, cache.len()).await;

for (query, response) in cache.into_iter() {
this.cache.insert(query, response).await;
Expand All @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down
16 changes: 12 additions & 4 deletions apollo-router/src/query_planner/bridge_query_planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion apollo-router/src/services/supergraph_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down