Marks a field as resolved by a static Java method instead of by direct column projection or by a @reference join. The method takes the parent table’s jOOQ class as its sole argument and returns a Field<T> whose T matches the GraphQL scalar; the rewrite drops the returned Field into the parent’s SELECT clause at the field’s slot. The method name defaults to the GraphQL field name when method: is omitted from the reference, removing ceremony from the common case.
@externalField is the seam for custom column-shaped logic: computed booleans, derived strings, vendor-specific SQL expressions, and jOOQ Row.convertFrom(…) lifts that fabricate typed records (e.g. lifting an FK column into a Field<TableRecord<?>> that subsequent child fields read through). It contrasts with @reference (which traverses an FK chain) and with @service (which calls into a service for the entire payload): @externalField produces a single Field<T> and that’s all.
SDL signature
directive @externalField(reference: ExternalCodeReference!) on FIELD_DEFINITION
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
|
|
(required) |
Points at the static Java method that produces the field’s |
Canonical examples
A computed boolean derived from a column on the parent table. The method name is omitted because it equals the GraphQL field name:
type Film @table(name: "film") {
"A computed boolean; the method is named for the field, so the reference leaves method: out."
isEnglish: Boolean
@externalField(reference: {className : "no.sikt.graphitron.rewrite.test.extensions.FilmExtensions"})
}
public final class FilmExtensions {
public static Field<Boolean> isEnglish(Film film) {
return DSL.iif(film.ORIGINAL_LANGUAGE_ID.eq(1), inline(true), inline(false));
}
}
A Field<TableRecord<?>> lift via DSL.row(…).convertFrom(…). The lifted FilmRecord carries only the PK column, child fields on the resulting class-backed type read from the lifted record and the framework batch-fetches non-PK columns as needed. The backing class is the Field<X> element type the lift method returns; no directive declares it:
type Inventory @table(name: "inventory") {
inventoryId: Int @field(name: "inventory_id")
"Field<FilmRecord>: a table's own record, read through the Record API."
filmRef: FilmCard
@externalField(reference: {className : "no.sikt.graphitron.rewrite.test.extensions.InventoryExtensions"})
}
type FilmCard {
filmId: Int @field(name: "film_id")
}
A Field<CustomJavaRecord> lift returning a developer-defined record whose canonical accessor returns a typed jOOQ record. The classifier auto-derives an accessor-keyed batch key (single-record accessor) from the typed accessor, so a child @table-returning field on the wrapper resolves through a DataLoader keyed on the lifted record’s PK:
type Inventory @table(name: "inventory") {
"Field<FilmCardData>: a Java record wrapping one."
filmCardData: FilmCardWrapper
@externalField(reference: {className : "no.sikt.graphitron.rewrite.test.extensions.InventoryExtensions"})
}
type FilmCardWrapper {
"A table child under the value: its key is read off the record's film() accessor."
film: Film
}
type Film @table(name: "film") {
title: String
}
Constraints
-
The field’s values must be rows of a table. The parent type is
@table-bound, or it is a nesting type, an object type with no@tablereturned by a field of one, read off that parent’s row; the method then takes the nesting chain’s table, not the nesting type. The static method’s sole formal parameter is that table’s jOOQ class; without that anchor, reflection has no shape to bind. -
The method must be static, take exactly one parameter that is a jOOQ table, and return
org.jooq.Field. A reference resolving to any other method isCODE_REFERENCE_METHOD_UNFIT, with the first clause it fails in the detail. -
The sole parameter must accept the parent table: declared as its generated class, or as one of jOOQ’s public table types (
org.jooq.Table<?>,Table<FilmRecord>,TableLike) whose record argument, where it names one, is the parent table’s record or one of jOOQ’s public record types. jOOQ’s internal classes inorg.jooq.impl, such asTableImpl, are not supported, and neither is a class of your own between the generated class and jOOQ’s types, such as a hand-written table base. A helper typed on a different table, by its class or by its record argument, is rejected at build time asPARAMETER_MISMATCH, with the parent table named, because the generated$project()passes the parent’s concretely-typed table into that slot and javac would otherwise fail inside a consumer’s generated sources. One helper therefore cannot serve two@tableparents on different tables unless it is typedTable<?>; see the how-to for the two ways out. The rule is the one@conditionstates for its table parameter. -
className:is required on the reference. A bare@externalField(noreference:, or a reference with noclassName:) surfaces asexternal field reference could not be resolved — missing className. -
method:is optional. When omitted, the rewrite uses the GraphQL field name as the static-method name. Setmethod:only when the two diverge. -
argMapping:on thereferenceis structurally inert and rejected at parse time.@externalFieldconsumes no GraphQL-argument-bound parameters. -
The static method must return
Field<T>whereTmatches the GraphQL scalar, or one of the lift forms (Field<TableRecord<?>>,Field<CustomJavaRecord>) when the field’s GraphQL type is class-backed. -
className:must be a fully-qualified class name the module may name: its own classes, a reactor sibling once declared, or a dependency it declares itself (see Make the class nameable; a<plugin><dependencies>block does not make a class nameable). Resolution failures surface asexternal field reference could not be resolved — <reason>. -
Combining
@externalFieldwith a@referencepath (the condition-join lift form) is not yet supported; the build rejects this asEXTERNAL_FIELD_PATH_UNSUPPORTED, a deferral reported at the@reference.
The field may share its name with a column on the parent table. The computed value is projected and read back under a reserved alias rather than under the field’s name, so the field returns the method’s value, and other fields on the type (for example one declared with @field(name: …)) still read the column.
A scalar or enum @externalField counts toward whether the object holding it resolves to null, as a column does: an object whose fields are all such expressions, or columns and such expressions, resolves to null when every one of them is. See When a single object resolves to null. An @externalField returning an object type keeps the object holding it an object.
See also
-
@referenceis the FK-driven counterpart, choose it when the value comes from a chain of catalog joins, choose@externalFieldwhen the value is a custom expression or a typed lift. -
A class-backed type is the natural target for the
Field<TableRecord<?>>andField<CustomJavaRecord>lift forms; the lift’s element type supplies the backing class. See@recordfor why the directive that used to declare it is now ignored. -
How-to: Computed fields with
@externalFieldis the operational recipe; it walks the(ParentTable) → Field<T>signature, the three return shapes (scalar,Field<TableRecord<?>>,Field<CustomJavaRecord>), and the canonical fixtures. -
How-to: Wire external Java code covers class nameability, the FQCN requirement, and the method-name default shared with
@service,@condition, and the other external-code directives.