CompleteableFuture that completes exceptionally with a custom exception which implements GraphQLError is not becoming an graphql error
See original GitHub issueHi - i am using graphql-java 13.0 and one of my async data fetchers returns a CompletableFuture which is completed exceptionally with a custom exception which implements GraphQLError and extends RuntimeException. eg:- preProcessRequest function in below data fetcher throws the above custom exception
@Override
public CompletionStage<T> get(final DataFetchingEnvironment environment) {
return CompletableFuture.completedFuture(null)
.thenCompose(v -> preProcessRequest(environment))
.thenCompose(v -> executeRequest(environment))
.exceptionally(throwable -> {
LOG.info("GraphQL Query failed {}", throwable);
final Throwable t = ThrowableUtils.unwrapIfExecutionOrCompletionException(throwable);
throw ThrowableUtils.ensureRuntime(t);
});
}
However, i am unable to get extensions from the error. When executing this code in ExecutionStrategy.java:
return fetchedValue
.handle((result, exception) -> {
fetchCtx.onCompleted(result, exception);
if (exception != null) {
handleFetchingException(executionContext, parameters, environment, exception);
return null;
} else {
return result;
}
})
.thenApply(result -> unboxPossibleDataFetcherResult(executionContext, parameters, result));
the exception object is of type CompletionException instead of the underlying GraphQLError and hence error extensions are null. This used to work with v12.0 and i am unsure if i changed something or the version upgrade broke it. Is this a known issue?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:5
- Comments:5 (3 by maintainers)
Top Results From Across the Web
How to handle custom GraphQL error such that it does not ...
One simple solution to it was to add a custom GraphQL error handler to handle the exceptions thrown from my services. I then,...
Read more >Understanding GraphQL Error Handling Mechanisms in ...
In case#1: Our custom exceptions were not instances of GraphQLErrors, the DefaultGraphQLErrorHandler considered them as internal server errors, containing ...
Read more >graphql-java Documentation - Read the Docs
NOTE: SDL is not currently part of the formal graphql spec. ... CustomRuntimeException extends RuntimeException implements GraphQLError {.
Read more >AppSyncAsyncClient (AWS SDK for Java - 2.18.10)
The CompletableFuture returned by this method can be completed exceptionally with the following exceptions. AccessDeniedException You don't ...
Read more >Error Handling in GraphQL With Spring Boot - Baeldung
Now let's see what the response will look like if we implement our custom exception handling. First, we have another custom exception: public ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
We can look into this but guilting us into it is probably not the way to do it.
A PR is worth a 1000 guilt trips
We just stumbled over this problem in 2021 - a little disheartening to see that there’s basically no reaction to this at all so far… For now, we’ve built ourselves a simple custom error handler that checks any exception thrown by a data fetcher if it’s a
CompletionException
and unwraps itscause
if it is, so extensions from our custom GraphqlError classes are properly passed on.I’d probably be able to draft a PR for integrating this unwrapping logic into the library, but I have not idea if that is actually a generally applicable solution or if there are pitfalls that make it unsuitable for being the default behavior, so would like some input on this from the maintainers, if possible.