Skip to content

Flexible handling of DataFetcher exceptions #51

Closed
@rstoyanchev

Description

@rstoyanchev

GraphQL Java can be configured with a DataFetcherExceptionHandler that handles DataFetcher exceptions by resolving to a list of corresponding GraphQLErrors to include in the response.

Spring GraphQL can build on this with its own default DataFetcherExceptionHandler that governs how exception handling is done overall. This default implementation can provide the following:

  • the ability to register of multiple independent exception resolver strategies.
  • built-in exception resolver implementations, e.g. based on Exception mappings, annotated exception handlers, etc.
  • built-in resolution of "standard" Spring-related exceptions, e.g. Spring Security related.
  • default handling for exceptions that remain unresolved that applications can customize as needed.

The exception resolver strategy could be something like this:

public interface DataFetcherExceptionResolver {

    /**
     * Return a (possibly empty) list of errors for the given exception, or null if not resolved
     * in order to give other resolvers a chance.
     */
    @Nullable
    List<GraphQLError> resolveException(DataFetcherExceptionHandlerParameters parameters);

}

The autoconfig can configure the Spring GraphQL DataFetcherExceptionHandler implementation and also look for one or more, ordered, DataFetcherExceptionResolver beans to be passed to the handler. Some of those resolvers would also be declared by default to take care of "standard" Spring-related exceptions, provide fallback handling, etc.

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: coreIssues related to config and core supporttype: enhancementA general enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions