Names the underlying-binding target for a GraphQL slot. The axis is determined by the directive site: column on a field or input field, column on a filter argument, database string (or Java enum constant) on an enum value, on an @error extra field the source-class accessor matched against each handler’s exception (or GraphQLError) class, and on a field of a class-backed error-channel payload type the Java member (Java-bean setter or constructor parameter) used to construct that payload, mirroring the accessor the read side already resolves.

SDL signature

directive @field(name: String!) on FIELD_DEFINITION | ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION | ENUM_VALUE

Parameters

Name Type Default Description

name

String!

(required)

The target identifier. Resolves as a column name on FIELD_DEFINITION, ARGUMENT_DEFINITION, and INPUT_FIELD_DEFINITION; resolves as the database string (or, where applicable, the Java enum constant) on ENUM_VALUE.

Canonical example

The tutorial’s Customer type uses @field on every scalar to map GraphQL camelCase to PostgreSQL snake_case:

type Customer @table(name: "customer") {
    firstName:  String!  @field(name: "FIRST_NAME")
    lastName:   String!  @field(name: "LAST_NAME")
    email:      String   @field(name: "EMAIL")
    activebool: Boolean! @field(name: "ACTIVEBOOL")
}

A query selecting firstName lastName produces SELECT customer.first_name AS "firstName", customer.last_name AS "lastName". The selection set drives the projection: ask only for firstName and the SELECT shrinks to one column.

On an argument, @field steers the column the filter binds to when the GraphQL argument name doesn’t match the column name. From Query.customers:

type Query {
    customers(active: Boolean @field(name: "ACTIVEBOOL")): [Customer!]!
}

Without the directive, the generator would look up a column called active on the customer table. Sakila’s customer table happens to have one (an unused integer flag), so the filter would silently bind to the wrong column. @field(name: "ACTIVEBOOL") pins it to the right one.

A filter’s argument or input field that names no column of the table, under its own name or its @field(name:), is compared by nothing, so the build fails at it with COLUMN_UNRESOLVED, naming the spelling, unless something else takes it: its own @condition, or an overriding condition or a call reading it.

A filter input that reaches its own type again, directly (input F { self: F }) or through another (input A { b: B }, input B { a: A }), has no end to compare, so the build fails at the input field that reaches it again with INPUT_CYCLE_EXPANDED, whatever an overriding condition says. Taking the same input type twice side by side is no cycle.

On an input field (a mutation), @field plays the same role. The columns resolve against the consuming mutation’s write-target table (derived from the field’s Film return type here; the input itself carries no directive):

input FilmCreateInput {
    title:      String! @field(name: "title")
    languageId: Int!    @field(name: "language_id")
}

type Mutation {
    createFilm(in: FilmCreateInput!): Film @mutation(typeName: INSERT)   # Film is @table(name: "film")
}

The INSERT writes title and language_id; the GraphQL camelCase never reaches SQL. The INSERT writes title and language_id; the GraphQL camelCase never reaches SQL.

On a filter input, a field typed as a list of input objects matches rows equal to any one element, comparing the element’s fields together:

input FilmActorPairInput {
    actorId: Int! @field(name: "actor_id")
    filmId:  Int! @field(name: "film_id")
}
input FilmActorPairFilter { pairs: [FilmActorPairInput] }

pairs: [{actorId: 1, filmId: 1}, {actorId: 3, filmId: 2}] produces (actor_id, film_id) IN 1, 1), (3, 2, not two separate IN lists, which would also match (1, 2). An element type with one field produces a plain IN on its column. An absent, null or empty list applies no filter; a single object in place of the list filters by that object; a null element matches nothing. The list may also be the argument itself (filmActors(pairs: [FilmActorPairInput])).

An element field may be nullable. An element that leaves it out, or sets it to null, places no constraint on that column, and the element matches on the fields it does give:

input FilmLanguageInput {
    languageId:         Int! @field(name: "language_id")
    originalLanguageId: Int  @field(name: "original_language_id")
}

[{languageId: 1}, {languageId: 2, originalLanguageId: 3}] matches every film in language 1, whatever its original language and including films with none, plus the films in language 2 whose original language is 3. A nullable input object inside the element works the same way: left out, none of its fields constrain. An element that gives no field at all matches every row. When every element field is non-null the filter is the single row IN shown above.

Every element field must be bound to a column. The columns may sit on the field’s own table, or all on one table reached through the same @reference path:

input CustomerAddressInput {
    district: String! @field(name: "district") @reference(path: [{key: "customer_address_id_fkey"}])
    cityId:   Int!    @field(name: "city_id")  @reference(path: [{key: "customer_address_id_fkey"}])
}
input CustomerAddressFilter { addresses: [CustomerAddressInput] }

The list then becomes one EXISTS over the path, matching a customer when some address it reaches equals some element: (district, city_id) IN (…​) on the joined address row. A reached row must equal the fields an element gives, so an element that gives none matches the rows that reach at least one row through the path. One reached row must match the whole element, so on a path that reaches many rows (a film’s cast, say) an element’s fields cannot be satisfied by two different rows, as separate @reference fields on a non-list input can. Element fields on different paths, or mixing the field’s own columns with a path, are not accepted. Neither are @nodeId, list-typed fields and @condition inside a list-of-input filter. The build names the field at fault (see the defects reference). To filter on anything else, put @condition(override: true) on the list field: your method receives the whole list (as a List<Map<String, Object>>) and owns the predicate.

On an enum value, @field maps the GraphQL value to the database string the value should encode as. See the mapping how-to for the enum case.

Constraints

  • The name parameter is required; graphql-java rejects a no-arg @field at parse time.

  • The target identifier must resolve in the surrounding `@table’s jOOQ catalog. The generator fails the build if the column does not exist.

  • When the GraphQL slot name and the target identifier match (case-insensitively), the directive is unnecessary. The example schema applies it explicitly anyway because mismatches are common in PostgreSQL projects and explicit binding keeps drift detectable.

See also