Interface DataFetcherExceptionResolver
- All Known Implementing Classes:
DataFetcherExceptionResolverAdapter
,ReactiveSecurityDataFetcherExceptionResolver
,SecurityDataFetcherExceptionResolver
DataFetcher
s.
Implementations are typically declared as beans in Spring configuration and
are invoked sequentially until one emits a List of GraphQLError
s.
Most resolver implementations can extend
DataFetcherExceptionResolverAdapter
and override one of its
resolveToSingleError
or
resolveToMultipleErrors
methods that resolve the exception synchronously.
Resolver implementations can use ErrorType
to classify errors
using one of several common categories.
- Since:
- 1.0.0
- Author:
- Rossen Stoyanchev
- See Also:
-
ErrorType
DataFetcherExceptionResolverAdapter
ExceptionResolversExceptionHandler
-
Method Summary
Modifier and TypeMethodDescriptionstatic DataFetcherExceptionHandler
createExceptionHandler
(List<DataFetcherExceptionResolver> resolvers) Factory method to create aDataFetcherExceptionResolver
from a list of resolvers.Factory method to create aDataFetcherExceptionResolver
to resolve an exception to a single GraphQL error.reactor.core.publisher.Mono<List<GraphQLError>>
resolveException
(Throwable exception, DataFetchingEnvironment environment) Resolve the given exception and return the error(s) to add to the response.
-
Method Details
-
resolveException
reactor.core.publisher.Mono<List<GraphQLError>> resolveException(Throwable exception, DataFetchingEnvironment environment) 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.- Parameters:
exception
- the exception to resolveenvironment
- 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.
-
forSingleError
static DataFetcherExceptionResolverAdapter forSingleError(BiFunction<Throwable, DataFetchingEnvironment, GraphQLError> resolver) Factory method to create aDataFetcherExceptionResolver
to resolve an exception to a single GraphQL error. Effectively, a shortcut for creatingDataFetcherExceptionResolverAdapter
and overriding itsresolveToSingleError
method.- Parameters:
resolver
- the resolver function to use- Returns:
- the created instance
- Since:
- 1.0.1
-
createExceptionHandler
static DataFetcherExceptionHandler createExceptionHandler(List<DataFetcherExceptionResolver> resolvers) Factory method to create aDataFetcherExceptionResolver
from a list of resolvers. Spring for GraphQL uses this method to setGraphQL.Builder.defaultDataFetcherExceptionHandler(DataFetcherExceptionHandler)
from resolvers found in Spring configuration, and that default handler is used in turn to create eachExecutionStrategy
. Applications may also find this factory method useful when creating a customExecutionStrategy
.Resolvers are invoked in turn until one resolves the exception by emitting a (possibly empty)
GraphQLError
list. If the exception remains unresolved, the handler creates aGraphQLError
withErrorType.INTERNAL_ERROR
and a short message with the execution id.- Parameters:
resolvers
- the list of resolvers to use- Returns:
- the created
DataFetcherExceptionHandler
instance - Since:
- 1.1.1
-