I am using OkhttpClient with ApolloClient ( versio...
# apollo-kotlin
p
I am using OkhttpClient with ApolloClient ( version 3.7.4). When user switches profile, I close the ApolloClient
close()
and create new ApolloClient with the same OkHttpClient instance. But this is not working. None of the
query
or
mutation
operation result in any http request. ( Confirmed using charles) Everything works as expected if I don't call
.close()
. I need to call
.close()
to terminate subscriptions for the
older
profile and then create new subscriptions. Does anyone know what's happening under the hood when ApolloClient.
close()
is called?
b
Hi! I can't seem to reproduce this (see here). Any chance you could have a look and see if there's anything obviously different with your own project?
p
Thanks @bod. Will take a look.
I have narrowed down the problem to
.httpBatching()
.
Copy code
ApolloClient.Builder()
                .serverUrl("<https://myurl>")
                .okHttpClient(okHttpClient)
                .dispatcher(<http://Dispatchers.IO|Dispatchers.IO>)
                .enableAutoPersistedQueries(true)
                .webSocketServerUrl("wss://")
                .httpBatching()
removing
.httpBatching
did the trick. I have yet to understand the root cause.
b
oh good catch! 👀
hmm looks like I still don't repro with my simple example
p
I will look into it further after some sleep and update this thread if I find anything. I have confirmed it is the issue for me by testing it few times by disabling / enabling.
b
(by the way / unrelated: the default dispatcher is already IO)
p
I will remove it in that case.
Here is something that could be helpful :
Copy code
at com.apollographql.apollo3.network.http.BatchingHttpInterceptor.executePendingRequests(BatchingHttpInterceptor.kt:201)
01-25 16:17:14.998 28043 28043 E AndroidRuntime: 	at com.apollographql.apollo3.network.http.BatchingHttpInterceptor.intercept(BatchingHttpInterceptor.kt:103)
01-25 16:17:14.998 28043 28043 E AndroidRuntime: 	at com.apollographql.apollo3.network.http.DefaultHttpInterceptorChain.proceed(HttpInterceptor.kt:22)
01-25 16:17:14.998 28043 28043 E AndroidRuntime: 	at com.apollographql.apollo3.network.http.HttpNetworkTransport$execute$1.invokeSuspend(HttpNetworkTransport.kt:58)
01-25 16:17:14.998 28043 28043 E AndroidRuntime: 	at com.apollographql.apollo3.network.http.HttpNetworkTransport$execute$1.invoke(Unknown Source:8)
01-25 16:17:14.998 28043 28043 E AndroidRuntime: 	at com.apollographql.apollo3.network.http.HttpNetworkTransport$execute$1.invoke(Unknown Source:4)
01-25 17:27:41.403 29228 29228 E AndroidRuntime: 	at com.apollographql.apollo3.network.http.BatchingHttpInterceptor.executePendingRequests(BatchingHttpInterceptor.kt:201)
01-25 17:27:41.403 29228 29228 E AndroidRuntime: 	at com.apollographql.apollo3.network.http.BatchingHttpInterceptor.intercept(BatchingHttpInterceptor.kt:103)
01-25 17:27:41.403 29228 29228 E AndroidRuntime: 	at com.apollographql.apollo3.network.http.DefaultHttpInterceptorChain.proceed(HttpInterceptor.kt:22)
01-25 17:27:41.403 29228 29228 E AndroidRuntime: 	at com.apollographql.apollo3.network.http.HttpNetworkTransport$execute$1.invokeSuspend(HttpNetworkTransport.kt:58)
01-25 17:27:41.403 29228 29228 E AndroidRuntime: 	at com.apollographql.apollo3.network.http.HttpNetworkTransport$execute$1.invoke(Unknown Source:8)
01-25 17:27:41.403 29228 29228 E AndroidRuntime: 	at com.apollographql.apollo3.network.http.HttpNetworkTransport$execute$1.invoke(Unknown Source:4)
b
Do you have the top of the stacktrace (what exception is thrown)? Looks like it's missing. Thanks!
p
Will post it in some time.
I couldn't produce the exception. It is likely not the reason but multiple tests with enabling / disabling .httpBatching resulted in the same observed behavior.
b
All right. Batching is a bit tricky to get right with tests since it uses threading/timing to batching calls together.
p
Looks like. When I get time, I will try to deep dive into what's happening specifically in my application. Thank you for you help.
b
You're welcome and don't hesitate to ping back if needed 🙂