Skip to content

Commit

Permalink
WIP Propagate query planner errors
Browse files Browse the repository at this point in the history
Fixes #1142
  • Loading branch information
SimonSapin committed Jun 30, 2022
1 parent 99c759c commit 0241e29
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions apollo-router/src/query_planner/bridge_query_planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ impl BridgeQueryPlanner {
options,
}),
query: Arc::new(selections),
errors: Vec::new(),
}),
PlanSuccess {
data: QueryPlan { node: None },
Expand Down
2 changes: 1 addition & 1 deletion apollo-router/src/services/http_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ pub struct Response<T> {
impl<T> Response<T> {
pub fn map<F, U>(self, f: F) -> Response<U>
where
F: FnMut(T) -> U,
F: FnOnce(T) -> U,
{
self.inner.map(f).into()
}
Expand Down
3 changes: 2 additions & 1 deletion apollo-router/src/services/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ pub enum QueryPlannerContent {
Plan {
query: Arc<Query>,
plan: Arc<QueryPlan>,
errors: Vec<Error>,
},
Introspection {
response: Box<Response>,
Expand Down Expand Up @@ -441,11 +442,11 @@ impl QueryPlannerResponse {
headers: MultiMap<IntoHeaderName, IntoHeaderValue>,
context: Context,
) -> Result<QueryPlannerResponse, BoxError> {
tracing::warn!("no way to propagate error response from QueryPlanner");
Ok(QueryPlannerResponse::new(
QueryPlannerContent::Plan {
plan: Arc::new(QueryPlan::fake_builder().build()),
query: Arc::new(Query::default()),
errors,
},
context,
))
Expand Down
15 changes: 13 additions & 2 deletions apollo-router/src/services/router_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,13 @@ where
}
.boxed());
}
QueryPlannerContent::Plan { query, plan } => {
if let Some(err) = query.validate_variables(body, &schema).err() {
QueryPlannerContent::Plan {
query,
mut errors,
plan,
} => {
if let Some(mut err) = query.validate_variables(body, &schema).err() {
err.append_errors(&mut errors);
Ok(RouterResponse::new_from_graphql_response(err, context).boxed())
} else {
let operation_name = body.operation_name.clone();
Expand All @@ -179,6 +184,12 @@ where
.build(),
)
.await?;
let response = response.map(move |stream| {
stream.map(move |mut r| {
r.errors.extend(errors.iter().cloned());
r
})
});

let (parts, response_stream) = http::Response::from(response).into_parts();
Ok(RouterResponse {
Expand Down

0 comments on commit 0241e29

Please sign in to comment.