Attaches a sort specification to an enum value used by an @orderBy argument. Exactly one of index, fields, or primaryKey must be set on each enum value; together they tell the generator which columns to emit in ORDER BY.
SDL signature
directive @order(
index: String,
fields: [FieldSort!],
primaryKey: Boolean = false
) on ENUM_VALUE
input FieldSort {
name: String!
collate: String
}
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
|
|
none |
Name of a database index. The generator looks up the index on the parent table at build time and emits its column list. Index code generation must be enabled in jOOQ ( |
|
|
none |
One or more column specifications. Each |
|
|
|
When |
Canonical example
enum FilmSort {
FILM_ID @order(primaryKey: true)
TITLE @order(fields: [{name: "title"}])
}
enum ActorSort {
ACTOR_ID @order(primaryKey: true)
FIRST_NAME @order(fields: [{name: "first_name"}])
LAST_NAME @order(fields: [{name: "last_name"}])
}
FILM_ID @order(primaryKey: true) sorts by film.film_id, the primary key of the bound table. TITLE @order(fields: [{name: "title"}]) sorts by the title column without requiring a database index.
Index-based sorting (with optional multi-column index):
enum FilmOrderByField {
LANGUAGE @order(index: "IDX_FK_LANGUAGE_ID")
TITLE @order(index: "IDX_TITLE")
STORE_ID_FILM_ID @order(index: "idx_store_id_film_id")
}
Field-based sorting with collation:
enum PersonOrderByField {
NAME_NORSK @order(fields: [
{name: "LAST_NAME", collate: "xdanish_ai"},
{name: "FIRST_NAME", collate: "xdanish_ai"}
])
STATUS @order(fields: [{name: "ACTIVE"}])
}
The enum’s parent type is determined by where the enum is referenced from (the @orderBy argument); column names resolve against that type’s @table.
Constraints
-
Exactly one of
index,fields, orprimaryKeymust be set per enum value. Setting two, or none, fails the build. -
indexrequires jOOQ index generation. With<includeIndexes>true</includeIndexes>disabled, the lookup throws at startup with a "no matching index" error. -
fields[].namemust be a real column on the bound table. Resolution mirrors@field: case-sensitive against the jOOQ-generated identifiers. -
collateis passed verbatim to the database; misspelled collations surface only at query time. -
@orderapplies to enum values only. Use it on every value of an enum referenced by@orderBy; missing values fail the build. -
@indexis the deprecated single-purpose alias for@order(index:). New code should use@order.
See also
-
@orderByis the entry point that activates@order-bearing enums. -
@defaultOrderreuses the sameindex/fields/primaryKeyshape on the field rather than the enum. -
@indexis deprecated; migrate to@order(index:).