Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename RouterService to SupergraphService in various places #1555

Merged
merged 1 commit into from
Aug 19, 2022
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
20 changes: 10 additions & 10 deletions apollo-router/src/axum_http_server_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ use crate::plugin::Handler;
use crate::plugins::traffic_shaping::Elapsed;
use crate::plugins::traffic_shaping::RateLimited;
use crate::router::ApolloRouterError;
use crate::router_factory::RouterServiceFactory;
use crate::router_factory::SupergraphServiceFactory;

/// A basic http server using Axum.
/// Uses streaming as primary method of response.
Expand All @@ -89,7 +89,7 @@ impl HttpServerFactory for AxumHttpServerFactory {
plugin_handlers: HashMap<String, Handler>,
) -> Self::Future
where
RF: RouterServiceFactory,
RF: SupergraphServiceFactory,
{
Box::pin(async move {
let (shutdown_sender, shutdown_receiver) = oneshot::channel::<()>();
Expand Down Expand Up @@ -787,22 +787,22 @@ mod tests {
>;

#[derive(Clone)]
struct TestRouterServiceFactory {
struct TestSupergraphServiceFactory {
inner: MockSupergraphServiceType,
}

impl NewService<Request<graphql::Request>> for TestRouterServiceFactory {
impl NewService<Request<graphql::Request>> for TestSupergraphServiceFactory {
type Service = MockSupergraphServiceType;

fn new_service(&self) -> Self::Service {
self.inner.clone()
}
}

impl RouterServiceFactory for TestRouterServiceFactory {
type RouterService = MockSupergraphServiceType;
impl SupergraphServiceFactory for TestSupergraphServiceFactory {
type SupergraphService = MockSupergraphServiceType;

type Future = <<TestRouterServiceFactory as NewService<
type Future = <<TestSupergraphServiceFactory as NewService<
http_ext::Request<graphql::Request>,
>>::Service as Service<http_ext::Request<graphql::Request>>>::Future;

Expand All @@ -827,7 +827,7 @@ mod tests {
});
let server = server_factory
.create(
TestRouterServiceFactory {
TestSupergraphServiceFactory {
inner: service.into_inner(),
},
Arc::new(
Expand Down Expand Up @@ -875,7 +875,7 @@ mod tests {
});
let server = server_factory
.create(
TestRouterServiceFactory {
TestSupergraphServiceFactory {
inner: service.into_inner(),
},
Arc::new(conf),
Expand Down Expand Up @@ -915,7 +915,7 @@ mod tests {
});
let server = server_factory
.create(
TestRouterServiceFactory {
TestSupergraphServiceFactory {
inner: service.into_inner(),
},
Arc::new(
Expand Down
6 changes: 3 additions & 3 deletions apollo-router/src/http_server_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use super::router::ApolloRouterError;
use crate::configuration::Configuration;
use crate::configuration::ListenAddr;
use crate::plugin::Handler;
use crate::router_factory::RouterServiceFactory;
use crate::router_factory::SupergraphServiceFactory;

/// Factory for creating the http server component.
///
Expand All @@ -27,7 +27,7 @@ pub(crate) trait HttpServerFactory {
plugin_handlers: HashMap<String, Handler>,
) -> Self::Future
where
RF: RouterServiceFactory;
RF: SupergraphServiceFactory;
}

/// A handle with with a client can shut down the server gracefully.
Expand Down Expand Up @@ -85,7 +85,7 @@ impl HttpServerHandle {
) -> Result<Self, ApolloRouterError>
where
SF: HttpServerFactory,
RF: RouterServiceFactory,
RF: SupergraphServiceFactory,
{
// we tell the currently running server to stop
if let Err(_err) = self.shutdown_sender.send(()) {
Expand Down
4 changes: 2 additions & 2 deletions apollo-router/src/plugins/expose_query_plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ mod tests {
use crate::json_ext::Object;
use crate::plugin::test::MockSubgraph;
use crate::plugin::DynPlugin;
use crate::services::PluggableRouterServiceBuilder;
use crate::services::PluggableSupergraphServiceBuilder;
use crate::Schema;

static EXPECTED_RESPONSE_WITH_QUERY_PLAN: Lazy<Response> = Lazy::new(|| {
Expand Down Expand Up @@ -170,7 +170,7 @@ mod tests {
include_str!("../../../apollo-router-benchmarks/benches/fixtures/supergraph.graphql");
let schema = Arc::new(Schema::parse(schema, &Default::default()).unwrap());

let builder = PluggableRouterServiceBuilder::new(schema.clone());
let builder = PluggableSupergraphServiceBuilder::new(schema.clone());
let builder = builder
.with_dyn_plugin("experimental.expose_query_plan".to_string(), plugin)
.with_subgraph_service("accounts", account_service.clone())
Expand Down
4 changes: 2 additions & 2 deletions apollo-router/src/plugins/include_subgraph_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ mod test {
use crate::json_ext::Object;
use crate::plugin::test::MockSubgraph;
use crate::plugin::DynPlugin;
use crate::PluggableRouterServiceBuilder;
use crate::PluggableSupergraphServiceBuilder;
use crate::Schema;
use crate::SupergraphRequest;
use crate::SupergraphResponse;
Expand Down Expand Up @@ -190,7 +190,7 @@ mod test {
include_str!("../../../apollo-router-benchmarks/benches/fixtures/supergraph.graphql");
let schema = Arc::new(Schema::parse(schema, &Default::default()).unwrap());

let builder = PluggableRouterServiceBuilder::new(schema.clone());
let builder = PluggableSupergraphServiceBuilder::new(schema.clone());
let builder = builder
.with_dyn_plugin("experimental.include_subgraph_errors".to_string(), plugin)
.with_subgraph_service("accounts", account_service.clone())
Expand Down
4 changes: 2 additions & 2 deletions apollo-router/src/plugins/traffic_shaping/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ mod test {
use crate::plugin::test::MockSubgraph;
use crate::plugin::test::MockSupergraphService;
use crate::plugin::DynPlugin;
use crate::PluggableRouterServiceBuilder;
use crate::PluggableSupergraphServiceBuilder;
use crate::Schema;
use crate::SupergraphRequest;
use crate::SupergraphResponse;
Expand Down Expand Up @@ -354,7 +354,7 @@ mod test {
);
let schema: Arc<Schema> = Arc::new(Schema::parse(schema, &Default::default()).unwrap());

let builder = PluggableRouterServiceBuilder::new(schema.clone());
let builder = PluggableSupergraphServiceBuilder::new(schema.clone());

let builder = builder
.with_dyn_plugin("apollo.traffic_shaping".to_string(), plugin)
Expand Down
4 changes: 2 additions & 2 deletions apollo-router/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use crate::axum_http_server_factory::AxumHttpServerFactory;
use crate::configuration::validate_configuration;
use crate::configuration::Configuration;
use crate::configuration::ListenAddr;
use crate::router_factory::YamlRouterServiceFactory;
use crate::router_factory::YamlSupergraphServiceFactory;
use crate::state_machine::StateMachine;

type SchemaStream = Pin<Box<dyn Stream<Item = String> + Send>>;
Expand Down Expand Up @@ -445,7 +445,7 @@ impl RouterHttpServer {
shutdown_receiver,
);
let server_factory = AxumHttpServerFactory::new();
let router_factory = YamlRouterServiceFactory::default();
let router_factory = YamlSupergraphServiceFactory::default();
let state_machine = StateMachine::new(server_factory, router_factory);
let listen_address = state_machine.listen_address.clone();
let result = spawn(
Expand Down
50 changes: 27 additions & 23 deletions apollo-router/src/router_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,21 @@ use crate::plugin::Handler;
use crate::services::new_service::NewService;
use crate::services::RouterCreator;
use crate::services::SubgraphService;
use crate::PluggableRouterServiceBuilder;
use crate::PluggableSupergraphServiceBuilder;
use crate::Schema;

/// Factory for creating a RouterService
/// Factory for creating a SupergraphService
///
/// Instances of this traits are used by the HTTP server to generate a new
/// RouterService on each request
pub(crate) trait RouterServiceFactory:
NewService<Request<graphql::Request>, Service = Self::RouterService> + Clone + Send + Sync + 'static
/// SupergraphService on each request
pub(crate) trait SupergraphServiceFactory:
NewService<Request<graphql::Request>, Service = Self::SupergraphService>
+ Clone
+ Send
+ Sync
+ 'static
{
type RouterService: Service<
type SupergraphService: Service<
Request<graphql::Request>,
Response = Response<BoxStream<'static, graphql::Response>>,
Error = BoxError,
Expand All @@ -39,42 +43,42 @@ pub(crate) trait RouterServiceFactory:
fn custom_endpoints(&self) -> HashMap<String, Handler>;
}

/// Factory for creating a RouterServiceFactory
/// Factory for creating a SupergraphServiceFactory
///
/// Instances of this traits are used by the StateMachine to generate a new
/// RouterServiceFactory from configuration when it changes
/// SupergraphServiceFactory from configuration when it changes
#[async_trait::async_trait]
pub(crate) trait RouterServiceConfigurator: Send + Sync + 'static {
type RouterServiceFactory: RouterServiceFactory;
pub(crate) trait SupergraphServiceConfigurator: Send + Sync + 'static {
type SupergraphServiceFactory: SupergraphServiceFactory;

async fn create<'a>(
&'a mut self,
configuration: Arc<Configuration>,
schema: Arc<crate::Schema>,
previous_router: Option<&'a Self::RouterServiceFactory>,
previous_router: Option<&'a Self::SupergraphServiceFactory>,
extra_plugins: Option<Vec<(String, Box<dyn DynPlugin>)>>,
) -> Result<Self::RouterServiceFactory, BoxError>;
) -> Result<Self::SupergraphServiceFactory, BoxError>;
}

/// Main implementation of the RouterService factory, supporting the extensions system
/// Main implementation of the SupergraphService factory, supporting the extensions system
#[derive(Default)]
pub(crate) struct YamlRouterServiceFactory;
pub(crate) struct YamlSupergraphServiceFactory;

#[async_trait::async_trait]
impl RouterServiceConfigurator for YamlRouterServiceFactory {
type RouterServiceFactory = RouterCreator;
impl SupergraphServiceConfigurator for YamlSupergraphServiceFactory {
type SupergraphServiceFactory = RouterCreator;

async fn create<'a>(
&'a mut self,
configuration: Arc<Configuration>,
schema: Arc<Schema>,
_previous_router: Option<&'a Self::RouterServiceFactory>,
_previous_router: Option<&'a Self::SupergraphServiceFactory>,
extra_plugins: Option<Vec<(String, Box<dyn DynPlugin>)>>,
) -> Result<Self::RouterServiceFactory, BoxError> {
) -> Result<Self::SupergraphServiceFactory, BoxError> {
// Process the plugins.
let plugins = create_plugins(&configuration, &schema, extra_plugins).await?;

let mut builder = PluggableRouterServiceBuilder::new(schema.clone());
let mut builder = PluggableSupergraphServiceBuilder::new(schema.clone());
builder = builder.with_configuration(configuration);

for (name, _) in schema.subgraphs() {
Expand Down Expand Up @@ -109,7 +113,7 @@ pub async fn create_test_service_factory_from_yaml(schema: &str, configuration:

let schema: Schema = Schema::parse(schema, &Default::default()).unwrap();

let service = YamlRouterServiceFactory::default()
let service = YamlSupergraphServiceFactory::default()
.create(Arc::new(config), Arc::new(schema), None, None)
.await;
assert_eq!(
Expand Down Expand Up @@ -285,8 +289,8 @@ mod test {
use crate::plugin::PluginInit;
use crate::register_plugin;
use crate::router_factory::inject_schema_id;
use crate::router_factory::RouterServiceConfigurator;
use crate::router_factory::YamlRouterServiceFactory;
use crate::router_factory::SupergraphServiceConfigurator;
use crate::router_factory::YamlSupergraphServiceFactory;
use crate::Schema;

#[derive(Debug)]
Expand Down Expand Up @@ -402,7 +406,7 @@ mod test {
let schema = include_str!("testdata/supergraph.graphql");
let schema = Schema::parse(schema, &config).unwrap();

let service = YamlRouterServiceFactory::default()
let service = YamlSupergraphServiceFactory::default()
.create(Arc::new(config), Arc::new(schema), None, None)
.await;
service.map(|_| ())
Expand Down
Loading