Skip to content

Commit

Permalink
Do not report usage to Studio when variable values are invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
goto-bus-stop committed Nov 6, 2024
1 parent d18598f commit a0eceba
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion apollo-router/src/services/supergraph/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ async fn service_call(
) -> Result<SupergraphResponse, BoxError> {
let context = req.context;
let body = req.supergraph_request.body();
let variables = body.variables.clone();
let variables = &body.variables;

let QueryPlannerResponse {
content,
Expand Down Expand Up @@ -304,6 +304,15 @@ async fn service_call(
*response.response.status_mut() = StatusCode::NOT_ACCEPTABLE;
Ok(response)
} else if let Some(err) = plan.query.validate_variables(body, &schema).err() {
// Replace the existing usage report so we do not report invalid variable values to
// Studio.
context.extensions().with_lock(|mut lock| {
lock.insert(Arc::new(UsageReporting {
stats_report_key: "GRAPHQL_VALIDATION_FAILED".to_string(),
referenced_fields_by_type: Default::default(),
}))
});

let mut res = SupergraphResponse::new_from_graphql_response(err, context);
*res.response.status_mut() = StatusCode::BAD_REQUEST;
Ok(res)
Expand Down

0 comments on commit a0eceba

Please sign in to comment.