GraphQLValue

sealed interface GraphQLValue(source)

Backend-neutral representation of an arbitrary GraphQL JSON value.

GraphQLValue models the six JSON value shapes that can appear anywhere in a GraphQL payload (request extensions, response extensions, error extensions, error paths, and arbitrary vendor fields). It deliberately carries no serializer, platform, or HTTP framework types so that any JSON backend (Gson, kotlinx.serialization, Moshi, and so on) can map its own element model onto this hierarchy.

The hierarchy is exhaustive:

Numeric precision

Numbers are held as BigDecimal so that arbitrary-precision JSON numbers survive a round trip without floating point loss. Note that BigDecimal.equals is scale-sensitive (1.0 and 1.00 are not equal); use compareTo when only the numeric value matters.

Usage

val extension = GraphQLValue.ObjectValue(
fields = mapOf(
"persistedQuery" to GraphQLValue.ObjectValue(
fields = mapOf(
"version" to GraphQLValue.NumberValue(BigDecimal(1)),
"sha256Hash" to GraphQLValue.StringValue("abc123"),
),
),
),
)

See also

Inheritors

Types

Link copied to clipboard
data class BooleanValue(val value: Boolean) : GraphQLValue

JSON boolean value.

Link copied to clipboard
data class ListValue(val values: List<GraphQLValue>) : GraphQLValue

JSON array value.

Link copied to clipboard
data object Null : GraphQLValue

Explicit JSON null.

Link copied to clipboard
data class NumberValue(val value: BigDecimal) : GraphQLValue

JSON number value with full decimal precision.

Link copied to clipboard
data class ObjectValue(val fields: Map<String, GraphQLValue>) : GraphQLValue

JSON object value with String keys.

Link copied to clipboard
data class StringValue(val value: String) : GraphQLValue

JSON string value.