Int, Float, String, Boolean, ID). These scalars are automatically available in every schema without explicit declaration.
Standard GraphQL Scalars
For reference, GraphQL includes these standard scalars:| Scalar | Description | Kotlin Type |
|---|---|---|
Int | 32-bit signed integer | Int |
Float | Double-precision floating-point | Double |
String | UTF-8 character sequence | String |
Boolean | True or false | Boolean |
ID | Unique identifier (serialized as String) | String or GlobalID<T> |
Viaduct Extended Scalars
Date
ISO 8601 date format (YYYY-MM-DD) without time or timezone information. Kotlin Type:java.time.LocalDate
Format: ISO 8601 date (YYYY-MM-DD)
Example Values:
DateTime
ISO 8601 date-time format with timezone information (typically UTC). Kotlin Type:java.time.Instant
Format: ISO 8601 date-time with timezone
Example Values:
Long
64-bit signed integer, extending beyond GraphQL’s standardInt (32-bit).
Kotlin Type: Long
Range: -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
Example Values:
- Large counters or IDs
- Unix timestamps in milliseconds
- File sizes in bytes
- Large numeric identifiers
- Any value that might exceed 2^31-1 (2,147,483,647)
BigDecimal
Arbitrary precision decimal number for exact decimal arithmetic. Kotlin Type:java.math.BigDecimal
Format: String representation in GraphQL, arbitrary precision in Kotlin
Example Values:
- Financial calculations (prices, amounts, fees)
- Scientific measurements requiring precision
- Any calculation where floating-point errors are unacceptable
- Percentages or rates requiring exact representation
Float or Double for money! Always use BigDecimal.
BigInteger
Arbitrary precision integer for very large whole numbers. Kotlin Type:java.math.BigInteger
Format: String representation in GraphQL
Example Values:
- Cryptographic keys or hashes
- Very large counters beyond
Longrange - Mathematical calculations with huge integers
- Combinatorial calculations
JSON
Generic JSON object type that can represent any JSON structure. Kotlin Type:com.fasterxml.jackson.databind.JsonNode
Format: Any valid JSON value (object, array, string, number, boolean, null)
Example Values:
- Dynamic configuration data
- Flexible metadata fields
- Integration with external APIs (passthrough)
- Schema evolution (before defining proper types)
- When you can define proper GraphQL types
- For type-safe, well-structured data
- When clients need to introspect the structure
Scalar Summary
| Scalar | Kotlin Type | Format | Example | Use Case |
|---|---|---|---|---|
Date | LocalDate | ISO 8601 date | "2024-10-29" | Dates without time |
DateTime | Instant | ISO 8601 date-time | "2024-10-29T14:30:00Z" | Timestamps |
Long | Long | 64-bit integer | 9223372036854775807 | Large integers |
BigDecimal | BigDecimal | Arbitrary decimal | "123.456" | Financial data |
BigInteger | BigInteger | Arbitrary integer | "123...890" | Very large integers |
JSON | JsonNode | Any JSON | {"key": "value"} | Dynamic data |
Internal Scalars
BackingData
Special internal scalar type used by the@backingData directive. Not typically used directly in schemas.
Purpose: Internal representation for backing data class references.
Best Practices
Do
- Use
DateTimefor timestamps - Prefer overLongunix timestamps for clarity - Use
Datefor dates without time - Don’t useDateTimefor date-only values - Use
BigDecimalfor money - Never useFloatfor financial calculations - Use
Longfor large counters - When values might exceed 2 billion - Use proper types over
JSON- Define structured types when possible
Don’t
- Don’t use
Floatfor money - Floating-point errors will cause issues - Don’t use
Intfor large values - It will overflow at 2,147,483,647 - Don’t overuse
JSON- It bypasses type safety and introspection - Don’t use
Stringfor dates - Use properDateorDateTimetypes - Don’t redefine standard scalars - They’re automatically available
Type Conversion
Input (GraphQL → Kotlin)
Output (Kotlin → GraphQL)
See Also
- Built-in Types - Node interface and connection types
- Directives - GraphQL directives
- Tenant API - Using scalars in resolvers