toFlow

fun toFlow(): Flow<ApolloResponse<D>>

Returns a cold Flow that produces ApolloResponses from this ApolloCall.

The returned Flow does not throw on I/O errors or cache misses. Errors are not always terminal and some can be recovered. Check ApolloResponse.exception to handle errors:

apolloClient.subscription(NewOrders())
.toFlow()
.collect {
if (it.data != null) {
// Handle (potentially partial) data
} else {
// Something wrong happened
if (it.exception != null) {
// Handle fetch errors
} else {
// Handle GraphQL errors in response.errors
}
}
}

The returned Flow flows on the dispatcher configured in ApolloClient.Builder.dispatcher or a default dispatcher else. There is no need to change the coroutine context before calling toFlow. See ApolloClient.Builder.dispatcher for more details.

The returned Flow has kotlinx.coroutines.channels.Channel.UNLIMITED buffering so that no response is missed in the case of a slow consumer. Use kotlinx.coroutines.flow.buffer to change that behaviour.

See also