Skip to content

Commit

Permalink
[batching] fix subgraph unwrapping (#4849)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
garypen authored Mar 26, 2024
1 parent 224ab9d commit 41d5826
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions apollo-router/src/services/subgraph_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -805,12 +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| {
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(),
}
})?;
})?;

tracing::debug!("json value from body is: {value:?}");

Expand Down Expand Up @@ -1038,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
Expand Down

0 comments on commit 41d5826

Please sign in to comment.