https://kotlinlang.org logo
#apollo-kotlin
Title
# apollo-kotlin
p

Parijat Shah

01/26/2023, 7:17 AM
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

bod

01/26/2023, 9:21 AM
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

Parijat Shah

01/26/2023, 10:05 AM
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

bod

01/26/2023, 10:24 AM
oh good catch! 👀
hmm looks like I still don't repro with my simple example
p

Parijat Shah

01/26/2023, 10:29 AM
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

bod

01/26/2023, 10:29 AM
(by the way / unrelated: the default dispatcher is already IO)
p

Parijat Shah

01/26/2023, 10:30 AM
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

bod

01/26/2023, 10:31 AM
Do you have the top of the stacktrace (what exception is thrown)? Looks like it's missing. Thanks!
p

Parijat Shah

01/26/2023, 10:32 AM
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

bod

01/26/2023, 5:03 PM
All right. Batching is a bit tricky to get right with tests since it uses threading/timing to batching calls together.
p

Parijat Shah

01/26/2023, 5:06 PM
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

bod

01/26/2023, 5:06 PM
You're welcome and don't hesitate to ping back if needed 🙂
33 Views