async-graphql
async-graphql copied to clipboard
Most ergonomic way to return custom errors
Hi!
I've been playing around with your crate and it's really nicely put together. Thank you for your work.
The only issue I've found so far is that reporting of custom application errors is a bit awkward with the current extensions API. What I mean is that they don't feel like first class citizens and introduce inconsistency when dealing with GraphQL errors or application errors. From an API user point of view I think it would be nice if there was one consistent way of handling errors.
In my particular case this is awkward because some endpoints in my app can return multiple errors. So what I'd have is a list of GraphQL errors and one of those would have a nested list of my own errors, in the extensions field. Would be nice if I could flatten them.
Would it be possible to override the default GraphQL error with a custom application one? E.g. with something like:
#[derive(Serialize)]
#[serde(untagged)]
pub enum ServerError<T: Serialize> {
GraphQL(async_graphl::Error),
Custom(T),
}
But I think generics wouldn't work here as they make ServerError
not object safe which would cause issues with async_trait
, that is used throughout the code.
Do you see alternatives? Even just suggestions on application error reporting best practices via async_graphql
would be welcome (I did go through all the examples).
Thanks!
Related: https://github.com/async-graphql/async-graphql/issues/399
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
This issue was closed because it has been stalled for 5 days with no activity.