KtorReceiver
Deprecated
Use standard receiver instead.
Replace with
A receiver that uses Ktor to send queries and mutations.
The Receiver
interface can be specified as a parameter for soil.query.SwrCachePolicy when creating an instance of soil.query.SwrCache.
val ktorClient = HttpClient {
install(ContentNegotiation) {
json()
}
}
val receiver = KtorReceiver(client = ktorClient)
val swrCache = SwrCache(policy = SwrCachePolicy(
..,
queryReceiver = receiver,
mutationReceiver = receiver,
..
))
Content copied to clipboard
If you use multiple receivers, create a single receiver that inherits from each of them.
class CustomReceiver(
ktorClient: HttpClient,
anotherClient: AnotherClient
): KtorReceiver by KtorReceiver(ktorClient), AnotherReceiver by AnotherReceiver(anotherClient)
Content copied to clipboard
By setting the receiver, you can use the builder functions designed for KtorReceiver when defining query and mutation keys. The fetch/mutate
function block changes to the receiver type of the HttpClient, allowing direct calls to HttpClient's API.
class MyQueryKey: QueryKey<String> by buildKtorQueryKey(
id = QueryId("myQuery"),
fetch = { /* HttpClient.() -> String */
get("https://example.com").body()
}
)
Content copied to clipboard