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
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedProtected constructor since this class is meant to be extended to provide the actual exception resolution logic. -
Method Summary
Modifier and TypeMethodDescriptionbooleanWhether ThreadLocal context needs to be restored for this resolver.final reactor.core.publisher.Mono<List<graphql.GraphQLError>> resolveException(Throwable ex, graphql.schema.DataFetchingEnvironment env) Resolve the given exception and return the error(s) to add to the response.protected @Nullable List<graphql.GraphQLError> resolveToMultipleErrors(Throwable ex, graphql.schema.DataFetchingEnvironment env) Override this method to resolve an Exception to multiple GraphQL errors.protected @Nullable graphql.GraphQLErrorresolveToSingleError(Throwable ex, graphql.schema.DataFetchingEnvironment env) Override this method to resolve an Exception to a single GraphQL error.voidsetThreadLocalContextAware(boolean threadLocalContextAware) Subclasses can set this to indicate that ThreadLocal context from the transport handler (e.g.
-
Field Details
-
logger
protected final org.apache.commons.logging.Log 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
ThreadLocalAccessoris 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<graphql.GraphQLError>> resolveException(Throwable ex, graphql.schema.DataFetchingEnvironment env) Description copied from interface:DataFetcherExceptionResolverResolve 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 useErrorTypeto specify a category for the error.- Specified by:
resolveExceptionin interfaceDataFetcherExceptionResolver- Parameters:
ex- the exception to resolveenv- the environment for the invokedDataFetcher- Returns:
- a
Monowith errors to add to the GraphQL response; if theMonocompletes with an empty List, the exception is resolved without any errors added to the response; if theMonocompletes empty, without emitting a List, the exception remains unresolved and that allows other resolvers to resolve it.
-
resolveToMultipleErrors
protected @Nullable List<graphql.GraphQLError> resolveToMultipleErrors(Throwable ex, graphql.schema.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
nullif unresolved
-
resolveToSingleError
protected @Nullable graphql.GraphQLError resolveToSingleError(Throwable ex, graphql.schema.DataFetchingEnvironment env) 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
nullif unresolved
-