From eee086df0042ba1afb03e26568653d1532e065fd Mon Sep 17 00:00:00 2001 From: Gary Pennington Date: Tue, 26 Mar 2024 11:46:34 +0000 Subject: [PATCH 1/3] fix subgraph unwrapping Without this fix a null body would cause the router to panic. With this fix, if a body is null, then the router returns an error to the user. --- apollo-router/src/services/subgraph_service.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/apollo-router/src/services/subgraph_service.rs b/apollo-router/src/services/subgraph_service.rs index 654ca83881..adfd1ced5a 100644 --- a/apollo-router/src/services/subgraph_service.rs +++ b/apollo-router/src/services/subgraph_service.rs @@ -805,11 +805,15 @@ pub(crate) async fn process_batch( } tracing::debug!("parts: {parts:?}, content_type: {content_type:?}, body: {body:?}"); - let value = serde_json::from_slice(&body.unwrap().unwrap()).map_err(|error| { + let value = serde_json::from_slice(&body.ok_or(BoxError::from( FetchError::SubrequestMalformedResponse { service: service.to_string(), - reason: error.to_string(), - } + reason: "no body in response".to_string(), + }, + ))??) + .map_err(|error| FetchError::SubrequestMalformedResponse { + service: service.to_string(), + reason: error.to_string(), })?; tracing::debug!("json value from body is: {value:?}"); From 7ba39aa9070478c5e92838f45c44be32af471588 Mon Sep 17 00:00:00 2001 From: Gary Pennington Date: Tue, 26 Mar 2024 12:04:14 +0000 Subject: [PATCH 2/3] make sure my error propagation syntax is correct --- apollo-router/src/services/subgraph_service.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/apollo-router/src/services/subgraph_service.rs b/apollo-router/src/services/subgraph_service.rs index adfd1ced5a..356c242911 100644 --- a/apollo-router/src/services/subgraph_service.rs +++ b/apollo-router/src/services/subgraph_service.rs @@ -805,16 +805,15 @@ pub(crate) async fn process_batch( } tracing::debug!("parts: {parts:?}, content_type: {content_type:?}, body: {body:?}"); - let value = serde_json::from_slice(&body.ok_or(BoxError::from( - FetchError::SubrequestMalformedResponse { + let value = + serde_json::from_slice(&body.ok_or(FetchError::SubrequestMalformedResponse { service: service.to_string(), reason: "no body in response".to_string(), - }, - ))??) - .map_err(|error| FetchError::SubrequestMalformedResponse { - service: service.to_string(), - reason: error.to_string(), - })?; + })??) + .map_err(|error| FetchError::SubrequestMalformedResponse { + service: service.to_string(), + reason: error.to_string(), + })?; tracing::debug!("json value from body is: {value:?}"); From 0ce51eae132bd4f04107f2391f77f6bb936c78d1 Mon Sep 17 00:00:00 2001 From: Gary Pennington Date: Tue, 26 Mar 2024 12:22:22 +0000 Subject: [PATCH 3/3] make change requested by customer to reduce trace to debug from info... --- apollo-router/src/services/subgraph_service.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apollo-router/src/services/subgraph_service.rs b/apollo-router/src/services/subgraph_service.rs index 356c242911..cdf1e757de 100644 --- a/apollo-router/src/services/subgraph_service.rs +++ b/apollo-router/src/services/subgraph_service.rs @@ -1041,7 +1041,7 @@ pub(crate) async fn call_http( let (parts, _) = subgraph_request.into_parts(); let body = serde_json::to_string(&body).expect("JSON serialization should not fail"); - tracing::info!("our JSON body: {body:?}"); + tracing::debug!("our JSON body: {body:?}"); let mut request = http::Request::from_parts(parts, Body::from(body)); request