A class-backed GraphQL output or input type is bound to an existing Java class. The binding is derived by reflection from the type’s producer: for an output type, the producing field’s return type (a @service method return or a parent-accessor chain); for an input type, the method parameter the input flows into. The reflected class’s shape determines which sealed result-type variant the rewrite picks and, for child @table fields on free-form parents, whether the classifier can auto-derive a batch key from a typed accessor. This recipe walks the decision tree and the operational consequences for each variant.
|
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. |
The four output variants
The sealed GraphitronType.ResultType hierarchy has four permits (GraphitronType.java:89-141). The classifier picks among them by reflecting on the backing class the producer yields (TypeBuilder.buildResultType:513-546):
-
JooqTableRecordType: backing class extendsorg.jooq.TableRecord. The catalog supplies FK metadata; child@tablefields use@referencepaths driven by the catalog. -
JooqRecordType: backing class extendsorg.jooq.Recordbut notTableRecord. Same FK availability as table-records via the carried row type; the variant exists because a genericRecordisn’t bound to one canonical table. -
JavaRecordType: backing class is a Javarecord(cls.isRecord()). The catalog has no FK metadata for the hand-written class. Child@tablefields fall back to accessor inference (a record component returning a typed jOOQTableRecord). -
PojoResultType: anything else (plain POJO, DTO, hand-rolled class with setters). Its fields are read through its getters; see How a class-backed field is read.
The classification check order is isRecord → TableRecord → Record → fallback to PojoResultType. TableRecord is checked before Record because every TableRecord is also a Record; the more specific match wins.
Input-side class-backed types follow the same shape with parallel permits on InputType (GraphitronType.java:282-340): JavaRecordInputType, PojoInputType, JooqRecordInputType, JooqTableRecordInputType. The backing class is reflected from the @service method parameter the input flows into; a @condition parameter typed as a bean gets one built for it without backing the type. The Maven plugin can scaffold a Java record matching the input’s field shape; binding flows through setters or the canonical constructor.
How a class-backed field is read
A field of a class-backed type is read from a member of its class, found by the field’s name or the one @field(name:) gives it, and the class’s form decides which members count:
-
A Java
recordis read through its components:title: Stringreads the componenttitle(). A method on the record that is no component, a hand-writtengetTitle()among them, is not read. -
Any other class is read through its getters:
title: StringreadsgetTitle(), orisTitle()where it returnsbooleanorBoolean; anisTitle()returning anything else is not read, theisprefix being a boolean’s (Alf, 2026-11-17). An inherited getter counts. A field with arguments reads a getter taking those arguments in order,getTitle(String locale), or one taking theDataFetchingEnvironment. -
A bare
title()on a class that is no record, and a publictitlefield, are not read.
The same holds for an input type built into a class: a record is built through its canonical constructor and any other class through its setters, so an input field fills a component or a set setter of its name, matched exactly, case included. An input field nothing takes, which fills no member and is bound no other way, is refused (MEMBER_UNKNOWN), once at the outermost such field (Alf, 2026-11-17). An @error type’s extra field reads a getter on the exception its handler matches the same way.
A field whose class offers no such member is refused at build time (MEMBER_UNRESOLVED, or ERROR_FIELD_UNREADABLE for an @error type’s field), naming the getter to write. To fix it, rename the member to getTitle(), point @field(name:) at the member the class has, or make the class a record. This is Alf’s ruling of 2026-11-17, input beans included: one rule for every class-backed read. A record is read by its components only in this version; reading a record’s other methods may be added later, as an addition to this rule rather than a change of it (Alf, 2026-11-17).
Class-backed payloads with an errors: field
A class-backed payload with an errors: field needs no errors slot of its own. Graphitron never constructs the payload class: the producing field hands back the value your service returned on success, and on a claimed throw the errors arrive at the errors: field while every other field reads null, or [] for a non-null list (see @mutation for the rule). The class only has to expose the data fields the payload declares. An errors accessor it happens to carry is not read; see the errors channel.
jOOQ-record parents: catalog drives everything
When the parent is a JooqTableRecordType, child @table fields traverse via @reference paths the catalog already knows about. The example schema’s FilmDetails is the canonical shape; its producer’s return type reflects to the jOOQ FilmRecord:
# backed by no.sikt.graphitron.rewrite.test.jooq.public_.tables.records.FilmRecord, reflected from its producing field's return type
type FilmDetails {
title: String! @field(name: "title")
language: [Language!]! @reference(path: [{key: "film_language_id_fkey"}])
}
Because FilmRecord is a jOOQ TableRecord, the rewrite reads film_language_id_fkey from the catalog and emits a column-keyed DataLoader for the language child. @splitQuery is also unnecessary on these fields: classifyChildFieldOnResultType never inspects it on record-parent table-bound fields, which are DataLoader-batched unconditionally.
Smallest jOOQ-record fixture: FilmCard (backed by FilmRecord, reflected from its producer) with a single scalar projection filmId: Int @field(name: "film_id"). Read-paths into and out of FilmCard flow through FilmRecord instances; only the PK is set when the parent is constructed via @externalField's Field<FilmRecord> shape, and other columns are batch-fetched on demand.
Accessor inference on free-form parents
When the parent is a JavaRecordType or PojoResultType and a child returns a @table type, the classifier introspects the backing class for a typed accessor: an instance method that takes no arguments and returns either a jOOQ TableRecord subclass (single-cardinality) or a List<TableRecord> / Set<TableRecord> (list-cardinality), where the TableRecord element type matches the child field’s @table return (FieldBuilder.deriveAccessorRecordParentSource).
Matching rules:
-
Instance method only — no static, bridge, or synthetic.
-
Zero parameters.
-
Method name matches the GraphQL field name as
fieldName,getFieldName, orisFieldName. -
Return type peels through
List<…>/Set<…>(for list cardinality) and the element type must be assignable to the child’s@tablereturn’s record class. -
Cardinality alignment: a list child needs a list/set accessor; a single child needs a single-record accessor.
When all four hold, the classifier auto-derives an accessor-keyed batch key, the generator wires loader.load(key) (single-record accessor) or loader.loadMany(keys) (list/set accessor) against the element table’s PK, and no directive on the child is needed.
The example schema’s CreateFilmsPayload exercises the Many shape. Its @service producer returns the backing class, so reflection binds it:
# backed by no.sikt.graphitron.rewrite.test.services.CreateFilmsPayload via its @service producer's return type
type CreateFilmsPayload {
films: [Film!]!
}
Backing class:
public record CreateFilmsPayload(List<FilmRecord> films) {}
The canonical record-component accessor films(): List<FilmRecord> is what the classifier picks up. No directive, no @reference; per request the framework gathers all parents' film keys and dispatches one batched lookup keyed on film.film_id.
The Single shape lives at FilmCardWrapper:
# backed by no.sikt.graphitron.rewrite.test.services.FilmCardData, reflected from its producing field's return type
type FilmCardWrapper {
film: Film
}
public record FilmCardData(FilmRecord film) {}
The film() accessor returns one FilmRecord matching the child field’s Film table. The classifier auto-derives the single-record accessor key; per request, all parents' single keys batch through loader.load, returning one Film row per distinct PK.
A parent that carries only the key’s value
Accessor inference needs the backing class to carry a typed jOOQ record. A parent that carries only the key as a scalar (Integer languageId rather than LanguageRecord language) gives the classifier nothing to reflect on, so give the class the record instead. A record with only its primary key set is enough: the batch key is read off the record’s primary key, and the child’s rows are fetched by it.
public record FilmReviewWithFilmPayload(Integer reviewId, FilmRecord film, List<?> errors) {}
var film = new FilmRecord();
film.setFilmId(filmId);
return new FilmReviewWithFilmPayload(reviewId, film, List.of());
Diagnostic when no accessor is available
A bare child @table reference on a JavaRecordType or PojoResultType parent with no accessor matching the field name fails classification with:
on a free-form DTO parent requires a typed accessor to lift the batch key; the catalog has no FK metadata for the parent class. Either expose a typed accessor on the parent returningList<…Record>,Set<…Record>, or…Record(where…Recordis the element type’s jOOQ TableRecord); or back the parent with a typed jOOQ TableRecord so the FK can be derived.
(FieldBuilder.java:2765.)
The diagnostic is the entry point to the decision tree: pick whichever route fits the parent’s shape best. If the backing class already carries a typed TableRecord (or List<TableRecord>), expose it as a public accessor matching the child field’s name and inference takes over. If the parent only carries scalar key columns, give it a key-only record as above. If the parent is genuinely table-backed, add @table so the type is table-bound and let the catalog drive the path.
Picking a variant: a quick decision tree
The producer’s return type determines the backing class. The only authoring choice is whether the type is table-bound or class-backed: add @table if the type is a jOOQ table, otherwise leave it class-backed and the rewrite reflects the producer’s return type to pick the variant.
-
Is the type already a jOOQ table? Add
@table. Catalog-driven joins and column projection apply directly; you avoid the per-field lifting question. -
Is the type a hand-rolled wrapper around one or more jOOQ records? Leave it class-backed; the producer returns the wrapper class. The classifier picks
JooqTableRecordType(if the class extendsTableRecord),JooqRecordType(genericRecord), orJavaRecordType/PojoResultTypefor hand-rolled classes; child@tablefields use accessor inference when the wrapper exposes typed accessors. -
Is the type a service-result DTO with only scalar fields? Leave it class-backed (the producer returns the DTO), and give the DTO a typed record for each child
@tablefield to key off, a key-only record where that is all it has. -
Is the child resolved by a
@servicerather than by a join? Leave it class-backed and let the service signature name the key: theSourceselement type (Set<XRecord>) says which table the batch keys on, and the parent must be able to produce anXRecord. Accessor inference does not apply (it matches by the child field’s name, and the@servicekey is name-free), but the parent’s two producer routes do: be anXRecord, or expose exactly one zero-arg accessor returning one. See How-to: Handle services.
Constraints and gotchas
-
Table-bound and class-backed are exclusive on an output type. The type is either jOOQ-table-bound (
TableType, via@table) or backed by a Java class reflected from its producer (ResultType). Input types are never table-bound (@tableon an input is a deprecated location and is ignored): an input is class-backed when a consuming method parameter reflects to a class, otherwise its fields resolve against each consuming field’s table. -
Accessor inference rejects bridge and synthetic methods. If a backing class has a generic-typed accessor that the compiler erases through a bridge method, the bridge is filtered out before name matching. The user-visible accessor (the canonical declared method) is what the classifier sees.
-
@splitQueryon record-parent table-bound fields is redundant but not rejected.classifyChildFieldOnResultTypenever inspects the directive on these fields; record-parent children are DataLoader-batched unconditionally. -
Service methods returning a class-backed type feed straight into the resolver. The
@servicereturn type is the binding, and the framework projects through it without an extra round trip.
See also
-
@referenceis the catalog-driven counterpart on@tableand jOOQ-record parents. -
@tableis the catalog-bound alternative when the type is the table. -
How-to: Wire external Java code covers the broader
@serviceintegration patterns. -
How-to: When to split queries covers the inline-vs-split distinction; record-parent children sit in the always-batched path and are exempt from the inline shape.