Skip to content

Commit

Permalink
graphql: Make the log for large results more useful
Browse files Browse the repository at this point in the history
  • Loading branch information
lutter committed Apr 29, 2022
1 parent 00e597f commit 0402b2a
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions graphql/src/store/prefetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,15 +498,18 @@ fn execute_root_selection_set(
execute_selection_set(resolver, ctx, make_root_node(), selection_set)
}

fn check_result_size(logger: &Logger, size: usize) -> Result<(), QueryExecutionError> {
fn check_result_size<'a>(
ctx: &'a ExecutionContext<impl Resolver>,
size: usize,
) -> Result<(), QueryExecutionError> {
if size > ENV_VARS.graphql.error_result_size {
return Err(QueryExecutionError::ResultTooBig(
size,
ENV_VARS.graphql.error_result_size,
));
}
if size > ENV_VARS.graphql.warn_result_size {
warn!(logger, "Large query result"; "size" => size);
warn!(ctx.logger, "Large query result"; "size" => size, "query_id" => &ctx.query.query_id);
}
Ok(())
}
Expand Down Expand Up @@ -583,7 +586,7 @@ fn execute_selection_set<'a>(
Join::perform(&mut parents, children, field.response_key());
let weight =
parents.iter().map(|parent| parent.weight()).sum::<usize>();
check_result_size(&ctx.logger, weight)?;
check_result_size(ctx, weight)?;
}
Err(mut e) => errors.append(&mut e),
}
Expand Down

0 comments on commit 0402b2a

Please sign in to comment.