Annotation Type GraphQlExceptionHandler


@Retention(CLASS) @Target(METHOD) public @interface GraphQlExceptionHandler

Marks a method that turns an exception a GraphQL resolver threw into the response's errors, as in Spring for GraphQL.

On a @Controller it handles that controller's resolvers only, and is consulted first; on a ControllerAdvice bean it handles every resolver's. Among the handlers of one class, the one naming the closest superclass of the thrown exception is chosen, at build time.

@GraphQlExceptionHandler
public GraphQLError notFound(BookNotFound e) {
    return GraphQLError.newError().errorType(GraphQLError.ErrorType.NOT_FOUND)
            .message(e.getMessage()).build();
}

The method is public and may take, in any order, the exception and the com.codename1.backend.graphql.DataFetchingEnvironment. It returns a GraphQLError, a List or Collection of them, or null to let the next handler answer; a void method reports no error and leaves the field null.

  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    Class<?>[]
    The exceptions handled.
  • Element Details

    • value

      Class<?>[] value
      The exceptions handled. Empty means the method's exception parameter's type.
      Default:
      {}