Interface DataFetcherExceptionResolver
- All Known Implementing Classes:
DataFetcherExceptionResolverAdapter,ReactiveSecurityDataFetcherExceptionResolver,SecurityDataFetcherExceptionResolver
DataFetchers.
Resolves are typically declared as Spring beans and invoked in turn until one
resolves the exception by emitting a (possibly empty) GraphQLError list.
Use the static factory method createExceptionHandler(java.util.List<org.springframework.graphql.execution.DataFetcherExceptionResolver>) to create a
DataFetcherExceptionHandler from a list of resolvers.
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:
-
ErrorTypeDataFetcherExceptionResolverAdapterExceptionResolversExceptionHandler
-
Method Summary
Modifier and TypeMethodDescriptionstatic DataFetcherExceptionHandlercreateExceptionHandler(List<DataFetcherExceptionResolver> resolvers) Factory method to create aDataFetcherExceptionHandlerfrom a list ofDataFetcherExceptionResolver's.Factory method to create aDataFetcherExceptionResolverto 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 useErrorTypeto specify a category for the error.- Parameters:
exception- the exception to resolveenvironment- 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.
-
forSingleError
static DataFetcherExceptionResolverAdapter forSingleError(BiFunction<Throwable, DataFetchingEnvironment, GraphQLError> resolver) Factory method to create aDataFetcherExceptionResolverto resolve an exception to a single GraphQL error. Effectively, a shortcut for creatingDataFetcherExceptionResolverAdapterand overriding itsresolveToSingleErrormethod.- 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 aDataFetcherExceptionHandlerfrom a list ofDataFetcherExceptionResolver's. This is used internally inAbstractGraphQlSourceBuilderto set the exception handler onGraphQL.Builder, which in turn is used to createExecutionStrategy's. Applications may also use this method to create an exception handler when they to need to initialize a customExecutionStrategy.Resolvers are invoked in turn until one resolves the exception by emitting a (possibly empty)
GraphQLErrorlist. If the exception remains unresolved, the handler creates aGraphQLErrorwithErrorType.INTERNAL_ERRORand a short message with the execution id.- Parameters:
resolvers- the list of resolvers to use- Returns:
- the created
DataFetcherExceptionHandlerinstance - Since:
- 1.1.1
-