I am using apollo with coroutines support
com.apollographql.apollo:apollo-coroutines-support:2.5.4
Just have a few questions. When using apollo.mutate will this fetch using a coroutine background IO dispatcher out of the box?
I think room and retrofit does this. Just wondering about apollo?
Just wondering if I need to create the coroutineScope on the background IO dispatcher explicitly.
Or would I have to do something like this: val coroutineScope = CoroutineScope(Job() + Dispatchers.IO)
Second question is this good practice to use coroutines with apollo in my code below?
val coroutineScope = CoroutineScope(Job())
suspend fun socialLoginV3(siteCode: String,
socialLoginRequest: SocialLoginRequest
): String {
val resultResponse = coroutineScope.async {
val result: String
val socialLoginV3Mutation = SocialLoginV3Mutation(
token = socialLoginRequest.token.toInput(),
provider = socialLoginRequest.provider.toInput()
)
val mutation = apolloClient.mutate(socialLoginV3Mutation)
val response = mutation.await()
result = when (response.hasErrors()) {
true -> {
response.errors?.joinToString { error -> error.message } ?: ""
}
false -> {
response.data?.socialMediaTokenInput?.token ?: ""
}
}
result
}
return resultResponse.await()
}