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
14 changes: 6 additions & 8 deletions apollo-router/src/axum_factory/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ use crate::services::RouterResponse;
use crate::services::SupergraphResponse;
use crate::services::MULTIPART_DEFER_ACCEPT;
use crate::services::MULTIPART_DEFER_CONTENT_TYPE;
use crate::spec::Schema;
use crate::test_harness::http_client;
use crate::test_harness::http_client::MaybeMultipart;
use crate::uplink::license_enforcement::LicenseState;
Expand Down Expand Up @@ -2309,14 +2310,11 @@ async fn test_supergraph_timeout() {
let conf: Arc<Configuration> = Arc::new(serde_json::from_value(config).unwrap());

let schema = include_str!("..//testdata/minimal_supergraph.graphql");
let planner = BridgeQueryPlannerPool::new(
schema.to_string(),
conf.clone(),
NonZeroUsize::new(1).unwrap(),
)
.await
.unwrap();
let schema = planner.schema();
let schema = Arc::new(Schema::parse(schema, &conf).unwrap());
let planner =
BridgeQueryPlannerPool::new(schema.clone(), conf.clone(), NonZeroUsize::new(1).unwrap())
.await
.unwrap();

// we do the entire supergraph rebuilding instead of using `from_supergraph_mock_callback_and_configuration`
// because we need the plugins to apply on the supergraph
Expand Down
2 changes: 1 addition & 1 deletion apollo-router/src/orbiter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl RouterSuperServiceFactory for OrbiterRouterSuperServiceFactory {
&'a mut self,
is_telemetry_disabled: bool,
configuration: Arc<Configuration>,
schema: String,
schema: Arc<Schema>,
previous_router: Option<&'a Self::RouterFactory>,
extra_plugins: Option<Vec<(String, Box<dyn DynPlugin>)>>,
) -> Result<Self::RouterFactory, BoxError> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,9 +462,9 @@ mod tests {

async fn planned_cost(schema_str: &str, query_str: &str) -> f64 {
let config: Arc<Configuration> = Arc::new(Default::default());
let (_schema, query) = parse_schema_and_operation(schema_str, query_str, &config);
let (schema, query) = parse_schema_and_operation(schema_str, query_str, &config);

let mut planner = BridgeQueryPlanner::new(schema_str.to_string(), config.clone(), None)
let mut planner = BridgeQueryPlanner::new(schema.into(), config.clone(), None)
.await
.unwrap();

Expand Down
4 changes: 3 additions & 1 deletion apollo-router/src/plugins/include_subgraph_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ mod test {
use crate::services::HasSchema;
use crate::services::PluggableSupergraphServiceBuilder;
use crate::services::SupergraphRequest;
use crate::spec::Schema;
use crate::Configuration;

static UNREDACTED_PRODUCT_RESPONSE: Lazy<Bytes> = Lazy::new(|| {
Expand Down Expand Up @@ -191,8 +192,9 @@ mod test {

let schema =
include_str!("../../../apollo-router-benchmarks/benches/fixtures/supergraph.graphql");
let schema = Schema::parse(schema, &Default::default()).unwrap();
let planner = BridgeQueryPlannerPool::new(
schema.to_string(),
schema.into(),
Default::default(),
NonZeroUsize::new(1).unwrap(),
)
Expand Down
2 changes: 1 addition & 1 deletion apollo-router/src/plugins/record_replay/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl Plugin for Record {
enabled: init.config.enabled,
supergraph_sdl: init.supergraph_sdl.clone(),
storage_path: storage_path.clone().into(),
schema: Arc::new(Schema::parse(&init.supergraph_sdl, &Default::default())?),
schema: Arc::new(Schema::parse_arc(init.supergraph_sdl, &Default::default())?),
};

if init.config.enabled {
Expand Down
16 changes: 8 additions & 8 deletions apollo-router/src/plugins/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use crate::services::http;
use crate::services::router;
use crate::services::subgraph;
use crate::services::supergraph;
use crate::spec::Schema;
use crate::Configuration;
use crate::Notify;

Expand Down Expand Up @@ -88,25 +89,24 @@ impl<T: Plugin> PluginTestHarness<T> {
.unwrap_or(Value::Object(Default::default()));

let (supergraph_sdl, parsed_schema, subgraph_schemas) = if let Some(schema) = schema {
let planner = BridgeQueryPlanner::new(schema.to_string(), Arc::new(config), None)
let schema = Schema::parse(schema, &config).unwrap();
let sdl = schema.raw_sdl.clone();
let supergraph = schema.supergraph_schema().clone();
let planner = BridgeQueryPlanner::new(schema.into(), Arc::new(config), None)
.await
.unwrap();
(
schema.to_string(),
planner.schema().supergraph_schema().clone(),
planner.subgraph_schemas(),
)
(sdl, supergraph, planner.subgraph_schemas())
} else {
(
"".to_string(),
"".to_string().into(),
Valid::assume_valid(apollo_compiler::Schema::new()),
Default::default(),
)
};

let plugin_init = PluginInit::builder()
.config(config_for_plugin.clone())
.supergraph_sdl(Arc::new(supergraph_sdl))
.supergraph_sdl(supergraph_sdl)
.supergraph_schema(Arc::new(parsed_schema))
.subgraph_schemas(subgraph_schemas)
.notify(Notify::default())
Expand Down
5 changes: 3 additions & 2 deletions apollo-router/src/plugins/traffic_shaping/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ mod test {
use crate::services::PluggableSupergraphServiceBuilder;
use crate::services::SupergraphRequest;
use crate::services::SupergraphResponse;
use crate::spec::Schema;
use crate::Configuration;

static EXPECTED_RESPONSE: Lazy<Bytes> = Lazy::new(|| {
Expand Down Expand Up @@ -568,14 +569,14 @@ mod test {
.unwrap();

let config = Arc::new(config);
let schema = Arc::new(Schema::parse(schema, &config).unwrap());
let planner = BridgeQueryPlannerPool::new(
schema.to_string(),
schema.clone(),
config.clone(),
NonZeroUsize::new(1).unwrap(),
)
.await
.unwrap();
let schema = planner.schema();
let subgraph_schemas = planner.subgraph_schemas();

let mut builder =
Expand Down
47 changes: 23 additions & 24 deletions apollo-router/src/query_planner/bridge_query_planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,11 +323,10 @@ impl PlannerMode {

impl BridgeQueryPlanner {
pub(crate) async fn new(
schema: String,
schema: Arc<Schema>,
configuration: Arc<Configuration>,
old_planner: Option<Arc<Planner<QueryPlanResult>>>,
) -> Result<Self, ServiceBuildError> {
let schema = Schema::parse(&schema, &configuration)?;
let planner = PlannerMode::new(&schema, &configuration, old_planner).await?;

let subgraph_schemas = Arc::new(planner.subgraphs().await?);
Expand All @@ -353,7 +352,7 @@ impl BridgeQueryPlanner {

Ok(Self {
planner,
schema: Arc::new(schema),
schema,
subgraph_schemas,
introspection,
enable_authorization_directives,
Expand All @@ -369,6 +368,7 @@ impl BridgeQueryPlanner {
.clone()
}

#[cfg(test)]
pub(crate) fn schema(&self) -> Arc<Schema> {
self.schema.clone()
}
Expand Down Expand Up @@ -988,13 +988,12 @@ mod tests {
#[test(tokio::test)]
async fn federation_versions() {
async {
let _planner = BridgeQueryPlanner::new(
include_str!("../testdata/minimal_supergraph.graphql").into(),
Default::default(),
None,
)
.await
.unwrap();
let sdl = include_str!("../testdata/minimal_supergraph.graphql");
let config = Arc::default();
let schema = Schema::parse(sdl, &config).unwrap();
let _planner = BridgeQueryPlanner::new(schema.into(), config, None)
.await
.unwrap();

assert_gauge!(
"apollo.router.supergraph.federation",
Expand All @@ -1006,13 +1005,12 @@ mod tests {
.await;

async {
let _planner = BridgeQueryPlanner::new(
include_str!("../testdata/minimal_fed2_supergraph.graphql").into(),
Default::default(),
None,
)
.await
.unwrap();
let sdl = include_str!("../testdata/minimal_fed2_supergraph.graphql");
let config = Arc::default();
let schema = Schema::parse(sdl, &config).unwrap();
let _planner = BridgeQueryPlanner::new(schema.into(), config, None)
.await
.unwrap();

assert_gauge!(
"apollo.router.supergraph.federation",
Expand All @@ -1026,10 +1024,10 @@ mod tests {

#[test(tokio::test)]
async fn empty_query_plan_should_be_a_planner_error() {
let schema = Schema::parse(EXAMPLE_SCHEMA, &Default::default()).unwrap();
let schema = Arc::new(Schema::parse(EXAMPLE_SCHEMA, &Default::default()).unwrap());
let query = include_str!("testdata/unknown_introspection_query.graphql");

let planner = BridgeQueryPlanner::new(EXAMPLE_SCHEMA.to_string(), Default::default(), None)
let planner = BridgeQueryPlanner::new(schema.clone(), Default::default(), None)
.await
.unwrap();

Expand Down Expand Up @@ -1128,10 +1126,10 @@ mod tests {
configuration.supergraph.introspection = true;
let configuration = Arc::new(configuration);

let planner =
BridgeQueryPlanner::new(EXAMPLE_SCHEMA.to_string(), configuration.clone(), None)
.await
.unwrap();
let schema = Schema::parse(EXAMPLE_SCHEMA, &configuration).unwrap();
let planner = BridgeQueryPlanner::new(schema.into(), configuration.clone(), None)
.await
.unwrap();

macro_rules! s {
($query: expr) => {
Expand Down Expand Up @@ -1436,7 +1434,8 @@ mod tests {
configuration.supergraph.introspection = true;
let configuration = Arc::new(configuration);

let planner = BridgeQueryPlanner::new(schema.to_string(), configuration.clone(), None)
let schema = Schema::parse(schema, &configuration).unwrap();
let planner = BridgeQueryPlanner::new(schema.into(), configuration.clone(), None)
.await
.unwrap();

Expand Down
19 changes: 5 additions & 14 deletions apollo-router/src/query_planner/bridge_query_planner_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ pub(crate) struct BridgeQueryPlannerPool {

impl BridgeQueryPlannerPool {
pub(crate) async fn new(
sdl: String,
schema: Arc<Schema>,
configuration: Arc<Configuration>,
size: NonZeroUsize,
) -> Result<Self, ServiceBuildError> {
Self::new_from_planners(Default::default(), sdl, configuration, size).await
Self::new_from_planners(Default::default(), schema, configuration, size).await
}

pub(crate) async fn new_from_planners(
old_planners: Vec<Arc<Planner<QueryPlanResult>>>,
schema: String,
schema: Arc<Schema>,
configuration: Arc<Configuration>,
size: NonZeroUsize,
) -> Result<Self, ServiceBuildError> {
Expand All @@ -63,12 +63,12 @@ impl BridgeQueryPlannerPool {
let mut old_planners_iterator = old_planners.into_iter();

(0..size.into()).for_each(|_| {
let sdl = schema.clone();
let schema = schema.clone();
let configuration = configuration.clone();

let old_planner = old_planners_iterator.next();
join_set.spawn(async move {
BridgeQueryPlanner::new(sdl, configuration, old_planner).await
BridgeQueryPlanner::new(schema, configuration, old_planner).await
});
});

Expand All @@ -80,15 +80,6 @@ impl BridgeQueryPlannerPool {
bridge_query_planners.push(bridge_query_planner);
}

let schema = bridge_query_planners
.first()
.ok_or_else(|| {
ServiceBuildError::QueryPlannerError(QueryPlannerError::PoolProcessing(
"There should be at least 1 Query Planner service in pool".to_string(),
))
})?
.schema();

let subgraph_schemas = bridge_query_planners
.first()
.ok_or_else(|| {
Expand Down
Loading