Class DataFetcherExceptionResolverAdapter
- All Implemented Interfaces:
DataFetcherExceptionResolver
- Direct Known Subclasses:
SecurityDataFetcherExceptionResolver
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)
Applications may also use
DataFetcherExceptionResolver.forSingleError(BiFunction)
as a shortcut
for resolveToSingleError(Throwable, DataFetchingEnvironment)
.
Implementations can also express interest in ThreadLocal context
propagation, from the underlying transport thread, via
setThreadLocalContextAware(boolean)
.
- Since:
- 1.0.0
- Author:
- Rossen Stoyanchev
-
Field Summary
-
Constructor Summary
ModifierConstructorDescriptionprotected
Protected constructor since this class is meant to be extended to provide the actual exception resolution logic. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Whether ThreadLocal context needs to be restored for this resolver.final reactor.core.publisher.Mono<List<GraphQLError>>
Resolve the given exception and return the error(s) to add to the response.protected List<GraphQLError>
Override this method to resolve an Exception to multiple GraphQL errors.protected GraphQLError
Override this method to resolve an Exception to a single GraphQL error.void
setThreadLocalContextAware
(boolean threadLocalContextAware) Subclasses can set this to indicate that ThreadLocal context from the transport handler (e.g.
-
Field Details
-
logger
-
-
Constructor Details
-
DataFetcherExceptionResolverAdapter
protected DataFetcherExceptionResolverAdapter()Protected constructor since this class is meant to be extended to provide the actual exception resolution logic.
-
-
Method Details
-
setThreadLocalContextAware
public void setThreadLocalContextAware(boolean threadLocalContextAware) Subclasses can set this to indicate that ThreadLocal context from the transport handler (e.g. HTTP handler) should be restored when resolving exceptions.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.
- Parameters:
threadLocalContextAware
- whether this resolver needs access to ThreadLocal context or not.
-
isThreadLocalContextAware
public boolean isThreadLocalContextAware()Whether ThreadLocal context needs to be restored for this resolver. -
resolveException
public final reactor.core.publisher.Mono<List<GraphQLError>> resolveException(Throwable ex, DataFetchingEnvironment env) Description copied from interface:DataFetcherExceptionResolver
Resolve the given exception and return the error(s) to add to the response.Implementations can use
GraphqlErrorBuilder.newError(DataFetchingEnvironment)
to create an error with the coordinates of the target field, and useErrorType
to specify a category for the error.- Specified by:
resolveException
in interfaceDataFetcherExceptionResolver
- Parameters:
ex
- the exception to resolveenv
- the environment for the invokedDataFetcher
- Returns:
- a
Mono
with errors to add to the GraphQL response; if theMono
completes with an empty List, the exception is resolved without any errors added to the response; if theMono
completes empty, without emitting a List, the exception remains unresolved and that allows other resolvers to resolve it.
-
resolveToMultipleErrors
@Nullable protected List<GraphQLError> resolveToMultipleErrors(Throwable ex, DataFetchingEnvironment env) Override this method to resolve an Exception to multiple GraphQL errors.- Parameters:
ex
- the exception to resolveenv
- the environment for the invokedDataFetcher
- Returns:
- the resolved errors or
null
if unresolved
-
resolveToSingleError
Override this method to resolve an Exception to a single GraphQL error.- Parameters:
ex
- the exception to resolveenv
- the environment for the invokedDataFetcher
- Returns:
- the resolved error or
null
if unresolved
-