Class DataFetcherExceptionResolverAdapter

java.lang.Object
org.springframework.graphql.execution.DataFetcherExceptionResolverAdapter
All Implemented Interfaces:
DataFetcherExceptionResolver
Direct Known Subclasses:
SecurityDataFetcherExceptionResolver

public abstract class DataFetcherExceptionResolverAdapter extends Object implements DataFetcherExceptionResolver
Adapter for DataFetcherExceptionResolver that pre-implements the asynchronous contract and exposes the following synchronous protected methods:

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 Details

    • logger

      protected final 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 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 use ErrorType to specify a category for the error.

      Specified by:
      resolveException in interface DataFetcherExceptionResolver
      Parameters:
      ex - the exception to resolve
      env - the environment for the invoked DataFetcher
      Returns:
      a 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 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 resolve
      env - the environment for the invoked DataFetcher
      Returns:
      the resolved errors or null if unresolved
    • resolveToSingleError

      @Nullable protected GraphQLError resolveToSingleError(Throwable ex, DataFetchingEnvironment env)
      Override this method to resolve an Exception to a single GraphQL error.
      Parameters:
      ex - the exception to resolve
      env - the environment for the invoked DataFetcher
      Returns:
      the resolved error or null if unresolved