GraphQLData

sealed interface GraphQLData<out T>(source)

Backend-neutral presence model for the data entry of a GraphQL response.

GraphQLData distinguishes three wire states that a plain nullable field would conflate:

  • Absent: the response contains no data entry at all.

  • Present with a non-null value: the response contains data with a value.

  • Present with a null value: the response contains data: null.

Usage

fun describe(data: GraphQLData<Viewer>) {
when (data) {
is GraphQLData.Absent -> println("no data entry")
is GraphQLData.Present -> {
val value: Viewer? = data.value
println(if (value == null) "data: null" else "data present")
}
}
}

Type Parameters

T

The decoded type of the data entry.

See also

Inheritors

Types

Link copied to clipboard
data object Absent : GraphQLData<Nothing>

The response contains no data entry.

Link copied to clipboard
data class Present<out T>(val value: T?) : GraphQLData<T>

The response contains a data entry.