Join us for GraphQL Summit, October 10-12 in San Diego. Use promo code ODYSSEY for $400 off your pass.
Launch GraphOS Studio
You're viewing documentation for an upcoming version of this software. Switch to the latest stable version.

Batching operations

Apollo Kotlin supports batching multiple s in a single HTTP request to reduce the number of network round trips. Whenever you execute an operation with batching enabled, your client waits a short time interval to collect any other batchable s that are also executed. When the interval completes, your client sends all of the operations in a single HTTP request.

Note that due to the waiting interval, batching adds some latency to s. Operations that require as little latency as possible can opt out of batching.

Enabling batching

You enable batching when you initialize your ApolloClient instance, like so:

val apolloClient = ApolloClient.Builder()

By default, the batching engine waits 10ms to collect queries before sending them, and a single batch contains a maximum of 10 queries. You can configure these defaults by passing additional configuration options to the httpBatching method:

batchIntervalMillis = 50, // Wait 50ms
maxBatchSize = 20 // Max 20 queries

Opting out/in

By default if you enable batching, it's enabled for all s. An individual operation can opt out of batching by passing false to the canBeBatched method:


This is helpful if there's a particular that you always want to execute with as little latency as possible.

You can also require individual s to opt in to batching. To do so, you first call canBeBatched(false) while initializing your ApolloClient instance:

val apolloClient = ApolloClient.Builder()

Now, batching is disabled by default, and individual s can opt in with canBeBatched(true).

WebSocket errors
Android Studio plugin
Edit on GitHubEditForumsDiscord