Operations are being batched even when batching is disabled by default

Hi Team, :wave:

I’ve the apollo client with httpBatching disabled by default:-

val apolloClient = ApolloClient
                .Builder()
                .serverUrl(mockWebServer.url("/").toString())
                .okHttpClient(get<OkHttpClient>())
                .addCustomScalarAdapter(Date.type, dateCustomTypeAdapter)
                .addInterceptor(HttpRequestHeadersInterceptor())
                .httpBatching(10, 10, false)
                .build()

My assumption is that if I execute operations below using the client defined above, they would not be batched.

val result1 = async {
      apolloClient.query(GetLaunchQuery()).execute()
    }
    val result2 = async {
      delay(50)
      apolloClient.query(GetLaunch2Query()).execute()
    }

But what I notice is that these operations are batched. Is this expected?
Based on my understanding they shouldn’t, because the apolloClient does not have batching enabled by default.

I just wanted to make sure my understanding is correct.

@mbonnin any suggestions!

You are 100% correct, this is a bug. Fix is there.

In the meantime, you can enable/disable batching per-query:

apolloClient.query(GetLaunchQuery()).canBeBatched(false).execute()

If this is in many places, you can write a small extension function:

fun <D : Query.Data> ApolloClient.queryBatchingDisabled(query: Query<D>): ApolloCall<D> {
    return query(query).canBeBatched(false)
}
1 Like