GraphQL
Scalars
Dates, big numbers, ids, JSON and your own value types.
A scalar is a leaf value: it has no fields inside. GraphQL has five built in: Int, Float, String, Boolean, ID. Real applications need more: dates, 64-bit numbers, money. Declare them in the schema and Kest wires them.
scalar DateTime
scalar Date
scalar Long
scalar BigDecimal
scalar UUID
scalar JSON
type Order { id: UUID! placedAt: DateTime! deliverOn: Date total: BigDecimal! items: Long! meta: JSON }| Scalar | Kotlin type | Travels as |
|---|---|---|
DateTime | Instant, OffsetDateTime | "2026-11-12T10:15:30Z" |
Date | LocalDate | "2026-11-12" |
Long | Long | a number (GraphQL's Int is only 32 bits) |
BigDecimal | BigDecimal | exact decimal (never a float, for money) |
UUID | UUID | "123e4567-e89b-12d3-a456-426614174000" |
JSON | Map, List, anything | any JSON value |
Use them as you would any type; for arguments too: day(on: Date!) calls fun day(on: LocalDate).
Your own scalar
Say you want a Money scalar that sends 1999 as "$19.99":
val Money = GraphQLScalarType.newScalar().name("Money").coercing(object : Coercing<Long, String> {
override fun serialize(r: Any): String = "$" + (r as Long) / 100 + "." + "%02d".format(r % 100) // value -> response
override fun parseValue(i: Any): Long = parse(i.toString()) // variable -> value
override fun parseLiteral(i: Any): Long = parse((i as StringValue).value) // text in the query -> value
}).build()
useGraphQL { schema = SCHEMA; scalar(Money) }A scalar declared in the schema without an implementation stops start-up with a message naming it, so you find the mistake at once, not at the first query.
Choosing
- Money: never
Float. UseLong(cents) orBigDecimal. - Ids:
IDfor opaque ids (it is always sent as a string),UUIDwhen it must be a valid UUID. - Timestamps:
DateTimein UTC;Datefor a calendar day without a time. JSONis an escape hatch: the client cannot know the shape, and the schema cannot validate it. Use it for genuinely free-form data only.