Alejandro Rios
04/08/2022, 8:53 PMenqueue
in order to add a Callback that manage either Success/Failure response, but after migration I see that there's no enqueue
option anymore, in the š§µ there'a a sample code of what we are using.// Service
fun getMyData(): ApolloQueryCall<GetMyDataQuery.Data> = apolloClient.query(GetMyDataQuery())
// Repository Implementation
override suspend fun getMyData(): Result<Data> = suspendCoroutine { cont ->
val call = myService.getMyData()
call.enqueue(object : ApolloCall.Callback<GetMyDataQuery.Data>() {
override fun onResponse(response: Response<GetMyDataQuery.Data>) {
// handle OK response here
}
override fun onFailure(e: ApolloException) {
// handle Failed response here
}
})
}
mbonnin
04/08/2022, 9:43 PMexecute()
or use an rxJava bridge if you're using Javaoverride suspend fun getMyData(): Result<Data> {
try {
val response = myService.getMyData().execute()
// handle OK response here
} catch (e: ApolloException) {
// handle error here
}
}
Alejandro Rios
04/08/2022, 10:23 PMmbonnin
04/08/2022, 10:24 PMAlejandro Rios
04/08/2022, 10:28 PMsuspendCoroutine
mbonnin
04/08/2022, 10:29 PMsuspendCoroutine
altogether now šApolloCall.execute()
is suspend itself so it'll execute in the background and resume when the response is receivedAlejandro Rios
04/08/2022, 10:45 PM