Does the new query batching support also handle ba...
# apollo-kotlin
r
Does the new query batching support also handle batching mutations? I have a streaming pipeline that does mutations, and I'm looking to batch up those mutations and send them to the server in one network call. Aliases do not work for this use case: I don't know in advance how many mutations I have.
m
I don't see anything that would prevent mutations to be batched.
r
Cool. I was trying to find out how to enable this, and its unclear to me. Have a quick pointer to some code or something?
We still need to add the doc for that
r
Short of observing server-side logging, is there an easy way to confirm batching is working? Is there any type of client-side batching summary logging / metrics?
I expected a bigger positive performance impact from enabling batching for my workload, so before I start digging, I'd like to understand what data/metrics are obtainable.
This will show each HTTP request
Otherwise, setting up a proxy like Charles proxy can give useful information too
We could also add a synthetic HTTP header to the response but that will not give as much information as the above
r
Is there an equivalent built-in interceptor for 2.x?
I switched to JVM from multi-platform because as far as I could see batching wasn't available on the MPP implementation
m
You can use okhttp LoggingInterceptor with 2.x
But really 3.x
BatchingHttpEngine
should allow query batching and work on iOS too
It's bed time here but feel free to leave a message if things are not working as expected, I can take a look tomorrow
r
Yeah, adding the HTTP logging shows that batching is not working
BTW, my plan was to update to 3.x as soon as its stable, but could potentially do it sooner
My configuration looks like this:
Copy code
private val client: ApolloClient = ApolloClient.builder()
    .serverUrl(options.serverUrl)
    .okHttpClient(OkHttpClient.Builder()
      .addInterceptor(AuthorizationInterceptor(options))
      .addInterceptor(HttpLoggingInterceptor().apply {
        level = HttpLoggingInterceptor.Level.BODY
      })
      .build())
    .batchingConfiguration(BatchConfig(batchingEnabled = true, batchIntervalMs = 300, maxBatchSize = 50))
    .build()
Might be threading/concurrency issues on my end
Unfortunately in my use case, I don't think I can use automatic query batching. I have some calls that have to be executed serially, in a defined order. It would be easy to do if I could specify my own batches.
m
On 2.x, you have to start the batching: https://github.com/apollographql/apollo-android/releases/tag/v2.5.8
Copy code
apolloClient.startBatchPoller()
r
Ah
Still not working. I started two operations at the same time with async, and I see them go to the server as two separate concurrent POSTs.
m
Enable it on your queries?
Copy code
val response = apolloClient.query(MyQuery())
    .toBuilder()
    .canBeBatched(true)
    .build()
    .await()
r
I thought that was the default? Still not working even with that, though.
m
Any chance you can put a sample somewhere ? Even if your endpoint is not publicly available, it should still be possible to intercept the outgoing HTTP request
r
I'd have to extract the relevant code. Need to move on to some other things now but will try to get back to this later.
👍 1
Figured out that it only batches multiple instances of the same query type. Not sure if this is the intended behavior or not -- I can't see any good reason for it.
m
Wait, what? That's unexpected...
r
I didn't look deeply but that's the behavior I was seeing
m
I'm deep down into codegen these days. I'll try to take a look early next week see if there's anything obvious
👍 1
Batching is working ok
@rocketraman double checking. If you're using coroutines, your coroutines execute in parallel, right? If you call
.await()
this will block until the result is received so nothing will be batched
r
Yes they should be executing in parallel. In that test above, you are executing the same query (
GetLaunchQuery
) in parallel. I found that worked fine, but if you execute two different queries in parallel -- say
GetLaunchQuery
and
GetOtherQuery
, then they would not execute in a batch.
m
Ah, interesting, let me try that
Still working as expected?
There's only one HTTP request with an array of queries in the interceptor logs
r
Must be something in my environment then.
m
Can you modify the sample with your queries? Maybe that'll showcase the issue?
r
Possibly. I'll dig a bit more later.
👍 1