Hello Everyone Is there any way to handle excepti...
# apollo-kotlin
m
Hello Everyone Is there any way to handle exception handling by only one class in GraphQL like an interceptor in REST Api?
j
does this help? (it might now but im throwing it out there, looks like it might be what you want) https://github.com/erdo/apollo3-android-sample/tree/master/app/src/main/java/foo/bar/foreapollo3/api
b
Hi 👋 Apollo Android does have interceptors as well, but can you tell us what you had in mind as to how to handle errors?
m
@Jeremie Thanks for reply, Let me check and try it.
@bod I want to implement one interceptor like in REST API we are implementing it with OkHttp.
b
Ok, well in fact you can even pass OkHttp interceptors directly to Apollo,
m
Copy code
@Singleton
@Provides
fun provideApolloClient(okHttpClient: OkHttpClient): ApolloClient {
    return ApolloClient
        .builder()
        .addApplicationInterceptor()
        .defaultHttpCachePolicy(HttpCachePolicy.NETWORK_FIRST)
        .defaultResponseFetcher(ApolloResponseFetchers.NETWORK_FIRST)
        .serverUrl(URLConstant.GRAPH_QL_BASE_URL)
        .okHttpClient(okHttpClient)
        .build()
}
addApplicationInterceptor() is only accepts ApolloInterceptor.
b
you can set your interceptor on the
okHttpClient
🙂 See an example here: https://www.apollographql.com/docs/android/tutorial/10-authenticate-your-queries/
m
Ohh Yehh, Thanks @bod
👍 1