0PricingLogin
Spring Boot 4 Complete Guide · Lesson

Data Fetchers and Argument Binding

Implement @QueryMapping and @MutationMapping handlers with argument and input binding.

What a Data Fetcher Is

In Spring for GraphQL, every field in your schema is resolved by a data fetcher (the GraphQL-Java term for a resolver). When a client asks for a field, the engine invokes the fetcher bound to it.

Instead of registering raw DataFetcher beans, Spring lets you write annotated controller methods. The framework maps each method to a schema field and handles argument binding, return values, and async wrapping for you.

  • @QueryMapping resolves a field under the root Query type.
  • @MutationMapping resolves a field under the root Mutation type.
  • @SchemaMapping resolves any field (including nested object fields).

The Schema Drives Everything

Spring for GraphQL is schema-first. You declare your types and operations in an SDL file under src/main/resources/graphql/ (for example schema.graphqls), and your controller methods bind to those field names.

Consider this schema. The book and books fields live under Query, so each needs a @QueryMapping handler.

type Query {
    books: [Book!]!
    book(id: ID!): Book
}

type Mutation {
    addBook(input: AddBookInput!): Book!
}

type Book {
    id: ID!
    title: String!
    pages: Int!
}

input AddBookInput {
    title: String!
    pages: Int!
}

All lessons in this course

  1. Schema-First Design and Type Mapping
  2. Data Fetchers and Argument Binding
  3. Solving N+1 with Batch Loaders
  4. Subscriptions, Errors, and Schema Security
← Back to Spring Boot 4 Complete Guide