question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CompleteableFuture that completes exceptionally with a custom exception which implements GraphQLError is not becoming an graphql error

See original GitHub issue

From spectrum : https://spectrum.chat/graphql-java/general/graphql-java-13-0-unable-to-get-extensions-from-async-data-fetcher-exceptions~f0752fa2-aa88-49ee-98ac-a56f1c2b64fa

Hi - 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:closed
  • Created 4 years ago
  • Reactions:5
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
bbakermancommented, Jul 7, 2021

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…

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

1reaction
roschlaucommented, Jul 7, 2021

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 its cause 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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found