diff --git a/NEXT_CHANGELOG.md b/NEXT_CHANGELOG.md index ed65d5dde5..e9044ffd78 100644 --- a/NEXT_CHANGELOG.md +++ b/NEXT_CHANGELOG.md @@ -262,11 +262,15 @@ Migration tips: By [@bryncooke](https://github.com/bryncooke) in https://github.com/apollographql/router/pull/1227 https://github.com/apollographql/router/pull/1234 https://github.com/apollographql/router/pull/1239 https://github.com/apollographql/router/pull/1263 -### Non-GraphQL response body variants removed from `RouterResponse` ([PR #1307](https://github.com/apollographql/router/pull/1307)) +### Non-GraphQL response body variants removed from `RouterResponse` ([PR #1307](https://github.com/apollographql/router/pull/1307), [PR #1328](https://github.com/apollographql/router/pull/1328)) -Previously the `ResponseBody` enum was used in `RouterResponse`. -One of this enum’s variants contains a `apollo_router::graphql::Response`, -which is now used directly instead. +The `ResponseBody` enum has been removed. +It had variants for GraphQL and non-GraphQL responses. + +It was used: + +* In `RouterResponse` which now uses `apollo_router::graphql::Response` instead +* In `Handler` for plugin custom endpoints which now uses `bytes::Bytes` instead Various type signatures will need changes such as: diff --git a/apollo-router/src/axum_http_server_factory.rs b/apollo-router/src/axum_http_server_factory.rs index 9d60be3e4f..4d6350436a 100644 --- a/apollo-router/src/axum_http_server_factory.rs +++ b/apollo-router/src/axum_http_server_factory.rs @@ -61,7 +61,6 @@ use crate::http_server_factory::NetworkStream; use crate::layers::DEFAULT_BUFFER_SIZE; use crate::plugin::Handler; use crate::router::ApolloRouterError; -use crate::ResponseBody; /// A basic http server using Axum. /// Uses streaming as primary method of response. @@ -414,31 +413,7 @@ async fn custom_plugin_handler( head.uri = Uri::from_str(&format!("http://{}{}", host, head.uri)) .expect("if the authority is some then the URL is valid; qed"); let req = Request::from_parts(head, body).into(); - let res = handler.oneshot(req).await.map_err(|err| err.to_string())?; - - let is_json = matches!( - res.body(), - ResponseBody::GraphQL(_) | ResponseBody::RawJSON(_) - ); - - let mut res = res.map(|body| match body { - ResponseBody::GraphQL(res) => { - Bytes::from(serde_json::to_vec(&res).expect("responsebody is serializable; qed")) - } - ResponseBody::RawJSON(res) => { - Bytes::from(serde_json::to_vec(&res).expect("responsebody is serializable; qed")) - } - ResponseBody::Text(res) => Bytes::from(res), - }); - - if is_json { - res.headers_mut().insert( - http::header::CONTENT_TYPE, - HeaderValue::from_static("application/json"), - ); - } - - Ok::<_, String>(res) + handler.oneshot(req).await.map_err(|err| err.to_string()) } async fn handle_get( @@ -1793,11 +1768,7 @@ Content-Type: application/json\r Ok::<_, BoxError>(http_ext::Response { inner: http::Response::builder() .status(StatusCode::OK) - .body(ResponseBody::Text(format!( - "{} + {}", - req.method(), - req.uri().path() - ))) + .body(format!("{} + {}", req.method(), req.uri().path()).into()) .unwrap(), }) }) diff --git a/apollo-router/src/plugin/mod.rs b/apollo-router/src/plugin/mod.rs index 35eef72d6f..6310bade1d 100644 --- a/apollo-router/src/plugin/mod.rs +++ b/apollo-router/src/plugin/mod.rs @@ -45,7 +45,6 @@ use crate::ExecutionRequest; use crate::ExecutionResponse; use crate::QueryPlannerRequest; use crate::QueryPlannerResponse; -use crate::ResponseBody; use crate::RouterRequest; use crate::RouterResponse; use crate::SubgraphRequest; @@ -319,14 +318,14 @@ macro_rules! register_plugin { #[derive(Clone)] pub struct Handler { service: Buffer< - BoxService, http_ext::Response, BoxError>, + BoxService, http_ext::Response, BoxError>, http_ext::Request, >, } impl Handler { pub fn new( - service: BoxService, http_ext::Response, BoxError>, + service: BoxService, http_ext::Response, BoxError>, ) -> Self { Self { service: ServiceBuilder::new().buffered().service(service), @@ -335,7 +334,7 @@ impl Handler { } impl Service> for Handler { - type Response = http_ext::Response; + type Response = http_ext::Response; type Error = BoxError; type Future = ResponseFuture>>; @@ -348,11 +347,9 @@ impl Service> for Handler { } } -impl From, http_ext::Response, BoxError>> - for Handler -{ +impl From, http_ext::Response, BoxError>> for Handler { fn from( - original: BoxService, http_ext::Response, BoxError>, + original: BoxService, http_ext::Response, BoxError>, ) -> Self { Self::new(original) } diff --git a/apollo-router/src/plugins/rhai.rs b/apollo-router/src/plugins/rhai.rs index 291499600d..7d456fa3e2 100644 --- a/apollo-router/src/plugins/rhai.rs +++ b/apollo-router/src/plugins/rhai.rs @@ -52,7 +52,6 @@ use crate::ExecutionRequest; use crate::ExecutionResponse; use crate::QueryPlannerRequest; use crate::QueryPlannerResponse; -use crate::ResponseBody; use crate::RouterRequest; use crate::RouterResponse; use crate::SubgraphRequest; @@ -1354,7 +1353,6 @@ impl Rhai { .register_type::<(Option, HeaderValue)>() .register_type::() .register_type::() - .register_type::() .register_type::() .register_type::() .register_type::() @@ -1502,107 +1500,6 @@ impl Rhai { *x = Uri::from_parts(parts).map_err(|e| e.to_string())?; Ok(()) }) - // ResponseBody "short-cuts" to bypass the enum - // ResponseBody.label - .register_get_result("label", |x: &mut ResponseBody| { - match x { - ResponseBody::GraphQL(resp) => { - // Because we are short-cutting the response here - // we need to select the label from our resp - to_dynamic(resp.label.clone()) - } - _ => Err("wrong type of response".into()), - } - }) - .register_set_result("label", |x: &mut ResponseBody, value: Dynamic| { - match x { - ResponseBody::GraphQL(resp) => { - // Because we are short-cutting the response here - // we need to update the label on our resp - resp.label = from_dynamic(&value)?; - Ok(()) - } - _ => Err("wrong type of response".into()), - } - }) - // ResponseBody.data - .register_get_result("data", |x: &mut ResponseBody| match x { - ResponseBody::GraphQL(resp) => { - // Because we are short-cutting the response here - // we need to select the data from our resp - to_dynamic(resp.data.clone()) - } - _ => Err("wrong type of response".into()), - }) - .register_set_result("data", |x: &mut ResponseBody, om: Map| match x { - ResponseBody::GraphQL(resp) => { - // Because we are short-cutting the response here - // we need to update the data on our resp - resp.data = from_dynamic(&om.into())?; - Ok(()) - } - _ => Err("wrong type of response".into()), - }) - // ResponseBody.path (Not Implemented) - // ResponseBody.errors - .register_get_result("errors", |x: &mut ResponseBody| { - match x { - ResponseBody::GraphQL(resp) => { - // Because we are short-cutting the response here - // we need to select the errors from our resp - to_dynamic(resp.errors.clone()) - } - _ => Err("wrong type of response".into()), - } - }) - .register_set_result("errors", |x: &mut ResponseBody, value: Dynamic| match x { - ResponseBody::GraphQL(resp) => { - resp.errors = from_dynamic(&value)?; - Ok(()) - } - _ => Err("wrong type of response".into()), - }) - // ResponseBody.extensions - .register_get_result("extensions", |x: &mut ResponseBody| { - match x { - ResponseBody::GraphQL(resp) => { - // Because we are short-cutting the response here - // we need to select the extensions from our resp - to_dynamic(resp.extensions.clone()) - } - _ => Err("wrong type of response".into()), - } - }) - .register_set_result("extensions", |x: &mut ResponseBody, om: Map| { - match x { - ResponseBody::GraphQL(resp) => { - // Because we are short-cutting the response here - // we need to update the extensions on our resp - resp.extensions = from_dynamic(&om.into())?; - Ok(()) - } - _ => Err("wrong type of response".into()), - } - }) - // ResponseBody.response - /* We short-cut the treatment of ResponseBody processing to directly - * manipulate "data" rather than moving the enum as we probably should. - * We do this to "harmonise" the interactions with response data for Rhai - * scripts and (effectively) hide the ResponseBody enum from sight. - * At some point: ResponseBody should probably be taken out of the - * codebase, so this is probably a good decision. - .register_get_result("response", |x: &mut ResponseBody| match x { - ResponseBody::GraphQL(resp) => Ok(resp.clone()), - _ => Err("wrong type of response".into()), - }) - .register_set_result("response", |x: &mut ResponseBody, value: Response| { - match x { - ResponseBody::GraphQL(resp) => std::mem::replace(resp, value), - _ => return Err("wrong type of response".into()), - }; - Ok(()) - }) - */ // Response.label .register_get("label", |x: &mut Response| { x.label.clone().map_or(Dynamic::UNIT, Dynamic::from) @@ -1698,9 +1595,6 @@ impl Rhai { .register_fn("to_string", |x: &mut Request| -> String { format!("{:?}", x) }) - .register_fn("to_string", |x: &mut ResponseBody| -> String { - format!("{:?}", x) - }) .register_fn("to_string", |x: &mut Response| -> String { format!("{:?}", x) }) diff --git a/apollo-router/src/plugins/telemetry/metrics/mod.rs b/apollo-router/src/plugins/telemetry/metrics/mod.rs index 00452da03a..20dd3eae68 100644 --- a/apollo-router/src/plugins/telemetry/metrics/mod.rs +++ b/apollo-router/src/plugins/telemetry/metrics/mod.rs @@ -35,7 +35,6 @@ use crate::plugins::telemetry::config::MetricsCommon; use crate::plugins::telemetry::metrics::apollo::Sender; use crate::services::RouterResponse; use crate::Context; -use crate::ResponseBody; pub(crate) mod apollo; pub(crate) mod otlp; @@ -43,7 +42,7 @@ pub(crate) mod prometheus; pub(crate) type MetricsExporterHandle = Box; pub(crate) type CustomEndpoint = - BoxService, http_ext::Response, BoxError>; + BoxService, http_ext::Response, BoxError>; #[derive(Debug, Clone, Deserialize, JsonSchema)] #[serde(deny_unknown_fields)] diff --git a/apollo-router/src/plugins/telemetry/metrics/prometheus.rs b/apollo-router/src/plugins/telemetry/metrics/prometheus.rs index 48cc9a2177..253934f2c8 100644 --- a/apollo-router/src/plugins/telemetry/metrics/prometheus.rs +++ b/apollo-router/src/plugins/telemetry/metrics/prometheus.rs @@ -17,7 +17,6 @@ use crate::http_ext; use crate::plugins::telemetry::config::MetricsCommon; use crate::plugins::telemetry::metrics::MetricsBuilder; use crate::plugins::telemetry::metrics::MetricsConfigurator; -use crate::ResponseBody; #[derive(Debug, Clone, Deserialize, JsonSchema)] #[serde(deny_unknown_fields)] @@ -57,7 +56,7 @@ pub(crate) struct PrometheusService { } impl Service> for PrometheusService { - type Response = http_ext::Response; + type Response = http_ext::Response; type Error = BoxError; type Future = BoxFuture<'static, Result>; @@ -74,9 +73,7 @@ impl Service> for PrometheusService { Ok(http_ext::Response { inner: http::Response::builder() .status(StatusCode::OK) - .body(ResponseBody::Text( - String::from_utf8_lossy(&result).into_owned(), - )) + .body(result.into()) .map_err(|err| BoxError::from(err.to_string()))?, }) }) diff --git a/apollo-router/src/plugins/telemetry/mod.rs b/apollo-router/src/plugins/telemetry/mod.rs index 62ccc25af1..05b379a06e 100644 --- a/apollo-router/src/plugins/telemetry/mod.rs +++ b/apollo-router/src/plugins/telemetry/mod.rs @@ -66,7 +66,6 @@ use crate::ExecutionRequest; use crate::ExecutionResponse; use crate::QueryPlannerRequest; use crate::QueryPlannerResponse; -use crate::ResponseBody; use crate::RouterRequest; use crate::RouterResponse; use crate::SubgraphRequest; @@ -626,7 +625,7 @@ impl Telemetry { Ok::<_, BoxError>(http_ext::Response { inner: http::Response::builder() .status(StatusCode::NOT_FOUND) - .body(ResponseBody::Text("Not found".to_string())) + .body("Not found".into()) .unwrap(), }) }) @@ -1269,26 +1268,22 @@ mod tests { .unwrap(); let resp = handler.oneshot(http_req_prom).await.unwrap(); assert_eq!(resp.status(), StatusCode::OK); - match resp.body() { - crate::ResponseBody::Text(prom_metrics) => { - assert!(prom_metrics.contains(r#"http_requests_total{another_test="my_default_value",my_value="2",myname="label_value",renamed_value="my_value_set",status="200",x_custom="coming_from_header"} 1"#)); - assert!(prom_metrics.contains(r#"http_request_duration_seconds_count{another_test="my_default_value",my_value="2",myname="label_value",renamed_value="my_value_set",status="200",x_custom="coming_from_header"}"#)); - assert!(prom_metrics.contains(r#"http_request_duration_seconds_bucket{another_test="my_default_value",my_value="2",myname="label_value",renamed_value="my_value_set",status="200",x_custom="coming_from_header",le="0.001"}"#)); - assert!(prom_metrics.contains(r#"http_request_duration_seconds_bucket{another_test="my_default_value",my_value="2",myname="label_value",renamed_value="my_value_set",status="200",x_custom="coming_from_header",le="0.005"}"#)); - assert!(prom_metrics.contains(r#"http_request_duration_seconds_bucket{another_test="my_default_value",my_value="2",myname="label_value",renamed_value="my_value_set",status="200",x_custom="coming_from_header",le="0.015"}"#)); - assert!(prom_metrics.contains(r#"http_request_duration_seconds_bucket{another_test="my_default_value",my_value="2",myname="label_value",renamed_value="my_value_set",status="200",x_custom="coming_from_header",le="0.05"}"#)); - assert!(prom_metrics.contains(r#"http_request_duration_seconds_bucket{another_test="my_default_value",my_value="2",myname="label_value",renamed_value="my_value_set",status="200",x_custom="coming_from_header",le="0.3"}"#)); - assert!(prom_metrics.contains(r#"http_request_duration_seconds_bucket{another_test="my_default_value",my_value="2",myname="label_value",renamed_value="my_value_set",status="200",x_custom="coming_from_header",le="0.4"}"#)); - assert!(prom_metrics.contains(r#"http_request_duration_seconds_bucket{another_test="my_default_value",my_value="2",myname="label_value",renamed_value="my_value_set",status="200",x_custom="coming_from_header",le="0.5"}"#)); - assert!(prom_metrics.contains(r#"http_request_duration_seconds_bucket{another_test="my_default_value",my_value="2",myname="label_value",renamed_value="my_value_set",status="200",x_custom="coming_from_header",le="1"}"#)); - assert!(prom_metrics.contains(r#"http_request_duration_seconds_bucket{another_test="my_default_value",my_value="2",myname="label_value",renamed_value="my_value_set",status="200",x_custom="coming_from_header",le="5"}"#)); - assert!(prom_metrics.contains(r#"http_request_duration_seconds_bucket{another_test="my_default_value",my_value="2",myname="label_value",renamed_value="my_value_set",status="200",x_custom="coming_from_header",le="10"}"#)); - assert!(prom_metrics.contains(r#"http_request_duration_seconds_bucket{another_test="my_default_value",my_value="2",myname="label_value",renamed_value="my_value_set",status="200",x_custom="coming_from_header",le="+Inf"}"#)); - assert!(prom_metrics.contains(r#"http_request_duration_seconds_count{another_test="my_default_value",my_value="2",myname="label_value",renamed_value="my_value_set",status="200",x_custom="coming_from_header"}"#)); - assert!(prom_metrics.contains(r#"http_request_duration_seconds_sum{another_test="my_default_value",my_value="2",myname="label_value",renamed_value="my_value_set",status="200",x_custom="coming_from_header"}"#)); - assert!(prom_metrics.contains(r#"http_request_duration_seconds_bucket{error="INTERNAL_SERVER_ERROR",my_key="my_custom_attribute_from_context",query_from_request="query { test }",status="200",subgraph="my_subgraph_name",unknown_data="default_value",le="1"}"#)); - } - _ => panic!("body does not have the right format"), - } + let prom_metrics = String::from_utf8_lossy(resp.body()); + assert!(prom_metrics.contains(r#"http_requests_total{another_test="my_default_value",my_value="2",myname="label_value",renamed_value="my_value_set",status="200",x_custom="coming_from_header"} 1"#)); + assert!(prom_metrics.contains(r#"http_request_duration_seconds_count{another_test="my_default_value",my_value="2",myname="label_value",renamed_value="my_value_set",status="200",x_custom="coming_from_header"}"#)); + assert!(prom_metrics.contains(r#"http_request_duration_seconds_bucket{another_test="my_default_value",my_value="2",myname="label_value",renamed_value="my_value_set",status="200",x_custom="coming_from_header",le="0.001"}"#)); + assert!(prom_metrics.contains(r#"http_request_duration_seconds_bucket{another_test="my_default_value",my_value="2",myname="label_value",renamed_value="my_value_set",status="200",x_custom="coming_from_header",le="0.005"}"#)); + assert!(prom_metrics.contains(r#"http_request_duration_seconds_bucket{another_test="my_default_value",my_value="2",myname="label_value",renamed_value="my_value_set",status="200",x_custom="coming_from_header",le="0.015"}"#)); + assert!(prom_metrics.contains(r#"http_request_duration_seconds_bucket{another_test="my_default_value",my_value="2",myname="label_value",renamed_value="my_value_set",status="200",x_custom="coming_from_header",le="0.05"}"#)); + assert!(prom_metrics.contains(r#"http_request_duration_seconds_bucket{another_test="my_default_value",my_value="2",myname="label_value",renamed_value="my_value_set",status="200",x_custom="coming_from_header",le="0.3"}"#)); + assert!(prom_metrics.contains(r#"http_request_duration_seconds_bucket{another_test="my_default_value",my_value="2",myname="label_value",renamed_value="my_value_set",status="200",x_custom="coming_from_header",le="0.4"}"#)); + assert!(prom_metrics.contains(r#"http_request_duration_seconds_bucket{another_test="my_default_value",my_value="2",myname="label_value",renamed_value="my_value_set",status="200",x_custom="coming_from_header",le="0.5"}"#)); + assert!(prom_metrics.contains(r#"http_request_duration_seconds_bucket{another_test="my_default_value",my_value="2",myname="label_value",renamed_value="my_value_set",status="200",x_custom="coming_from_header",le="1"}"#)); + assert!(prom_metrics.contains(r#"http_request_duration_seconds_bucket{another_test="my_default_value",my_value="2",myname="label_value",renamed_value="my_value_set",status="200",x_custom="coming_from_header",le="5"}"#)); + assert!(prom_metrics.contains(r#"http_request_duration_seconds_bucket{another_test="my_default_value",my_value="2",myname="label_value",renamed_value="my_value_set",status="200",x_custom="coming_from_header",le="10"}"#)); + assert!(prom_metrics.contains(r#"http_request_duration_seconds_bucket{another_test="my_default_value",my_value="2",myname="label_value",renamed_value="my_value_set",status="200",x_custom="coming_from_header",le="+Inf"}"#)); + assert!(prom_metrics.contains(r#"http_request_duration_seconds_count{another_test="my_default_value",my_value="2",myname="label_value",renamed_value="my_value_set",status="200",x_custom="coming_from_header"}"#)); + assert!(prom_metrics.contains(r#"http_request_duration_seconds_sum{another_test="my_default_value",my_value="2",myname="label_value",renamed_value="my_value_set",status="200",x_custom="coming_from_header"}"#)); + assert!(prom_metrics.contains(r#"http_request_duration_seconds_bucket{error="INTERNAL_SERVER_ERROR",my_key="my_custom_attribute_from_context",query_from_request="query { test }",status="200",subgraph="my_subgraph_name",unknown_data="default_value",le="1"}"#)); } } diff --git a/apollo-router/src/services/mod.rs b/apollo-router/src/services/mod.rs index be0ee22ccd..043b1c8869 100644 --- a/apollo-router/src/services/mod.rs +++ b/apollo-router/src/services/mod.rs @@ -1,8 +1,6 @@ //! Implementation of the various steps in the router's processing pipeline. use std::collections::HashMap; -use std::convert::Infallible; -use std::str::FromStr; use std::sync::Arc; use futures::future::ready; @@ -20,8 +18,6 @@ use http::Uri; use http_ext::IntoHeaderName; use http_ext::IntoHeaderValue; use multimap::MultiMap; -use serde::Deserialize; -use serde::Serialize; use serde_json_bytes::ByteString; use static_assertions::assert_impl_all; pub use subgraph_service::SubgraphService; @@ -46,86 +42,6 @@ pub(crate) mod layers; mod router_service; pub(crate) mod subgraph_service; -/// Different kinds of body we could have as the Router's response -#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)] -#[serde(untagged)] -pub enum ResponseBody { - /// A GraphQL response corresponding to the spec - GraphQL(Response), - /// A json value - RawJSON(serde_json::Value), - /// Text without any serialization (example: HTML content, Prometheus metrics, ...) - Text(String), -} - -impl TryFrom for Response { - type Error = &'static str; - - fn try_from(value: ResponseBody) -> Result { - match value { - ResponseBody::GraphQL(res) => Ok(res), - ResponseBody::RawJSON(_) => { - Err("wrong ResponseBody kind: expected Response, found RawJSON") - } - ResponseBody::Text(_) => Err("wrong ResponseBody kind: expected Response, found Text"), - } - } -} - -impl TryFrom for String { - type Error = &'static str; - - fn try_from(value: ResponseBody) -> Result { - match value { - ResponseBody::RawJSON(_) => { - Err("wrong ResponseBody kind: expected RawString, found RawJSON") - } - ResponseBody::GraphQL(_) => { - Err("wrong ResponseBody kind: expected RawString, found GraphQL") - } - ResponseBody::Text(res) => Ok(res), - } - } -} - -impl TryFrom for serde_json::Value { - type Error = &'static str; - - fn try_from(value: ResponseBody) -> Result { - match value { - ResponseBody::RawJSON(res) => Ok(res), - ResponseBody::GraphQL(_) => { - Err("wrong ResponseBody kind: expected RawJSON, found GraphQL") - } - ResponseBody::Text(_) => Err("wrong ResponseBody kind: expected RawJSON, found Text"), - } - } -} - -impl From for ResponseBody { - fn from(response: Response) -> Self { - Self::GraphQL(response) - } -} - -impl From for ResponseBody { - fn from(json: serde_json::Value) -> Self { - Self::RawJSON(json) - } -} - -// This impl is purposefully done this way to hint users this might not be what they would like to do. -/// Creates a ResponseBody from a &str -/// -/// /!\ No serialization or deserialization is involved, -/// please make sure you don't want to send a GraphQL response or a Raw JSON payload instead. -impl FromStr for ResponseBody { - type Err = Infallible; - fn from_str(s: &str) -> Result { - Ok(Self::Text(s.to_owned())) - } -} - assert_impl_all!(RouterRequest: Send); /// Represents the router processing step of the processing pipeline. /// @@ -224,7 +140,7 @@ impl RouterRequest { } assert_impl_all!(RouterResponse>: Send); -/// [`Context`] and [`http_ext::Response`] for the response. +/// [`Context`] and [`http_ext::Response`] for the response. /// /// This consists of the response body and the context. #[derive(Clone, Debug)] diff --git a/examples/rhai-data-response-mutate/src/main.rs b/examples/rhai-data-response-mutate/src/main.rs index a5e4271d2c..86fc236740 100644 --- a/examples/rhai-data-response-mutate/src/main.rs +++ b/examples/rhai-data-response-mutate/src/main.rs @@ -72,14 +72,9 @@ mod tests { assert_eq!(StatusCode::OK, service_response.response.status()); // with the expected message - if let apollo_router::ResponseBody::GraphQL(response) = - service_response.response.body() - { - assert!(response.errors.is_empty()); - assert_eq!(expected_mock_response_data, response.data.as_ref().unwrap()); - } else { - panic!("unexpected response"); - } + let response = service_response.response.body(); + assert!(response.errors.is_empty()); + assert_eq!(expected_mock_response_data, response.data.as_ref().unwrap()); */ } } diff --git a/examples/rhai-error-response-mutate/src/main.rs b/examples/rhai-error-response-mutate/src/main.rs index 313881cab6..3c09dd76be 100644 --- a/examples/rhai-error-response-mutate/src/main.rs +++ b/examples/rhai-error-response-mutate/src/main.rs @@ -69,14 +69,9 @@ mod tests { assert_eq!(StatusCode::OK, service_response.response.status()); // with the expected message - if let apollo_router::ResponseBody::GraphQL(response) = - service_response.response.body() - { - assert!(response.errors.is_empty()); - assert_eq!(expected_mock_response_data, response.data.as_ref().unwrap()); - } else { - panic!("unexpected response"); - } + let response = service_response.response.body(); + assert!(response.errors.is_empty()); + assert_eq!(expected_mock_response_data, response.data.as_ref().unwrap()); */ } } diff --git a/examples/rhai-subgraph-request-log/src/main.rs b/examples/rhai-subgraph-request-log/src/main.rs index 5e57222e2c..c4ac926da7 100644 --- a/examples/rhai-subgraph-request-log/src/main.rs +++ b/examples/rhai-subgraph-request-log/src/main.rs @@ -69,14 +69,9 @@ mod tests { assert_eq!(StatusCode::OK, service_response.response.status()); // with the expected message - if let apollo_router::ResponseBody::GraphQL(response) = - service_response.response.body() - { - assert!(response.errors.is_empty()); - assert_eq!(expected_mock_response_data, response.data.as_ref().unwrap()); - } else { - panic!("unexpected response"); - } + let response = service_response.response.body(); + assert!(response.errors.is_empty()); + assert_eq!(expected_mock_response_data, response.data.as_ref().unwrap()); */ } } diff --git a/examples/rhai-surrogate-cache-key/src/main.rs b/examples/rhai-surrogate-cache-key/src/main.rs index 23ce5035fa..637d8e75c4 100644 --- a/examples/rhai-surrogate-cache-key/src/main.rs +++ b/examples/rhai-surrogate-cache-key/src/main.rs @@ -68,14 +68,9 @@ mod tests { /* TBD: Figure out how to run this as a test // with the expected message - if let apollo_router::ResponseBody::GraphQL(response) = - service_response.response.body() - { - assert!(response.errors.is_empty()); - assert_eq!(expected_mock_response_data, response.data.as_ref().unwrap()); - } else { - panic!("unexpected response"); - } + let response = service_response.response.body(); + assert!(response.errors.is_empty()); + assert_eq!(expected_mock_response_data, response.data.as_ref().unwrap()); */ } }