router
router copied to clipboard
Context not updated from error in subgraph
Describe the bug I'm trying to insert an entry to the context in a subgraph error, something like this:
.map_result(|result: Result<SubgraphResponse, BoxError>| match result {
Err(err) => {
if let Some(fetch_err) = err.downcast_ref::<FetchError>() {
match fetch_err {
FetchError::SubrequestHttpError { service: _, reason } => {
if reason.contains("\"statusCode\":401") {
let res = http::Response::builder()
.status(StatusCode::from_u16(200).unwrap())
.body(fetch_err.to_response())
.expect("Issue serializing fetch error");
let context = Context::new();
let _ = context
.insert::<&str, String>("status-code", "401".into())
.unwrap();
let res =
SubgraphResponse::new_from_response(res.into(), context);
info!("response: {:?}", res);
Ok(res)
} else {
Err(err)
}
}
_ => Err(err),
}
} else {
Err(err)
}
}
other => other,
})
The subgraph response becomes:
I can see the entry but in the router_service part, it's absent:

Another point, when I insert a new entry in a subgraph response that is Ok, I'm able to see it in the router_service. I suspect that this is an issue only when the errors field is not empty.
Expected behavior we should be able to see new entry in the route_service map_response part.
JFI, issue persists in v 0.10.0
thanks, I'll look into it
is there any change on this 🤔 🙏 with the 0.16.0 of the router, are we able to update context now from the map_result
I think this is actually down to the same kind of problem as #1284. Namely, any subgraph response isn't preserved through the chain of execution and supergraph response.
Until we resolve #1284 (which is no longer well titled. It's been about header propagation for most users, but this issue shows that it's really about response propagation) this isn't going to be possible as written.
I could think of a way to just solve the context part, but the mapping of the result will still be lost (until we fix #1284 or something like that).