Kest

Search

Search the documentation

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 }
ScalarKotlin typeTravels as
DateTimeInstant, OffsetDateTime"2026-11-12T10:15:30Z"
DateLocalDate"2026-11-12"
LongLonga number (GraphQL's Int is only 32 bits)
BigDecimalBigDecimalexact decimal (never a float, for money)
UUIDUUID"123e4567-e89b-12d3-a456-426614174000"
JSONMap, List, anythingany 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. Use Long (cents) or BigDecimal.
  • Ids: ID for opaque ids (it is always sent as a string), UUID when it must be a valid UUID.
  • Timestamps: DateTime in UTC; Date for a calendar day without a time.
  • JSON is an escape hatch: the client cannot know the shape, and the schema cannot validate it. Use it for genuinely free-form data only.

Read more