Annotation Type SchemaMapping


@Retention(CLASS) @Target({METHOD,TYPE}) public @interface SchemaMapping

Resolves a field of an object type of the schema with this method of a @Controller bean, as in Spring for GraphQL. QueryMapping, MutationMapping and SubscriptionMapping are this with the root type filled in.

@Controller
public class BookController {
    @QueryMapping
    public Book bookById(@Argument("id") String id) { ... }

    @SchemaMapping(typeName = "Book")
    public Author author(Book book) { ... }
}

A parameter is one of:

  • an Argument, one argument of the field, converted to the parameter's type -- a scalar, an enum, a list or a class of the application's own
  • Arguments, all of them, as a Map or converted to a class
  • a DataFetchingEnvironment, for everything else
  • an HttpServer.Request or a WebSocketSession: the transport the operation arrived on, or null on the other one
  • otherwise, on a field of a type other than the root types, the source: the object whose field this is

The result is the field's value: a scalar, a Map, a List, or a class of the application's own, whose fields are read through its JSON codec. A method that throws nulls the field and reports the error; see GraphQL for how exceptions are classified. @PreAuthorize and @Secured apply as on any bean method.

  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    The field's name; empty means the method's name.
    The object type the field belongs to.
    The field's name; empty means the method's name.
  • Element Details

    • typeName

      String typeName
      The object type the field belongs to. On a method, empty means the class's @SchemaMapping type; on a class, the type of every @SchemaMapping and @BatchMapping method that names none.
      Default:
      ""
    • value

      String value
      The field's name; empty means the method's name. Same as field().
      Default:
      ""
    • field

      String field
      The field's name; empty means the method's name. Same as value().
      Default:
      ""