public abstract class DataFetcherExceptionResolverAdapter extends Object implements DataFetcherExceptionResolver
DataFetcherExceptionResolver
that pre-implements the
asynchronous contract and exposes the following synchronous protected methods:
resolveToSingleError(java.lang.Throwable, graphql.schema.DataFetchingEnvironment)
resolveToMultipleErrors(java.lang.Throwable, graphql.schema.DataFetchingEnvironment)
Use from(BiFunction)
to create an instance or extend this class
and override one of its resolve methods.
Implementations can also express interest in ThreadLocal context
propagation, from the underlying transport thread, via
setThreadLocalContextAware(boolean)
.
Modifier | Constructor and Description |
---|---|
protected |
DataFetcherExceptionResolverAdapter()
Protected constructor since this class is meant to be extended to provide
the actual exception resolution logic.
|
Modifier and Type | Method and Description |
---|---|
static DataFetcherExceptionResolverAdapter |
from(BiFunction<Throwable,DataFetchingEnvironment,GraphQLError> resolver)
Factory method to create a
DataFetcherExceptionResolverAdapter that
resolves exceptions with the given BiFunction . |
boolean |
isThreadLocalContextAware()
Whether ThreadLocal context needs to be restored for this resolver.
|
reactor.core.publisher.Mono<List<GraphQLError>> |
resolveException(Throwable ex,
DataFetchingEnvironment env)
Resolve the given exception and return the error(s) to add to the response.
|
protected List<GraphQLError> |
resolveToMultipleErrors(Throwable ex,
DataFetchingEnvironment env)
Override this method to resolve an Exception to multiple GraphQL errors.
|
protected GraphQLError |
resolveToSingleError(Throwable ex,
DataFetchingEnvironment env)
Override this method to resolve an Exception to a single GraphQL error.
|
void |
setThreadLocalContextAware(boolean threadLocalContextAware)
Sub-classes can set this to indicate that ThreadLocal context from the
transport handler (e.g.
|
protected DataFetcherExceptionResolverAdapter()
public void setThreadLocalContextAware(boolean threadLocalContextAware)
Note: This property is applicable only if transports
use ThreadLocal's' (e.g. Spring MVC) and if a ThreadLocalAccessor
is registered to extract ThreadLocal values of interest. There is no
impact from setting this property otherwise.
By default this is set to "false" in which case there is no attempt to propagate ThreadLocal context.
threadLocalContextAware
- whether this resolver needs access to
ThreadLocal context or not.public boolean isThreadLocalContextAware()
public final reactor.core.publisher.Mono<List<GraphQLError>> resolveException(Throwable ex, DataFetchingEnvironment env)
DataFetcherExceptionResolver
Implementations can use
GraphqlErrorBuilder.newError(DataFetchingEnvironment)
to
create an error with the coordinates of the target field, and use
ErrorType
to specify a category for the error.
resolveException
in interface DataFetcherExceptionResolver
ex
- the exception to resolveenv
- the environment for the invoked DataFetcher
Mono
with errors to add to the GraphQL response;
if the Mono
completes with an empty List, the exception is resolved
without any errors added to the response; if the Mono
completes
empty, without emitting a List, the exception remains unresolved and gives
other resolvers a chance.@Nullable protected List<GraphQLError> resolveToMultipleErrors(Throwable ex, DataFetchingEnvironment env)
ex
- the exception to resolveenv
- the environment for the invoked DataFetcher
null
if unresolved@Nullable protected GraphQLError resolveToSingleError(Throwable ex, DataFetchingEnvironment env)
ex
- the exception to resolveenv
- the environment for the invoked DataFetcher
null
if unresolvedpublic static DataFetcherExceptionResolverAdapter from(BiFunction<Throwable,DataFetchingEnvironment,GraphQLError> resolver)
DataFetcherExceptionResolverAdapter
that
resolves exceptions with the given BiFunction
.resolver
- the resolver function to use