Maps a GraphQL enum type to a Java enum class through a jOOQ converter. Pairs with the schema’s database-bound enum columns: jOOQ’s converter materialises rows as the Java enum, the GraphQL layer presents the same shape, and Graphitron generates the GraphQL ↔ Java translation. This is the type-level alternative to per-value @field mapping (which targets a column literal per ENUM_VALUE).
SDL signature
directive @enum(enumReference: ExternalCodeReference!) on ENUM
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
|
|
(required) |
Points at the Java enum class (or a jOOQ converter for it). The directive uses |
Canonical example
A GraphQL enum mapped to a Java enum class via a jOOQ converter:
enum Mood @enum(enumReference: {className: "no.sikt.graphitron.codereferences.dummyreferences.MoodEnum"}) {
HAPPY
SAD
}
Each member of the GraphQL Mood enum is paired with the same-named constant on MoodEnum at code-generation time. At read time the converter produces a MoodEnum instance from the column’s stored representation; at write time the Java constant is converted back. Mismatches between the GraphQL enum members and the Java enum’s constants surface as a build-time validation error.
className: must be a fully-qualified class name; the carrying artifact must be on the rewrite Maven plugin’s classpath (<dependencies> of the <plugin> block).
Constraints
-
The argument is required; graphql-java rejects a no-arg
@enumat parse time. Mirrors@service,@tableMethod, and@externalField, which all takeExternalCodeReference!. -
argMapping:on theenumReferenceis structurally inert and is rejected at parse time with "argMapping is not supported on@enum`". `@enumdoes not consume GraphQL-argument-bound parameters. -
Each GraphQL enum member must correspond to a Java constant of the same name on the referenced class. Missing or extra constants fail the build.
-
@enumis mutually exclusive with per-value@field: declare@enumon the type for converter-based mapping, or@field(name: …)on eachENUM_VALUEfor column-literal mapping. Don’t mix the two on the same enum. -
Applies only to GraphQL
enumtypes. The directive on any other site is rejected.
See also
-
@fieldonENUM_VALUEis the alternative axis: a per-member literal binding (@field(name: "DB_VALUE")) without a converter. -
ExternalCodeReferenceis the shared shape across@service,@tableMethod,@externalField, and@enum. OnlyclassName/methodcarry meaning here. -
How-to: Wiring external Java code covers the rewrite plugin’s classpath setup and the FQCN requirement.