-
Notifications
You must be signed in to change notification settings - Fork 317
Annotated exception handler methods #160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks for raising this point @Sam-Kruglov We can mix and match MVC, WebFlux and GraphQL handler methods in the same It looks like graphql-java-kickstart accepts the following signatures for
I'm surprised the choice was done here to support only synchronous calls. Right now With that in mind, I think that supporting
Maybe we could instead with an
As we can see, dealing with reactive types for return values can lead to subtle behaviors: the exception remains unresolved vs. no error should be added to the response. The |
Yeah, you're right, I like Also, GraphQL can return errors and data at the same time, so when an error occurs, it occurs inside a field resolver (is it called data fetcher here?). So, when a resolver fails, the exception translates via this annotation method, and gets added to the "errors" field of the graphql response. Other resolvers should be able to proceed their work and populate the "data" field of the graphql response. Not sure if this is the current behaviour already but from the documentation I got the impression that a single error would fail everything. |
Yes, that's right. In Spring GraphQL, we're using GraphQL Java concepts such as
Yes, this is the current behavior - and IMO expected behavior for GraphQL applications. |
The underlying mechanism is still that of GraphQL Java, so when a controller raises an exception, it has to propagate at first. Then GraphQL Java calls the registered What we have currently, as explained in the docs, is that you can register one or more @Bean
public DataFetcherExceptionResolver exceptionResolver() {
return DataFetcherExceptionResolverAdapter.from((ex, env) -> {
if (ex instanceof SomeException) {
return GraphqlErrorBuilder.newError(env).message("...").errorType(...).build();
}
else if (ex instanceof AnotherException) {
return GraphqlErrorBuilder.newError(env).message("...").errorType(...).build();
}
else {
return null;
}
});
} I'm wondering whether this is sufficient for GraphQL? For once the inputs are simpler and for output there is no need to write to a response, which reduces the amount of benefit from such methods. At the same time there is extra overhead in GraphQL where there may be multiple exceptions per request for different parts of the data graph and the exception resolution steps are repeated multiple times. The other aspect could be the need for localized handling. It would be useful to hear more feedback on all this. |
@rstoyanchev I think it's just nicer to have separate Some exceptions will be in response for the client to see, some will be internal errors that the client should not see but we still want to recover from or at least log. |
It's good way than using if (ex instanceof ....
|
It looks like the |
Hi, would be a nice addition to support
@ExceptionHandler
methods and@ControllerAdvice
. Those could be injected into the exception resolver chain. This feature is available here (at least to some extend) https://github.com/graphql-java-kickstart/graphql-spring-bootThe text was updated successfully, but these errors were encountered: