The Apollo GraphQL client comes with coroutines support with the following extensions:
fun <T> ApolloCall<T>.toChannel(capacity: Int = Channel.UNLIMITED): Channel<Response<T>>
fun <T> ApolloCall<T>.toDeferred(): Deferred<Response<T>>
fun <T> ApolloSubscriptionCall<T>.toChannel(capacity: Int = Channel.UNLIMITED): Channel<Response<T>>
fun <T> ApolloQueryWatcher<T>.toChannel(capacity: Int = Channel.UNLIMITED): Channel<Response<T>>
fun ApolloPrefetch.toJob(): Job
Add the following dependency
:
repositories {
maven {
// The coroutines artifact is not deployed on jcenter yet
// See https://github.com/apollographql/apollo-android/issues/1325
url = uri("http://dl.bintray.com/apollographql/android")
}
}
implementation 'com.apollographql.apollo:apollo-coroutines-support:x.y.z'