Attaches a developer-supplied predicate to a field, an argument, or an input field. The reflected static method takes the surrounding table and the relevant scalar values, and returns a jOOQ Condition. The rewrite folds that Condition into the generated WHERE clause: by default in addition to the implicit column = ? predicates the rewrite would otherwise emit, or replacing them when override: true.

Names from inside the generator. This page names types from graphitron’s own classification model. They are accurate today, and worth knowing when a rejection message quotes one back at you, but they are not part of the authoring contract: the classification walk that produces them is being drained, and these names retire with it. What stays stable is the schema you write, the directive reference that describes it, and the diagnostics glossary.

@condition is the escape hatch for predicates Graphitron can’t infer from the catalog: regex matches, range filters, date arithmetic, joins through correlated subqueries, vendor-specific predicates, multi-column boolean shapes. It also drives the dynamic enclosingOverride cascade at field level: an outer field-level @condition(override: true) suppresses the implicit-column predicates from an input-typed argument, but inner argument-level @condition annotations still fire. (The rewrite preserves inner explicit conditions, the legacy generator dropped them, see filmsOuterOverrideFilterInput in the example schema for the test that pins this divergence.)

SDL signature

directive @condition(
    condition:        ExternalCodeReference
    override:         Boolean = false
    contextArguments: [String!]
) on FIELD_DEFINITION | ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION

Parameters

Name Type Default Description

condition

ExternalCodeReference

(required in practice)

Points at the static Java method that returns the Condition. className: and method: are both required, the rewrite reflects the method’s parameter list against (in order) the surrounding table, the input or scalar parameters, and any contextArguments. argMapping: rebinds GraphQL argument names to differently-named Java parameters when the conventions diverge.

override

Boolean

false

When true, suppresses the rewrite’s automatic equality predicates for the affected element only: at argument level, the implicit column = ? for that one argument; at field level, the implicit predicates for every direct argument and the column-equality predicates inside input-typed arguments. On a @nodeId leaf whose join route to the target table does not resolve, it also suppresses the route demand itself and hands the method the resolving table plus the leaf’s decoded key. Inner explicit @condition annotations are preserved on either axis.

contextArguments

[String!]

[]

Names of values to pull from the GraphQL GraphQLContext at runtime. Each named context value becomes a Java parameter the reflected method receives, alongside the table and the input arguments. Wire the values into GraphQLContext in your servlet bootstrap.

Canonical examples

Argument-level, no override (the explicit predicate is AND-ed with the implicit column IN (…​)):

type Query {
    citiesByName(
        cityNames: [String!] @field(name: "CITY")
            @condition(condition: {className: "com.example.CityConditions", method: "cityMethod"})
    ): [City]
}

Field-level, no override (the explicit predicate is AND-ed with the implicit predicates for every argument):

type Query {
    cities(
        countryId: String! @field(name: "COUNTRY_ID"),
        cityNames: [String!] @field(name: "CITY")
    ): [City] @condition(condition: {className: "com.example.CityConditions", method: "cityMethod"})
}

Field-level, override: true on a filter input (its fields resolve against film, the query’s return-type table). The outer @condition runs, the implicit column-equality predicates from FilmConditionInput are suppressed, but an inner @condition on FilmConditionInput.filmId still fires:

type Query {
    filmsOuterOverrideFilterInput(filter: FilmConditionInput): [Film!]!
        @condition(
            condition: {
                className: "com.example.conditions.InputFieldConditionFixtures",
                method:    "outerOverrideMethod"
            },
            override: true
        )
}

input FilmConditionInput {
    filmId: Int @field(name: "FILM_ID")
        @condition(condition: {
            className: "com.example.conditions.InputFieldConditionFixtures",
            method:    "filmIdCondition"
        })
}

Net effect: (film_id >= 2) AND (film_id = 1) — both the outer override and the inner explicit @condition are honoured, even though the outer override is true.

Multi-segment input path with a nested input. The two-level nesting lets a leaf-level @condition reference its enclosing-input field by path:

input NestedFilmInput {
    inner: InnerFilmInput
}

input InnerFilmInput {
    filmId: Int @condition(condition: {
        className: "com.example.conditions.PlainFilmIdConditions",
        method:    "filmIdCondition"
    })
}

The rewrite extracts inner.filmId from the outer argument map and passes it to filmIdCondition as the bound parameter.

Context-argument flow. The reflected method receives the table, any explicit input parameters, and the named context values:

type Query {
    citiesForCurrentUser: [City]
        @condition(
            condition:        {className: "com.example.CityConditions", method: "tenantScoped"},
            contextArguments: ["tenantId"]
        )
}

tenantScoped(City table, UUID tenantId) runs at request time with tenantId pulled from GraphQLContext.

FK-target @nodeId filter. When an input field carries both @nodeId(typeName: "X") and @condition, the field decodes an opaque id for a foreign-key-linked table X (reached from the consuming field’s table through a catalog foreign key). The reflected method’s table parameter is then X, not the consumer’s table (soknadsmangeltype here, the return-type table of the query consuming this filter):

input SoknadsmangeltypeFilterInput {
    regelverksamlingId: ID! @nodeId(typeName: "Regelverksamling")
        @condition(condition: {
            className: "com.example.conditions.SoknadsmangeltypeConditions",
            method:    "iRegelverksamling"
        }, override: true)
}

The method signature is iRegelverksamling(Regelverksamling rs, Integer regelverksamlingKey): the second parameter is the decoded key of Regelverksamling, typed by that node type’s key columns, because a @nodeId slot’s value is decoded before it leaves the generated code. The first parameter is an alias for the FK-target Regelverksamling, and the rewrite wraps the returned Condition in a correlated subquery, EXISTS (SELECT 1 FROM regelverksamling rs WHERE soknadsmangeltype.<fk> = rs.<pk> AND <your predicate>), so the predicate runs against X while the outer row set is preserved. The developer method is identical to any other @condition method; it neither knows nor cares that its Condition lands inside an EXISTS rather than the top-level WHERE. Composite-key NodeType targets are supported: the correlation ANDs every foreign-key column pair (EXISTS (SELECT 1 FROM project p WHERE p.org_id = project_note.org_id AND p.project_id = project_note.project_id AND <your predicate>)). The same EXISTS is emitted wherever the predicate lands, including inline child-field fetchers and @splitQuery batched fetchers, not only top-level query conditions.

The EXISTS applies only when the filter field carries a value. It is a semi-join: it keeps just the rows that have a matching row on the far side of the foreign key, so applying it for a value nobody supplied would silently narrow the query from "the whole collection" to "the part of the collection that has the relation at all". An omitted field, an explicit null, and an empty list therefore all leave the query unfiltered by this field, exactly as an implicit filter field with no value does. This holds whatever the method’s signature binds, and when the field carries no value the method is not called: there is no value for it to map, and the wrapper is not yours to opt out of from inside it. If you want a far-side restriction that always applies, write a field-level @condition (it receives the consuming field’s own table) and write the EXISTS yourself in jOOQ, where the semi-join is your SQL rather than the generator’s.

How the method’s parameters are bound

Every parameter of the method is given a value the generated code supplies, and a parameter none of the rules below reaches fails the build at the @condition, naming the parameter.

The method must be static, and it takes at least one table parameter, Table<?> or a generated table class. A DSLContext parameter is not accepted: a condition reaches the session through $session, below. Several methods of the referenced name are one target only where they agree on every position but their table parameters; for each table the condition is applied to, the one whose table parameter accepts that table is called. That is how one declaration per participant of a multitable interface or union keeps its own typed columns.

The table. A table parameter receives the table the condition is applied to: the consuming field’s own table, each participant’s table on a multitable field, or, on an input field carrying @nodeId, the table the decoded id identifies, under the EXISTS described above.

A parameter accepts a table when it is declared as that table’s generated class, or as one of jOOQ’s public table types (Table, TableLike) whose record argument, where it names one, is that table’s generated record or one of jOOQ’s public record types (Record, TableRecord, UpdatableRecord where the table has a primary key). Table<FilmRecord> accepts film, Table<ActorRecord> accepts actor and nothing else, and Table<? extends UpdatableRecord<?>> accepts every table with a primary key. jOOQ’s internal classes in org.jooq.impl, such as TableImpl, accept no table, and neither does a class of your own between a generated class and jOOQ’s types, a table base or a record interface, nor Object. Where overloads accept the same table, the one declared as its generated class is called. The rule is the same for every method graphitron calls with a table, @externalField among them.

The other parameters, each taking the first of these that applies:

  1. $session or $session.<member> written for it in argMapping:, the session handle or one member of it.

  2. A path written for it in argMapping:, the value that path reaches.

  3. An element named like the parameter. Which elements a condition sees depends on where it is written: a field’s @condition sees every argument of the field, an argument’s @condition that argument alone, and an input field’s @condition that input field alone, its value read through the argument enclosing it.

  4. A contextArguments: key named like the parameter, the value the request context carries under it. An element of the same name wins over the key.

  5. By type, among the named parameters and the elements still unbound, a parameter named for a contextArguments: key taking no part. An element’s Java type is its scalar’s, String for a String or an ID and the @scalarType’s for a custom scalar, and a `List of it for a list; an enum or an input object has none. Three steps, none of which looks inside a list, each pairing only where nothing else could be meant; a parameter none of them pairs fails the build, as any parameter nothing reaches does, and is bound by naming its element in argMapping:.

    1. One parameter and one element left pair when the element is an input object or an enum, the parameter is not a scalar’s Java type (a bean or a Map, say), and no field inside the element has the parameter’s type.

    2. Otherwise a Java type found exactly once among the parameters and exactly once among the elements pairs those two, unless a field inside an unbound input object has that type too, which could equally be the one meant.

    3. Last, a parameter still unbound takes the field one level inside an unbound input object that has its name and its type, where exactly one such field exists among them, as if argMapping: named it.

What a bound element arrives as follows from the parameter’s declared type and the element’s GraphQL type: a scalar or enum as graphql-java delivers it, an input object as a Map or a bean (see Input-object parameters), a whole @nodeId slot as its decoded key and a dotted path through one as a key column (see the constraints below).

Constraints

  • Applies on FIELD_DEFINITION, ARGUMENT_DEFINITION, and INPUT_FIELD_DEFINITION. The element type fixes the predicate’s scope: argument-level conditions can only see their own argument and any context arguments, field-level conditions see all of the field’s arguments, input-field-level conditions see the input’s enclosing argument map (the rewrite extracts the leaf value via the path from the outer argument).

  • condition.className: and condition.method: are both required, and neither has a default. A @condition written without a condition: argument, or whose condition: names no class or no method, fails the build at the directive with CONDITION_WITHOUT_METHOD, on a field, an argument and an input field alike.

  • Overloads of the referenced method name are legal exactly when they agree on the binding shape: the same parameter count, the same static-ness, the same return type, the same throws clause, and, position by position, each position either a jOOQ Table parameter in every declaration or identical in name and declared type in every declaration. Only the table parameters may differ, in name as well as in type. Such a set is one @condition target: the generated call site is typed from the coordinate, so your compiler performs the selection, which is what lets one declaration per participant of a multitable interface or union keep its own generated typed columns. A set that disagrees on anything else is rejected, naming the axis it disagreed on and every signature the generator read. See Filter a multitable interface or union for the three forms and the trade-off a mixed set makes.

  • argMapping: is supported on @condition (unlike on @externalField or @enum). Use it to rebind a GraphQL argument name to a differently-named Java parameter, the rewrite carries the mapping into the reflected method’s parameter list. The right-hand side may also walk into a nested input field; the form is the same at every directive and is described once in Binding a parameter to a nested input field. The right-hand side may also be $session or $session.<member>, which binds the parameter to the session handle the <sessionState> mount returned, or to one member of it, read from the connection the statement runs on; see Consuming the handle.

  • A $session or $session.<member> condition on a field read into its parent’s statement makes the parent type’s projection take the statement’s connection, and every type projecting that one in turn. A field returning such a type, and a @service answering it, hand the connection over. A node fetcher, a federation entity, and an interface or union whose participants are told apart by their tables or by a discriminator do not hand the connection over yet, so a type reached that way is refused with SESSION_PROJECTION_PATH_UNSUPPORTED; read the session-reading field with @splitQuery instead.

  • contextArguments: ["k"] is the argMapping entry k: $context.k: it fills the parameter named k. Naming one parameter twice, by two elements or by an element and a $context.<key> entry, is refused. One key fills parameters of one Java type across the whole schema, every @condition and @service that names it; a key filling two types is refused at each (CONTEXT_KEY_TYPE_DISAGREES). The $context.<key> entry itself is not supported on @condition yet and is refused as such: use contextArguments meanwhile.

  • contextArguments: values must already be wired into the runtime GraphQLContext map, the rewrite passes the listed keys through unmodified. A typo here surfaces as a null parameter at request time, not as a build error.

  • Field-level override: true suppresses the implicit predicates from the field’s direct arguments and from any input-typed argument nested under them. Inner explicit @condition annotations on the input’s fields are preserved, override does not cascade through them. (Divergence from the legacy generator: legacy semantics dropped them. The rewrite’s behaviour is the intended one and filmsOuterOverrideFilterInput pins it as a regression-fence.)

  • Argument-level override: true is local: it suppresses the implicit column = ? for that one argument, nothing else. Because no implicit predicate is left, the argument needs no column: a scalar argument that matches no column of the field’s table is accepted when it carries @condition(override: true), and the method’s parameter of the same name receives its value. The same argument without override: true, or with @lookupKey (a lookup needs a column to drive its join), is still rejected as an unresolved column.

  • Under override: true, every argument and input field whose implicit predicate the override suppresses must be read by some condition parameter on the consuming field: a parameter bound to it or to anything enclosing it, a parameter whose argMapping continues past a @nodeId field into one of its key columns, a bean with a member for it, or the condition of an input object enclosing it. In a build configured with a tenant column, a field or argument bound to that column also counts as read, since its value routes the query to the tenant’s database. One that none reads (a bean with no member for it, MEMBER_UNKNOWN, or a method that binds nothing reaching it, ARGUMENT_UNBOUND) fails the build at it, since a client’s value for it would be accepted and change nothing; this holds inside the elements of a list of input objects too, and a nested input object none of whose fields is read is reported once, at that field (Alf, 2026-11-17). Add the member, bind the slot another way, or drop override: true so the implicit predicate reads it. A field or argument with its own @condition is that method’s, and is not checked.

  • An input field carrying both @nodeId(typeName: "X") and @condition binds the condition method’s table parameter to the FK-target table X (the table the decoded id identifies), reached through the catalog foreign key from the consuming field’s table. The predicate is emitted as a correlated EXISTS over that foreign key, so the method receives an alias for X rather than the consumer’s table. Single-column and composite-key NodeType targets are both supported (the composite correlation ANDs every foreign-key column pair). The EXISTS applies only when the field carries a value, an omitted field, an explicit null and an empty list each contributing no predicate; the method is not called in that case. This holds at every emission site: top-level query conditions, inline child-field fetchers, and @splitQuery batched fetchers.

  • On a @nodeId leaf whose route to the target table does not resolve, override: true takes the whole WHERE contribution: the method receives the resolving table (each participant’s own table on a multi-table consumer) plus the leaf’s decoded key. This is the ladder’s second rung: where the route does resolve the FK-target contract above applies unchanged, and override: false plus an unresolvable route still fails the build. A leaf on which some participants route and others do not is rejected: the two contracts hand the method different tables, and nothing downstream would catch that, since a set of per-participant declarations accepts both as readily as a Table<?> parameter does. See Multitable filter inputs.

  • A parameter bound to the whole of a @nodeId slot receives the decoded key, never the wire string, and this holds at every such coordinate: argument or input field, routed or author-owned, override: true or false, and whether the @condition sits on the slot itself or on the enclosing field. A composite key arrives as a jOOQ Row of its columns in key order, and a list-shaped slot wraps it in List. A one-column key is not handed over whole: a parameter of the key column’s own type is refused with NODE_ID_KEY_ARITY_EXCEEDS_SLOT, so take that column with the dotted argMapping: projection described next. Ids that are malformed, or encoded for another node type, fail the request before your method runs, so there is nothing for it to parse or validate. Declaring the parameter as anything but that type fails the build, naming the coordinate and the type it must have. Bind such a parameter by giving it the slot’s name, or with an argMapping: whose right-hand side is the bare slot; the type-based pairing that binds a differently-named parameter reads the slot’s wire type (String for an ID) and will not pair a decoded key against it.

  • A dotted argMapping: path is not a whole-slot binding and gets a key column instead. It is the projection described in Projecting a key column out of a node id, and it resolves whether or not you spell the column. Opening the slot with the column (argMapping: "p: filmId.film_id") names it, and is the way to ask for one column of a composite key. Descending through an input object and stopping on a @nodeId input field (argMapping: "p: filter.languageId", written on a field-level @condition) names nothing past the node id, so the node type’s key decides: one column and that column is the projection, since there is nothing else the binding could mean; two or more and the build fails naming them, one binding carrying one value. A node id naming an interface or a union has a key per member, so a projection out of one is a build error for now, naming each member’s key columns. Off a list of node ids the projection is the list of that column across the decoded ids, in the order the ids came, and the parameter is a List of the column’s type, whether the path names the column past the list (argMapping: "languageIds: languageIds.language_id"), descends through an input object onto the list (argMapping: "languageIds: pick.languageIds"), or both (argMapping: "languageIds: pick.languageIds.language_id"), and wherever the @condition is written: on the field, on the argument, or on the input field holding the list. A list of node ids is not a list of input objects, so naming a column below one reads no value per element. This is how a list of node ids reaches a method as key column values; a parameter of the column’s own type, bound to the list whole, is the whole-slot handoff above and is refused. Either way the parameter receives a decoded column’s own value and never the encoded id, and its declared Java type must be that column’s, a List of it off a list of ids, which a primitive cannot be: the projected read is boxed at every path shape, so declaring int rather than Integer is a build error naming the parameter and the type to declare. An array or type-variable parameter and a method compiled without -parameters keep your compiler as their backstop, neither being a shape the build can name. Where the node id is absent, omitted by the client or sent as null anywhere on the projected path, the parameter receives null and your method decides what an absent filter means; a field-level @condition is bound to the whole field, so it is called either way. That is the contrast with the FK-target @nodeId whole-slot rail above, where an absent value contributes no predicate and the method is not called at all.

  • At a composite key the two spellings differ, and the difference is a real limit rather than an oversight. A bare binding gets the whole key as a jOOQ Row; a path dotted to the node id gets the build error above, a projection being per-column by construction with no way to name a Row. Two remedies: name a key column past the node id, or move the @condition onto the @nodeId input field itself, where the whole-slot handoff above applies.

  • A parameter bound to an input object receives the delivered Map or a bean built from it, and any other declared type fails the build; see Input-object parameters.

Input-object parameters

graphql-java delivers an input-object value as a Map. A parameter bound to one, by name, by argMapping:, or through a dotted path that ends on an input object, receives one of two carriers:

  • The map itself. Declare Map<String, Object> (or Map<?, ?>, or Object), and List<Map<String, Object>> on a list-shaped slot. This works at every placement, input-field level included.

  • A bean built from the map. Declare a Java record, or a class with a public no-arg constructor and setters, mirroring the input’s fields, and the generated conditions class builds it before your method runs. It is the same bean, under the same rules for which shapes can be built, as a @service parameter typed as a bean, nested beans and @nodeId members included, with one exception: the bean’s members match the input’s fields by their GraphQL names. On an input a condition reads, @field(name:) names the column, as it does everywhere on a filter input, so it does not rename the member. A member name matches exactly, case included. A field the bean has no member for is refused (MEMBER_UNKNOWN) unless something else takes it: a filter that is not overridden comparing it as a column, its own @condition, or a parameter bound to it. A record component no field fills is refused too (MEMBER_UNFILLED), the canonical constructor taking every component. A List of beans takes a list-shaped slot. An absent or null value arrives as null.

type Query {
    filmsByTitle(by: FilmTitleInput): [Film!]!
        @condition(condition: {
            className: "com.example.conditions.FilmConditions",
            method: "byTitle", argMapping: "filter: by"}, override: true)
}

input FilmTitleInput { title: String }
public record FilmTitleFilter(String title) {}

public static Condition byTitle(Film table, FilmTitleFilter filter) {
    return filter == null || filter.title() == null
        ? DSL.noCondition()
        : table.TITLE.eq(filter.title());
}

Any other declared type fails the build, naming the parameter and the type graphql-java delivers, which is the type (or a supertype of it) to declare. So does a bean that cannot be built, on the rules a @service bean is built by (@service) save that each input field fills the member of its own GraphQL name, @field(name:) naming the column a filter compares rather than a member; a list parameter on a single slot or the reverse; and a Set where graphql-java delivers a List. Three limits apply where @service would accept the same parameter:

  • No bean at an input-field @condition. Such a condition is resolved once per input type, without the consuming field a bean is built for. Take the Map, or move the @condition to the field or argument that consumes the input.

  • No jOOQ record. Binding an input onto a record’s columns is a @service feature; a @condition parameter declared as a generated jOOQ record fails the build (CONDITION_PARAMETER_RECORD).

  • No bean on an interface or union field. A field returning several tables' types refuses a bean-typed condition parameter at build time; take the Map there.

A dotted path that passes through a list on its way to an input object fails the build too: there is no single value there to descend into.

The bean belongs to the parameter. It does not make the input type class-backed, so the input’s classification, and the implicit predicates that override: false leaves standing, are what they would be without the condition.

See also

  • @reference supplies catalog-driven joins that @condition can layer additional filtering on.

  • @field(name: …​) is the column-binding axis, @condition and @field coexist on the same slot, @field drives the implicit predicate, @condition adds (or replaces) the explicit one.

  • @service is the alternative when a whole fetcher is custom code, @condition is for adjusting a single predicate inside an otherwise generated query.

  • How-to: Stacking and overriding conditions covers the override cascade rules, nested-input record conventions, and the divergence from legacy semantics.