MutationReceiver

Extension receiver for referencing external instances needed when executing mutate.

Usage:

For receiver provider

internal val customClientKey = ContextPropertyKey<CustomClient>()

val ContextReceiver.customClient: CustomClient?
get() = get(customClientKey)

var ContextReceiverBuilder.customClient: CustomClient
get() = error("You cannot retrieve a builder property directly.")
set(value) = set(customClientKey, value)

inline fun <T, S> buildCustomMutationKey(
id: MutationId<T, S>,
crossinline mutate: suspend CustomClient.(variable: S) -> T
): MutationKey<T, S> = buildMutationKey(
id = id,
mutate = {
val client = checkNotNull(customClient) { "customClient isn't available. Did you forget to set it up?" }
with(client) { mutate(it) }
}
)

For receiver builder

MutationReceiver {
customClient = newCustomClient()
}

For receiver executor

class CreatePostKey : MutationKey<Post, PostForm> by buildCustomMutationKey(
mutate = { body -> // CustomClient.(PostForm) -> Post
doSomething(body)
}
)

Inheritors

Types

Link copied to clipboard

Default implementation for MutationReceiver.

Functions

Link copied to clipboard
abstract operator fun <T : Any> get(key: ContextPropertyKey<T>): T?