graphql-rust / juniper

GraphQL server library for Rust
Other
5.72k stars 425 forks source link

If a query/mutation returns an Err, how do I access it at the top level? #1132

Closed mikebaldry closed 1 year ago

mikebaldry commented 1 year ago

I want to log any errors like this. but using code like:

    let query: GraphQLRequest = request.body_json().await?;
    let response = query.execute(&SCHEMA, request.state()).await;

    let status = if response.is_ok() {
        StatusCode::Ok
    } else {
        StatusCode::BadRequest
    };

    Ok(Response::builder(status)
        .body(Body::from_json(&response)?)
        .build())

I am unable to access anything on response as the actual Result is not public.

Can anyone suggest how this should be achieved?

tyranron commented 1 year ago

@mikebaldry could you share your use case? Why do you need it at all?

At the moment, this can be achieved in the following ways:

mikebaldry commented 1 year ago

Thanks for the swift response. My use case, I don't think is anything special. I just want to log any errors that occur so I can report on them or find more details than what would be exposed via the graphql output.