Skip to content

Commit

Permalink
Rename the "router" pipeline stage to "supergraph"
Browse files Browse the repository at this point in the history
Fixes #1138
  • Loading branch information
SimonSapin committed Aug 17, 2022
1 parent 7865efe commit 4807713
Show file tree
Hide file tree
Showing 57 changed files with 507 additions and 500 deletions.
6 changes: 4 additions & 2 deletions NEXT_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,16 @@ At the crate root:

In the `apollo_router::plugin::Plugin` trait:

* `router_service` → `supergraph_service`
* `query_planning_service` → `query_planner_service`

A new `apollo_router::stages` module replaces `apollo_router::services` in the public API,
reexporting its items and adding `BoxService` and `BoxCloneService` type aliases.
In pseudo-syntax:
Additionally, the "router stage" is now known as "supergraph stage".
In pseudo-syntax, `use`’ing the old names:

```rust
mod router {
mod supergraph {
use apollo_router::services::RouterRequest as Request;
use apollo_router::services::RouterResponse as Response;
type BoxService = tower::util::BoxService<Request, Response, BoxError>;
Expand Down
8 changes: 4 additions & 4 deletions apollo-router-benchmarks/src/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use apollo_router::plugin::Plugin;
use apollo_router::plugin::PluginInit;
use apollo_router::plugin::test::MockSubgraph;
use apollo_router::stages::router;
use apollo_router::stages::supergraph;
use apollo_router::stages::subgraph;
use apollo_router::TestHarness;
use apollo_router::graphql::Response;
Expand All @@ -21,14 +21,14 @@ static EXPECTED_RESPONSE: Lazy<Response> = Lazy::new(|| {
static QUERY: &str = r#"query TopProducts($first: Int) { topProducts(first: $first) { upc name reviews { id product { name } author { id name } } } }"#;

pub async fn basic_composition_benchmark(
mut router_service: router::BoxCloneService,
mut supergraph_service: supergraph::BoxCloneService,
) {
let request = router::Request::fake_builder()
let request = supergraph::Request::fake_builder()
.query(QUERY.to_string())
.variable("first", 2usize)
.build().expect("expecting valid request");

let response = router_service
let response = supergraph_service
.ready()
.await
.unwrap()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use apollo_router::plugin::Plugin;
use apollo_router::plugin::PluginInit;
use apollo_router::register_plugin;
use apollo_router::stages::router;
use apollo_router::stages::supergraph;
{{#if type_basic}}
use apollo_router::stages::execution;
use apollo_router::stages::query_planner;
Expand Down Expand Up @@ -47,10 +47,10 @@ impl Plugin for {{pascal_name}} {
}

// Delete this function if you are not customizing it.
fn router_service(
fn supergraph_service(
&self,
service: router::BoxService,
) -> router::BoxService {
service: supergraph::BoxService,
) -> supergraph::BoxService {
// Always use service builder to compose your plugins.
// It provides off the shelf building blocks for your plugin.
//
Expand Down Expand Up @@ -99,13 +99,13 @@ impl Plugin for {{pascal_name}} {
Ok({{pascal_name}} { configuration: init.config })
}

fn router_service(
fn supergraph_service(
&self,
service: router::BoxService,
) -> router::BoxService {
service: supergraph::BoxService,
) -> supergraph::BoxService {

ServiceBuilder::new()
.checkpoint_async(|request : router::Request| async {
.checkpoint_async(|request : supergraph::Request| async {
// Do some async call here to auth, and decide if to continue or not.
Ok(ControlFlow::Continue(request))
})
Expand All @@ -126,10 +126,10 @@ impl Plugin for {{pascal_name}} {
Ok({{pascal_name}} { configuration: init.config })
}

fn router_service(
fn supergraph_service(
&self,
service: router::BoxService,
) -> router::BoxService {
service: supergraph::BoxService,
) -> supergraph::BoxService {

ServiceBuilder::new()
.instrument(|_request| {
Expand All @@ -155,7 +155,7 @@ register_plugin!("{{project_name}}", "{{snake_name}}", {{pascal_name}});
#[cfg(test)]
mod tests {
use apollo_router::TestHarness;
use apollo_router::stages::router;
use apollo_router::stages::supergraph;
use tower::BoxError;
use tower::ServiceExt;

Expand All @@ -173,7 +173,7 @@ mod tests {
.build()
.await
.unwrap();
let request = router::Request::canned_builder().build().unwrap();
let request = supergraph::Request::canned_builder().build().unwrap();
let mut streamed_response = test_harness.oneshot(request).await?;

let first_response = streamed_response
Expand Down
64 changes: 32 additions & 32 deletions apollo-router/src/axum_http_server_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -776,31 +776,31 @@ mod tests {

mock! {
#[derive(Debug)]
RouterService {
SupergraphService {
fn service_call(&mut self, req: Request<graphql::Request>) -> Result<http_ext::Response<BoxStream<'static, graphql::Response>>, BoxError>;
}
}

type MockRouterServiceType = tower_test::mock::Mock<
type MockSupergraphServiceType = tower_test::mock::Mock<
http_ext::Request<graphql::Request>,
http_ext::Response<Pin<Box<dyn Stream<Item = graphql::Response> + Send>>>,
>;

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

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

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

impl RouterServiceFactory for TestRouterServiceFactory {
type RouterService = MockRouterServiceType;
type RouterService = MockSupergraphServiceType;

type Future = <<TestRouterServiceFactory as NewService<
http_ext::Request<graphql::Request>,
Expand All @@ -811,7 +811,7 @@ mod tests {
}
}

async fn init(mut mock: MockRouterService) -> (HttpServerHandle, Client) {
async fn init(mut mock: MockSupergraphService) -> (HttpServerHandle, Client) {
let server_factory = AxumHttpServerFactory::new();
let (service, mut handle) = tower_test::mock::spawn();

Expand Down Expand Up @@ -856,7 +856,7 @@ mod tests {
}

async fn init_with_config(
mut mock: MockRouterService,
mut mock: MockSupergraphService,
conf: Configuration,
plugin_handlers: HashMap<String, Handler>,
) -> (HttpServerHandle, Client) {
Expand Down Expand Up @@ -897,7 +897,7 @@ mod tests {

#[cfg(unix)]
async fn init_unix(
mut mock: MockRouterService,
mut mock: MockSupergraphService,
temp_dir: &tempfile::TempDir,
) -> HttpServerHandle {
let server_factory = AxumHttpServerFactory::new();
Expand Down Expand Up @@ -943,7 +943,7 @@ mod tests {
// let root_span = info_span!("root");
// {
// let _guard = root_span.enter();
let expectations = MockRouterService::new();
let expectations = MockSupergraphService::new();
let (server, client) = init(expectations).await;

// Regular studio redirect
Expand Down Expand Up @@ -974,7 +974,7 @@ mod tests {
.data(json!({"response": "yayyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"})) // Body must be bigger than 32 to be compressed
.build();
let example_response = expected_response.clone();
let mut expectations = MockRouterService::new();
let mut expectations = MockSupergraphService::new();
expectations
.expect_service_call()
.times(2)
Expand Down Expand Up @@ -1061,7 +1061,7 @@ mod tests {
.data(json!({"response": "yayyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"})) // Body must be bigger than 32 to be compressed
.build();
let example_response = expected_response.clone();
let mut expectations = MockRouterService::new();
let mut expectations = MockSupergraphService::new();
expectations
.expect_service_call()
.times(1)
Expand Down Expand Up @@ -1103,7 +1103,7 @@ mod tests {

#[tokio::test]
async fn malformed_request() -> Result<(), ApolloRouterError> {
let expectations = MockRouterService::new();
let expectations = MockSupergraphService::new();
let (server, client) = init(expectations).await;

let response = client
Expand All @@ -1127,7 +1127,7 @@ mod tests {
.data(json!({"response": "yay"}))
.build();
let example_response = expected_response.clone();
let mut expectations = MockRouterService::new();
let mut expectations = MockSupergraphService::new();
expectations
.expect_service_call()
.times(2)
Expand Down Expand Up @@ -1189,7 +1189,7 @@ mod tests {

#[tokio::test]
async fn bad_response() -> Result<(), ApolloRouterError> {
let expectations = MockRouterService::new();
let expectations = MockSupergraphService::new();
let (server, client) = init(expectations).await;
let url = format!("{}/test", server.listen_address());

Expand Down Expand Up @@ -1229,7 +1229,7 @@ mod tests {
.data(json!({"response": "yay"}))
.build();
let example_response = expected_response.clone();
let mut expectations = MockRouterService::new();
let mut expectations = MockSupergraphService::new();
expectations
.expect_service_call()
.times(2)
Expand Down Expand Up @@ -1298,7 +1298,7 @@ mod tests {
.data(json!({"response": "yay"}))
.build();
let example_response = expected_response.clone();
let mut expectations = MockRouterService::new();
let mut expectations = MockSupergraphService::new();
expectations
.expect_service_call()
.times(2)
Expand Down Expand Up @@ -1367,7 +1367,7 @@ mod tests {
.data(json!({"response": "yay"}))
.build();
let example_response = expected_response.clone();
let mut expectations = MockRouterService::new();
let mut expectations = MockSupergraphService::new();
expectations
.expect_service_call()
.times(4)
Expand Down Expand Up @@ -1451,7 +1451,7 @@ mod tests {
.build();
let example_response = expected_response.clone();

let mut expectations = MockRouterService::new();
let mut expectations = MockSupergraphService::new();
expectations
.expect_service_call()
.times(1)
Expand Down Expand Up @@ -1511,7 +1511,7 @@ mod tests {
.build();
let example_response = expected_response.clone();

let mut expectations = MockRouterService::new();
let mut expectations = MockSupergraphService::new();
expectations
.expect_service_call()
.times(1)
Expand Down Expand Up @@ -1554,7 +1554,7 @@ mod tests {

#[tokio::test]
async fn response_failure() -> Result<(), ApolloRouterError> {
let mut expectations = MockRouterService::new();
let mut expectations = MockSupergraphService::new();
expectations
.expect_service_call()
.times(1)
Expand Down Expand Up @@ -1602,7 +1602,7 @@ mod tests {

#[tokio::test]
async fn cors_preflight() -> Result<(), ApolloRouterError> {
let expectations = MockRouterService::new();
let expectations = MockSupergraphService::new();
let conf = Configuration::builder()
.server(
crate::configuration::Server::builder()
Expand Down Expand Up @@ -1661,7 +1661,7 @@ mod tests {
.build();
let example_response = expected_response.clone();

let mut expectations = MockRouterService::new();
let mut expectations = MockSupergraphService::new();
expectations
.expect_service_call()
.times(2)
Expand Down Expand Up @@ -1771,7 +1771,7 @@ Content-Type: application/json\r
// let root_span = info_span!("root");
// {
// let _guard = root_span.enter();
let expectations = MockRouterService::new();
let expectations = MockSupergraphService::new();
let (server, client) = init(expectations).await;
let url = format!(
"{}/.well-known/apollo/server-health",
Expand All @@ -1797,7 +1797,7 @@ Content-Type: application/json\r
.build(),
)
.build();
let expectations = MockRouterService::new();
let expectations = MockSupergraphService::new();
let (server, client) = init_with_config(expectations, conf, HashMap::new()).await;
let url = format!("{}/health", server.listen_address());

Expand All @@ -1810,7 +1810,7 @@ Content-Type: application/json\r
let query = "query";
let operation_name = "operationName";

let expectations = MockRouterService::new();
let expectations = MockSupergraphService::new();
let (server, client) = init(expectations).await;
let url = format!("{}", server.listen_address());
let response = client
Expand All @@ -1828,7 +1828,7 @@ Content-Type: application/json\r

#[test(tokio::test)]
async fn it_doesnt_display_disabled_home_page() -> Result<(), ApolloRouterError> {
let expectations = MockRouterService::new();
let expectations = MockSupergraphService::new();
let conf = Configuration::builder()
.server(
crate::configuration::Server::builder()
Expand Down Expand Up @@ -1857,7 +1857,7 @@ Content-Type: application/json\r

#[test(tokio::test)]
async fn it_answers_to_custom_endpoint() -> Result<(), ApolloRouterError> {
let expectations = MockRouterService::new();
let expectations = MockSupergraphService::new();
let plugin_handler = Handler::new(
service_fn(|req: stages::http::Request| async move {
Ok::<_, BoxError>(http_ext::Response {
Expand Down Expand Up @@ -1935,7 +1935,7 @@ Content-Type: application/json\r

#[test(tokio::test)]
async fn it_checks_the_shape_of_router_request() -> Result<(), ApolloRouterError> {
let mut expectations = MockRouterService::new();
let mut expectations = MockSupergraphService::new();
expectations
.expect_service_call()
.times(2)
Expand Down Expand Up @@ -2002,7 +2002,7 @@ Content-Type: application/json\r

#[tokio::test]
async fn cors_origin_default() -> Result<(), ApolloRouterError> {
let (server, client) = init(MockRouterService::new()).await;
let (server, client) = init(MockSupergraphService::new()).await;
let url = format!("{}/", server.listen_address());

let response =
Expand All @@ -2027,7 +2027,7 @@ Content-Type: application/json\r
)
.build();
let (server, client) =
init_with_config(MockRouterService::new(), conf, HashMap::new()).await;
init_with_config(MockSupergraphService::new(), conf, HashMap::new()).await;
let url = format!("{}/", server.listen_address());

let response =
Expand All @@ -2054,7 +2054,7 @@ Content-Type: application/json\r
)
.build();
let (server, client) =
init_with_config(MockRouterService::new(), conf, HashMap::new()).await;
init_with_config(MockSupergraphService::new(), conf, HashMap::new()).await;
let url = format!("{}/", server.listen_address());

let response = request_cors_with_origin(&client, url.as_str(), valid_origin).await;
Expand Down Expand Up @@ -2085,7 +2085,7 @@ Content-Type: application/json\r
)
.build();
let (server, client) =
init_with_config(MockRouterService::new(), conf, HashMap::new()).await;
init_with_config(MockSupergraphService::new(), conf, HashMap::new()).await;
let url = format!("{}/", server.listen_address());

// regex tests
Expand Down
Loading

0 comments on commit 4807713

Please sign in to comment.