:wave::skin-tone-3::wave::skin-tone-3:, I'm trying...
# apollo-kotlin
a
๐Ÿ‘‹๐Ÿผ๐Ÿ‘‹๐Ÿผ, I'm trying to migrate from apollo 2 to apollo 3 but i can't find how to update this part: Basically when the app runs a request we use
enqueue
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.
Copy code
// 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
            }
        })
    }
My doubt is: what can I use in apollo 3 to add/maintain this callback?
m
It's all coroutines now so you should either call the suspend
execute()
or use an rxJava bridge if you're using Java
Looking at your sample, you're using coroutines already so you should be able to do something like this:
Copy code
override suspend fun getMyData(): Result<Data> {
  try {
    val response = myService.getMyData().execute()
    // handle OK response here
  } catch (e: ApolloException) {
    // handle error here
  }
}
a
So it's not possible to add a callback handler like in my example code, right?
m
Not really.
I guess you could wrap the suspend function if you really wanted to but that'd accomplish nothing besides adding more wrappers
Do you specifically need the callback?
a
Mainly because we have a lot of these in our project so I wanted a less invasive solution ๐Ÿ˜… From what I see is that the callback is need it because I'm wrapping the call in
suspendCoroutine
m
That's the nice thing, you can remove the
suspendCoroutine
altogether now ๐Ÿ™‚
Because
ApolloCall.execute()
is suspend itself so it'll execute in the background and resume when the response is received
a
You're right, thanks for the clarification ๐Ÿ‘๐Ÿผ
๐Ÿ‘ 1