From a2c1a1e7a6cdded87b726f04ea30b12cc3c10cec Mon Sep 17 00:00:00 2001 From: bryn Date: Wed, 9 Mar 2022 18:24:24 +0100 Subject: [PATCH] Completely remove subgraph section of yaml. --- Cargo.lock | 1 + apollo-router/Cargo.toml | 1 + apollo-router/src/configuration/mod.rs | 48 +----------- ...e_configuration_api_does_not_change-2.snap | 4 +- ...e_configuration_api_does_not_change-3.snap | 4 +- ...e_configuration_api_does_not_change-4.snap | 4 +- ...ure_configuration_api_does_not_change.snap | 4 +- ...figuration_api_does_not_change_grpc-2.snap | 4 +- ...onfiguration_api_does_not_change_grpc.snap | 4 +- ...figuration_api_does_not_change_http-2.snap | 3 - ...onfiguration_api_does_not_change_http.snap | 3 - ...ration_api_does_not_change_tls_config.snap | 4 +- ...nfiguration__tests__schema_generation.snap | 75 +++++++++++++++---- ...ation__tests__supergraph_config_serde.snap | 7 +- .../configuration/testdata/config_basic.yml | 3 - .../configuration/testdata/config_full.yml | 3 - .../config_opentelemetry_jaeger_basic.yml | 3 - .../config_opentelemetry_jaeger_full.yml | 3 - ..._opentelemetry_otlp_tracing_grpc_basic.yml | 3 - ...opentelemetry_otlp_tracing_grpc_common.yml | 3 - ...g_opentelemetry_otlp_tracing_grpc_full.yml | 3 - ...ig_opentelemetry_otlp_tracing_grpc_tls.yml | 3 - ..._opentelemetry_otlp_tracing_http_basic.yml | 3 - ...opentelemetry_otlp_tracing_http_common.yml | 3 - ...g_opentelemetry_otlp_tracing_http_full.yml | 3 - .../configuration/testdata/invalid_url.yaml | 3 - .../testdata/supergraph_config.yaml | 9 --- apollo-router/src/router_factory.rs | 29 +------ apollo-router/src/state_machine.rs | 52 ++----------- apollo-router/src/warp_http_server_factory.rs | 2 - .../tests/fixtures/supergraph_config.yaml | 20 ----- apollo-router/tests/integration_tests.rs | 16 ++-- 32 files changed, 91 insertions(+), 239 deletions(-) delete mode 100644 apollo-router/tests/fixtures/supergraph_config.yaml diff --git a/Cargo.lock b/Cargo.lock index f608b0a8fb..e8cb5b6453 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -133,6 +133,7 @@ dependencies = [ "http", "hyper", "insta", + "itertools", "libc", "maplit", "mockall", diff --git a/apollo-router/Cargo.toml b/apollo-router/Cargo.toml index 1e1f2295e2..9c17ee03d6 100644 --- a/apollo-router/Cargo.toml +++ b/apollo-router/Cargo.toml @@ -39,6 +39,7 @@ futures = { version = "0.3.21", features = ["thread-pool"] } hotwatch = "0.4.6" http = "0.2.6" hyper = { version = "0.14.17", features = ["server"] } +itertools = "0.10.3" once_cell = "1.9.0" opentelemetry = { version = "0.17.0", features = ["rt-tokio", "serialize"] } opentelemetry-jaeger = { version = "0.16.0", features = [ diff --git a/apollo-router/src/configuration/mod.rs b/apollo-router/src/configuration/mod.rs index 431aee3fc3..238245c719 100644 --- a/apollo-router/src/configuration/mod.rs +++ b/apollo-router/src/configuration/mod.rs @@ -1,16 +1,15 @@ //! Logic for loading configuration in to an object model use apollo_router_core::plugins; -use apollo_router_core::prelude::*; use derivative::Derivative; use displaydoc::Display; +use itertools::Itertools; use schemars::gen::SchemaGenerator; use schemars::schema::{ObjectValidation, Schema, SchemaObject, SubschemaValidation}; use schemars::{JsonSchema, Set}; use serde::{Deserialize, Serialize}; use serde_json::Map; use serde_json::Value; -use std::collections::HashMap; use std::fmt; use std::net::SocketAddr; use std::path::PathBuf; @@ -60,11 +59,6 @@ pub struct Configuration { #[builder(default)] pub server: Server, - /// Mapping of name to subgraph that the router may contact. - #[serde(default)] - #[builder(default)] - pub subgraphs: HashMap, - /// Plugin configuration #[serde(default)] #[builder(default)] @@ -76,13 +70,6 @@ fn default_listen() -> ListenAddr { } impl Configuration { - pub fn load_subgraphs(&self, schema: &graphql::Schema) -> HashMap { - schema - .subgraphs() - .map(|(name, _subgraph_url)| (name.to_owned(), SubgraphConf {})) - .collect() - } - pub fn boxed(self) -> Box { Box::new(self) } @@ -115,6 +102,7 @@ impl JsonSchema for Plugins { let plugins = plugins() .iter() + .sorted_by_key(|(name, _)| *name) .map(|(name, factory)| (name.to_string(), factory.create_schema(gen))) .collect::>(); let plugins_refs = plugins @@ -146,23 +134,6 @@ impl JsonSchema for Plugins { } } -/// Configuration for a subgraph. -#[derive(Debug, Clone, Deserialize, Serialize, TypedBuilder)] -pub struct SubgraphConf {} - -impl JsonSchema for SubgraphConf { - fn schema_name() -> String { - stringify!(Subgraph).to_string() - } - - fn json_schema(_gen: &mut SchemaGenerator) -> Schema { - // This is a manual implementation of Subgraph schema to allow layers that have been registered at - // compile time to be picked up. - let subgraph = SchemaObject::default(); - Schema::Object(subgraph) - } -} - /// Configuration options pertaining to the http server component. #[derive(Debug, Clone, Deserialize, Serialize, TypedBuilder, JsonSchema)] #[serde(deny_unknown_fields)] @@ -358,10 +329,12 @@ impl TlsConfig { #[cfg(test)] mod tests { use super::*; + use apollo_router_core::prelude::*; use apollo_router_core::SchemaError; use insta::assert_json_snapshot; use reqwest::Url; use schemars::gen::SchemaSettings; + use std::collections::HashMap; macro_rules! assert_config_snapshot { ($file:expr) => {{ @@ -438,18 +411,6 @@ mod tests { #[test] fn routing_url_in_schema() { - let configuration = Configuration::builder() - .subgraphs( - [ - ("inventory".to_string(), SubgraphConf {}), - ("products".to_string(), SubgraphConf {}), - ] - .iter() - .cloned() - .collect(), - ) - .build(); - let schema: graphql::Schema = r#" schema @core(feature: "https://specs.apollo.dev/core/v0.1"), @@ -474,7 +435,6 @@ mod tests { .parse() .unwrap(); - let _subgraphs = configuration.load_subgraphs(&schema); let subgraphs: HashMap<&String, &Url> = schema.subgraphs().collect(); // if no configuration override, use the URL from the supergraph diff --git a/apollo-router/src/configuration/snapshots/apollo_router__configuration__tests__ensure_configuration_api_does_not_change-2.snap b/apollo-router/src/configuration/snapshots/apollo_router__configuration__tests__ensure_configuration_api_does_not_change-2.snap index 0b0bf0382b..1489039465 100644 --- a/apollo-router/src/configuration/snapshots/apollo_router__configuration__tests__ensure_configuration_api_does_not_change-2.snap +++ b/apollo-router/src/configuration/snapshots/apollo_router__configuration__tests__ensure_configuration_api_does_not_change-2.snap @@ -1,6 +1,6 @@ --- source: apollo-router/src/configuration/mod.rs -assertion_line: 395 +assertion_line: 366 expression: config --- @@ -19,7 +19,5 @@ server: methods: - foo - bar -subgraphs: - example: {} plugins: {} diff --git a/apollo-router/src/configuration/snapshots/apollo_router__configuration__tests__ensure_configuration_api_does_not_change-3.snap b/apollo-router/src/configuration/snapshots/apollo_router__configuration__tests__ensure_configuration_api_does_not_change-3.snap index 8e0eed93a0..6ee66f3916 100644 --- a/apollo-router/src/configuration/snapshots/apollo_router__configuration__tests__ensure_configuration_api_does_not_change-3.snap +++ b/apollo-router/src/configuration/snapshots/apollo_router__configuration__tests__ensure_configuration_api_does_not_change-3.snap @@ -1,13 +1,11 @@ --- source: apollo-router/src/configuration/mod.rs -assertion_line: 396 +assertion_line: 367 expression: config --- server: listen: "1.2.3.4:5" cors: ~ -subgraphs: - example: {} plugins: {} diff --git a/apollo-router/src/configuration/snapshots/apollo_router__configuration__tests__ensure_configuration_api_does_not_change-4.snap b/apollo-router/src/configuration/snapshots/apollo_router__configuration__tests__ensure_configuration_api_does_not_change-4.snap index 8be9cef93f..5437947464 100644 --- a/apollo-router/src/configuration/snapshots/apollo_router__configuration__tests__ensure_configuration_api_does_not_change-4.snap +++ b/apollo-router/src/configuration/snapshots/apollo_router__configuration__tests__ensure_configuration_api_does_not_change-4.snap @@ -1,13 +1,11 @@ --- source: apollo-router/src/configuration/mod.rs -assertion_line: 397 +assertion_line: 368 expression: config --- server: listen: "1.2.3.4:5" cors: ~ -subgraphs: - example: {} plugins: {} diff --git a/apollo-router/src/configuration/snapshots/apollo_router__configuration__tests__ensure_configuration_api_does_not_change.snap b/apollo-router/src/configuration/snapshots/apollo_router__configuration__tests__ensure_configuration_api_does_not_change.snap index 341a562c3f..9502d4cff3 100644 --- a/apollo-router/src/configuration/snapshots/apollo_router__configuration__tests__ensure_configuration_api_does_not_change.snap +++ b/apollo-router/src/configuration/snapshots/apollo_router__configuration__tests__ensure_configuration_api_does_not_change.snap @@ -1,13 +1,11 @@ --- source: apollo-router/src/configuration/mod.rs -assertion_line: 394 +assertion_line: 365 expression: config --- server: listen: "1.2.3.4:5" cors: ~ -subgraphs: - example: {} plugins: {} diff --git a/apollo-router/src/configuration/snapshots/apollo_router__configuration__tests__ensure_configuration_api_does_not_change_grpc-2.snap b/apollo-router/src/configuration/snapshots/apollo_router__configuration__tests__ensure_configuration_api_does_not_change_grpc-2.snap index 2bd3024213..012ee2d01c 100644 --- a/apollo-router/src/configuration/snapshots/apollo_router__configuration__tests__ensure_configuration_api_does_not_change_grpc-2.snap +++ b/apollo-router/src/configuration/snapshots/apollo_router__configuration__tests__ensure_configuration_api_does_not_change_grpc-2.snap @@ -1,13 +1,11 @@ --- source: apollo-router/src/configuration/mod.rs -assertion_line: 423 +assertion_line: 394 expression: config --- server: listen: "1.2.3.4:5" cors: ~ -subgraphs: - example: {} plugins: {} diff --git a/apollo-router/src/configuration/snapshots/apollo_router__configuration__tests__ensure_configuration_api_does_not_change_grpc.snap b/apollo-router/src/configuration/snapshots/apollo_router__configuration__tests__ensure_configuration_api_does_not_change_grpc.snap index 6ef80b043d..9081611e42 100644 --- a/apollo-router/src/configuration/snapshots/apollo_router__configuration__tests__ensure_configuration_api_does_not_change_grpc.snap +++ b/apollo-router/src/configuration/snapshots/apollo_router__configuration__tests__ensure_configuration_api_does_not_change_grpc.snap @@ -1,13 +1,11 @@ --- source: apollo-router/src/configuration/mod.rs -assertion_line: 422 +assertion_line: 393 expression: config --- server: listen: "1.2.3.4:5" cors: ~ -subgraphs: - example: {} plugins: {} diff --git a/apollo-router/src/configuration/snapshots/apollo_router__configuration__tests__ensure_configuration_api_does_not_change_http-2.snap b/apollo-router/src/configuration/snapshots/apollo_router__configuration__tests__ensure_configuration_api_does_not_change_http-2.snap index db1a719cee..7810082a7b 100644 --- a/apollo-router/src/configuration/snapshots/apollo_router__configuration__tests__ensure_configuration_api_does_not_change_http-2.snap +++ b/apollo-router/src/configuration/snapshots/apollo_router__configuration__tests__ensure_configuration_api_does_not_change_http-2.snap @@ -7,8 +7,5 @@ expression: config server: listen: "1.2.3.4:5" cors: ~ -subgraphs: - example: - layers: [] plugins: {} diff --git a/apollo-router/src/configuration/snapshots/apollo_router__configuration__tests__ensure_configuration_api_does_not_change_http.snap b/apollo-router/src/configuration/snapshots/apollo_router__configuration__tests__ensure_configuration_api_does_not_change_http.snap index bd9fbcb647..ba6c53fc08 100644 --- a/apollo-router/src/configuration/snapshots/apollo_router__configuration__tests__ensure_configuration_api_does_not_change_http.snap +++ b/apollo-router/src/configuration/snapshots/apollo_router__configuration__tests__ensure_configuration_api_does_not_change_http.snap @@ -7,8 +7,5 @@ expression: config server: listen: "1.2.3.4:5" cors: ~ -subgraphs: - example: - layers: [] plugins: {} diff --git a/apollo-router/src/configuration/snapshots/apollo_router__configuration__tests__ensure_configuration_api_does_not_change_tls_config.snap b/apollo-router/src/configuration/snapshots/apollo_router__configuration__tests__ensure_configuration_api_does_not_change_tls_config.snap index 2490ef886a..28f12751d4 100644 --- a/apollo-router/src/configuration/snapshots/apollo_router__configuration__tests__ensure_configuration_api_does_not_change_tls_config.snap +++ b/apollo-router/src/configuration/snapshots/apollo_router__configuration__tests__ensure_configuration_api_does_not_change_tls_config.snap @@ -1,13 +1,11 @@ --- source: apollo-router/src/configuration/mod.rs -assertion_line: 436 +assertion_line: 407 expression: config --- server: listen: "1.2.3.4:5" cors: ~ -subgraphs: - example: {} plugins: {} diff --git a/apollo-router/src/configuration/snapshots/apollo_router__configuration__tests__schema_generation.snap b/apollo-router/src/configuration/snapshots/apollo_router__configuration__tests__schema_generation.snap index 5c590dfe8a..5d2fb51906 100644 --- a/apollo-router/src/configuration/snapshots/apollo_router__configuration__tests__schema_generation.snap +++ b/apollo-router/src/configuration/snapshots/apollo_router__configuration__tests__schema_generation.snap @@ -1,6 +1,6 @@ --- source: apollo-router/src/configuration/mod.rs -assertion_line: 384 +assertion_line: 355 expression: "&schema" --- @@ -22,26 +22,28 @@ expression: "&schema" "cors": null }, "$ref": "#/definitions/Server" - }, - "subgraphs": { - "description": "Mapping of name to subgraph that the router may contact.", - "default": {}, - "type": "object", - "additionalProperties": { - "$ref": "#/definitions/Subgraph" - } } }, "additionalProperties": false, "definitions": { "Conf": { "type": "object", - "required": [ - "name" - ], "properties": { - "name": { - "type": "string" + "graph": { + "$ref": "#/definitions/StudioGraph", + "nullable": true + }, + "opentelemetry": { + "$ref": "#/definitions/OpenTelemetry", + "nullable": true + }, + "opentracing": { + "$ref": "#/definitions/OpenTracingConfig", + "nullable": true + }, + "spaceport": { + "$ref": "#/definitions/SpaceportConfig", + "nullable": true } } }, @@ -153,6 +155,20 @@ expression: "&schema" } ] }, + "OpenTelemetry": { + "$ref": "#/definitions/OpenTelemetry" + }, + "OpenTracingConfig": { + "type": "object", + "required": [ + "format" + ], + "properties": { + "format": { + "$ref": "#/definitions/PropagationFormat" + } + } + }, "Operation": { "oneOf": [ { @@ -305,6 +321,13 @@ expression: "&schema" } ] }, + "PropagationFormat": { + "type": "string", + "enum": [ + "jaeger", + "zipkin_b3" + ] + }, "Remove": { "oneOf": [ { @@ -351,6 +374,28 @@ expression: "&schema" }, "additionalProperties": false }, - "Subgraph": {} + "SpaceportConfig": { + "type": "object", + "required": [ + "external" + ], + "properties": { + "collector": { + "default": "https://127.0.0.1:50051", + "type": "string" + }, + "external": { + "type": "boolean" + }, + "listener": { + "default": "127.0.0.1:50051", + "type": "string" + } + }, + "additionalProperties": false + }, + "StudioGraph": { + "type": "object" + } } } diff --git a/apollo-router/src/configuration/snapshots/apollo_router__configuration__tests__supergraph_config_serde.snap b/apollo-router/src/configuration/snapshots/apollo_router__configuration__tests__supergraph_config_serde.snap index 0e72b0b5d0..badd3572b5 100644 --- a/apollo-router/src/configuration/snapshots/apollo_router__configuration__tests__supergraph_config_serde.snap +++ b/apollo-router/src/configuration/snapshots/apollo_router__configuration__tests__supergraph_config_serde.snap @@ -1,6 +1,6 @@ --- source: apollo-router/src/configuration/mod.rs -assertion_line: 389 +assertion_line: 360 expression: config --- @@ -17,10 +17,5 @@ server: methods: - GET - PUT -subgraphs: - accounts: {} - inventory: {} - products: {} - reviews: {} plugins: {} diff --git a/apollo-router/src/configuration/testdata/config_basic.yml b/apollo-router/src/configuration/testdata/config_basic.yml index d94abe263a..d1b76d4ced 100644 --- a/apollo-router/src/configuration/testdata/config_basic.yml +++ b/apollo-router/src/configuration/testdata/config_basic.yml @@ -1,5 +1,2 @@ server: listen: 1.2.3.4:5 -subgraphs: - example: - routing_url: http://foo diff --git a/apollo-router/src/configuration/testdata/config_full.yml b/apollo-router/src/configuration/testdata/config_full.yml index 2f964a3150..56b75532be 100644 --- a/apollo-router/src/configuration/testdata/config_full.yml +++ b/apollo-router/src/configuration/testdata/config_full.yml @@ -3,6 +3,3 @@ server: cors: origins: [foo, bar, baz] methods: [foo, bar] -subgraphs: - example: - routing_url: http://foo diff --git a/apollo-router/src/configuration/testdata/config_opentelemetry_jaeger_basic.yml b/apollo-router/src/configuration/testdata/config_opentelemetry_jaeger_basic.yml index d94abe263a..d1b76d4ced 100644 --- a/apollo-router/src/configuration/testdata/config_opentelemetry_jaeger_basic.yml +++ b/apollo-router/src/configuration/testdata/config_opentelemetry_jaeger_basic.yml @@ -1,5 +1,2 @@ server: listen: 1.2.3.4:5 -subgraphs: - example: - routing_url: http://foo diff --git a/apollo-router/src/configuration/testdata/config_opentelemetry_jaeger_full.yml b/apollo-router/src/configuration/testdata/config_opentelemetry_jaeger_full.yml index d94abe263a..d1b76d4ced 100644 --- a/apollo-router/src/configuration/testdata/config_opentelemetry_jaeger_full.yml +++ b/apollo-router/src/configuration/testdata/config_opentelemetry_jaeger_full.yml @@ -1,5 +1,2 @@ server: listen: 1.2.3.4:5 -subgraphs: - example: - routing_url: http://foo diff --git a/apollo-router/src/configuration/testdata/config_opentelemetry_otlp_tracing_grpc_basic.yml b/apollo-router/src/configuration/testdata/config_opentelemetry_otlp_tracing_grpc_basic.yml index d94abe263a..d1b76d4ced 100644 --- a/apollo-router/src/configuration/testdata/config_opentelemetry_otlp_tracing_grpc_basic.yml +++ b/apollo-router/src/configuration/testdata/config_opentelemetry_otlp_tracing_grpc_basic.yml @@ -1,5 +1,2 @@ server: listen: 1.2.3.4:5 -subgraphs: - example: - routing_url: http://foo diff --git a/apollo-router/src/configuration/testdata/config_opentelemetry_otlp_tracing_grpc_common.yml b/apollo-router/src/configuration/testdata/config_opentelemetry_otlp_tracing_grpc_common.yml index d94abe263a..d1b76d4ced 100644 --- a/apollo-router/src/configuration/testdata/config_opentelemetry_otlp_tracing_grpc_common.yml +++ b/apollo-router/src/configuration/testdata/config_opentelemetry_otlp_tracing_grpc_common.yml @@ -1,5 +1,2 @@ server: listen: 1.2.3.4:5 -subgraphs: - example: - routing_url: http://foo diff --git a/apollo-router/src/configuration/testdata/config_opentelemetry_otlp_tracing_grpc_full.yml b/apollo-router/src/configuration/testdata/config_opentelemetry_otlp_tracing_grpc_full.yml index d94abe263a..d1b76d4ced 100644 --- a/apollo-router/src/configuration/testdata/config_opentelemetry_otlp_tracing_grpc_full.yml +++ b/apollo-router/src/configuration/testdata/config_opentelemetry_otlp_tracing_grpc_full.yml @@ -1,5 +1,2 @@ server: listen: 1.2.3.4:5 -subgraphs: - example: - routing_url: http://foo diff --git a/apollo-router/src/configuration/testdata/config_opentelemetry_otlp_tracing_grpc_tls.yml b/apollo-router/src/configuration/testdata/config_opentelemetry_otlp_tracing_grpc_tls.yml index d94abe263a..d1b76d4ced 100644 --- a/apollo-router/src/configuration/testdata/config_opentelemetry_otlp_tracing_grpc_tls.yml +++ b/apollo-router/src/configuration/testdata/config_opentelemetry_otlp_tracing_grpc_tls.yml @@ -1,5 +1,2 @@ server: listen: 1.2.3.4:5 -subgraphs: - example: - routing_url: http://foo diff --git a/apollo-router/src/configuration/testdata/config_opentelemetry_otlp_tracing_http_basic.yml b/apollo-router/src/configuration/testdata/config_opentelemetry_otlp_tracing_http_basic.yml index d94abe263a..d1b76d4ced 100644 --- a/apollo-router/src/configuration/testdata/config_opentelemetry_otlp_tracing_http_basic.yml +++ b/apollo-router/src/configuration/testdata/config_opentelemetry_otlp_tracing_http_basic.yml @@ -1,5 +1,2 @@ server: listen: 1.2.3.4:5 -subgraphs: - example: - routing_url: http://foo diff --git a/apollo-router/src/configuration/testdata/config_opentelemetry_otlp_tracing_http_common.yml b/apollo-router/src/configuration/testdata/config_opentelemetry_otlp_tracing_http_common.yml index d94abe263a..d1b76d4ced 100644 --- a/apollo-router/src/configuration/testdata/config_opentelemetry_otlp_tracing_http_common.yml +++ b/apollo-router/src/configuration/testdata/config_opentelemetry_otlp_tracing_http_common.yml @@ -1,5 +1,2 @@ server: listen: 1.2.3.4:5 -subgraphs: - example: - routing_url: http://foo diff --git a/apollo-router/src/configuration/testdata/config_opentelemetry_otlp_tracing_http_full.yml b/apollo-router/src/configuration/testdata/config_opentelemetry_otlp_tracing_http_full.yml index d94abe263a..d1b76d4ced 100644 --- a/apollo-router/src/configuration/testdata/config_opentelemetry_otlp_tracing_http_full.yml +++ b/apollo-router/src/configuration/testdata/config_opentelemetry_otlp_tracing_http_full.yml @@ -1,5 +1,2 @@ server: listen: 1.2.3.4:5 -subgraphs: - example: - routing_url: http://foo diff --git a/apollo-router/src/configuration/testdata/invalid_url.yaml b/apollo-router/src/configuration/testdata/invalid_url.yaml index 133b9b2c5e..6870d47adc 100644 --- a/apollo-router/src/configuration/testdata/invalid_url.yaml +++ b/apollo-router/src/configuration/testdata/invalid_url.yaml @@ -1,5 +1,2 @@ server: listen: 127.0.0.1:0 -subgraphs: - accounts: - routing_url: abcd \ No newline at end of file diff --git a/apollo-router/src/configuration/testdata/supergraph_config.yaml b/apollo-router/src/configuration/testdata/supergraph_config.yaml index fbed665d8c..42149611ff 100644 --- a/apollo-router/src/configuration/testdata/supergraph_config.yaml +++ b/apollo-router/src/configuration/testdata/supergraph_config.yaml @@ -6,12 +6,3 @@ server: methods: - GET - PUT -subgraphs: - accounts: - routing_url: http://localhost:4001/graphql - reviews: - routing_url: http://localhost:4002/graphql - products: - routing_url: http://localhost:4003/graphql - inventory: - routing_url: http://localhost:4004/graphql diff --git a/apollo-router/src/router_factory.rs b/apollo-router/src/router_factory.rs index 3d07be8667..f69053f40f 100644 --- a/apollo-router/src/router_factory.rs +++ b/apollo-router/src/router_factory.rs @@ -1,11 +1,11 @@ use crate::configuration::{Configuration, ConfigurationError}; use apollo_router_core::deduplication::QueryDeduplicationLayer; -use apollo_router_core::DynPlugin; use apollo_router_core::{ http_compat::{Request, Response}, - PluggableRouterServiceBuilder, ReqwestSubgraphService, ResponseBody, RouterRequest, Schema, + PluggableRouterServiceBuilder, ResponseBody, RouterRequest, Schema, }; use apollo_router_core::{prelude::*, Context}; +use apollo_router_core::{DynPlugin, ReqwestSubgraphService}; use std::sync::Arc; use tower::buffer::Buffer; use tower::util::{BoxCloneService, BoxService}; @@ -73,13 +73,12 @@ impl RouterServiceFactory for YamlRouterServiceFactory { ) -> Result { let mut errors: Vec = Vec::default(); let configuration = (*configuration).clone(); - let subgraphs = configuration.load_subgraphs(&schema); let configuration = add_default_plugins(configuration); - let mut builder = PluggableRouterServiceBuilder::new(schema); + let mut builder = PluggableRouterServiceBuilder::new(schema.clone()); - for name in subgraphs.keys() { + for (name, _) in schema.subgraphs() { let dedup_layer = QueryDeduplicationLayer; let subgraph_service = BoxService::new(dedup_layer.layer(ReqwestSubgraphService::new(name.to_string()))); @@ -387,26 +386,6 @@ mod test { assert!(service.is_ok()) } - #[tokio::test] - #[test_log::test] - async fn test_yaml_layers() { - let config: Configuration = serde_yaml::from_str( - r#" - subgraphs: - foo: - routing_url: https://foo - layers: - - headers_insert: - name: "foo" - value: "foo" - - "#, - ) - .unwrap(); - let service = create_service(config).await; - assert!(service.is_ok()) - } - #[tokio::test] async fn test_yaml_plugins_always_starts_and_stops() { let config: Configuration = serde_yaml::from_str( diff --git a/apollo-router/src/state_machine.rs b/apollo-router/src/state_machine.rs index 400f498c54..c8989eeb8e 100644 --- a/apollo-router/src/state_machine.rs +++ b/apollo-router/src/state_machine.rs @@ -343,7 +343,6 @@ impl ResultExt for Result { #[cfg(test)] mod tests { use super::*; - use crate::configuration::SubgraphConf; use crate::http_server_factory::Listener; use crate::router_factory::RouterServiceFactory; use apollo_router_core::http_compat::{Request, Response}; @@ -421,12 +420,7 @@ mod tests { server_factory, router_factory, vec![ - UpdateConfiguration( - Configuration::builder() - .subgraphs(Default::default()) - .build() - .boxed() - ), + UpdateConfiguration(Configuration::builder().build().boxed()), UpdateSchema(Box::new(example_schema())), Shutdown ], @@ -458,12 +452,7 @@ mod tests { server_factory, router_factory, vec![ - UpdateConfiguration( - Configuration::builder() - .subgraphs(Default::default()) - .build() - .boxed() - ), + UpdateConfiguration(Configuration::builder().build().boxed()), UpdateSchema(Box::new(minimal_schema.parse().unwrap())), UpdateSchema(Box::new(example_schema())), Shutdown @@ -497,12 +486,7 @@ mod tests { server_factory, router_factory, vec![ - UpdateConfiguration( - Configuration::builder() - .subgraphs(Default::default()) - .build() - .boxed() - ), + UpdateConfiguration(Configuration::builder().build().boxed()), UpdateSchema(Box::new(example_schema())), UpdateConfiguration( Configuration::builder() @@ -511,7 +495,6 @@ mod tests { .listen(SocketAddr::from_str("127.0.0.1:4001").unwrap()) .build() ) - .subgraphs(Default::default()) .build() .boxed() ), @@ -546,20 +529,7 @@ mod tests { server_factory, router_factory, vec![ - UpdateConfiguration( - Configuration::builder() - .subgraphs( - [ - ("accounts".to_string(), SubgraphConf {}), - ("products".to_string(), SubgraphConf {}) - ] - .iter() - .cloned() - .collect() - ) - .build() - .boxed() - ), + UpdateConfiguration(Configuration::builder().build().boxed()), UpdateSchema(Box::new(example_schema())), Shutdown ], @@ -592,12 +562,7 @@ mod tests { server_factory, router_factory, vec![ - UpdateConfiguration( - Configuration::builder() - .subgraphs(Default::default()) - .build() - .boxed() - ), + UpdateConfiguration(Configuration::builder().build().boxed()), UpdateSchema(Box::new(example_schema())), ], vec![State::Startup, State::Errored,] @@ -633,12 +598,7 @@ mod tests { server_factory, router_factory, vec![ - UpdateConfiguration( - Configuration::builder() - .subgraphs(Default::default()) - .build() - .boxed() - ), + UpdateConfiguration(Configuration::builder().build().boxed()), UpdateSchema(Box::new(example_schema())), UpdateSchema(Box::new(example_schema())), Shutdown diff --git a/apollo-router/src/warp_http_server_factory.rs b/apollo-router/src/warp_http_server_factory.rs index 7856dbaa47..2bc3dcab9b 100644 --- a/apollo-router/src/warp_http_server_factory.rs +++ b/apollo-router/src/warp_http_server_factory.rs @@ -603,7 +603,6 @@ mod tests { )) .build(), ) - .subgraphs(Default::default()) .build(), ), None, @@ -650,7 +649,6 @@ mod tests { )) .build(), ) - .subgraphs(Default::default()) .build(), ), None, diff --git a/apollo-router/tests/fixtures/supergraph_config.yaml b/apollo-router/tests/fixtures/supergraph_config.yaml deleted file mode 100644 index e50195460c..0000000000 --- a/apollo-router/tests/fixtures/supergraph_config.yaml +++ /dev/null @@ -1,20 +0,0 @@ -plugins: - override_subgraph_url: - accounts: http://localhost:4001/graphql - reviews: http://localhost:4002/graphql - products: http://localhost:4003/graphql - inventory: http://localhost:4004/graphql - -subgraphs: - accounts: - schema: - file: ./accounts.graphql - reviews: - schema: - file: ./reviews.graphql - products: - schema: - file: ./products.graphql - inventory: - schema: - file: ./inventory.graphql diff --git a/apollo-router/tests/integration_tests.rs b/apollo-router/tests/integration_tests.rs index 75a8b7e2b2..d53c5a92b9 100644 --- a/apollo-router/tests/integration_tests.rs +++ b/apollo-router/tests/integration_tests.rs @@ -1,7 +1,7 @@ -use apollo_router::configuration::Configuration; use apollo_router_core::{ http_compat, prelude::*, Context, Object, PluggableRouterServiceBuilder, - ReqwestSubgraphService, ResponseBody, RouterRequest, RouterResponse, SubgraphRequest, ValueExt, + ReqwestSubgraphService, ResponseBody, RouterRequest, RouterResponse, Schema, SubgraphRequest, + ValueExt, }; use http::Method; use maplit::hashmap; @@ -468,14 +468,12 @@ async fn setup_router_and_registry() -> ( BoxCloneService, CountingServiceRegistry, ) { - let schema = Arc::new(include_str!("fixtures/supergraph.graphql").parse().unwrap()); - let config = - serde_yaml::from_str::(include_str!("fixtures/supergraph_config.yaml")) - .unwrap(); + let schema: Arc = + Arc::new(include_str!("fixtures/supergraph.graphql").parse().unwrap()); let counting_registry = CountingServiceRegistry::new(); - let subgraphs = config.load_subgraphs(&schema); - let mut builder = PluggableRouterServiceBuilder::new(schema); - for name in subgraphs.keys() { + let subgraphs = schema.subgraphs(); + let mut builder = PluggableRouterServiceBuilder::new(schema.clone()); + for (name, _url) in subgraphs { let cloned_counter = counting_registry.clone(); let cloned_name = name.clone();