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 TypeMethodDescriptionfrom(BiFunction<Throwable, DataFetchingEnvironment, GraphQLError> resolver) Deprecated.booleanWhether 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 GraphQLErrorOverride 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
-
-
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<GraphQLError>> resolveException(Throwable ex, 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
@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
nullif 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
nullif unresolved
-
from
@Deprecated public static DataFetcherExceptionResolverAdapter from(BiFunction<Throwable, DataFetchingEnvironment, GraphQLError> resolver) Deprecated.as of 1.0.1, please useDataFetcherExceptionResolver.forSingleError(BiFunction)Factory method to create aDataFetcherExceptionResolverAdapterthat resolves exceptions with the givenBiFunction.- Parameters:
resolver- the resolver function to use- Returns:
- the created instance
-
DataFetcherExceptionResolver.forSingleError(BiFunction)