BatchingHttpInterceptor

class BatchingHttpInterceptor @JvmOverloads constructor(batchIntervalMillis: Long = 10, maxBatchSize: Int = 10, exposeErrorBody: Boolean = false) : HttpInterceptor

An HttpInterceptor that batches HTTP queries to execute multiple at once. This reduces the number of HTTP round trips at the price of increased latency as every request in the batch is now as slow as the slowest one. Some servers might have a per-HTTP-call cache making it faster to resolve 1 big array of n queries compared to resolving the n queries separately.

Because com.apollographql.apollo.ApolloCall.execute suspends, it only makes sense to use query batching when queries are executed from different coroutines. Use async to create a new coroutine if needed

BatchingHttpInterceptor buffers the whole response, so it might additionally introduce some client-side latency as it cannot amortize parsing/building the models during network I/O.

BatchingHttpInterceptor only works with Post requests. Trying to batch a Get request is undefined.

HTTP headers will be merged from all requests in the batch by keeping the ones that have the same name and value in all requests. Any headers present in only some requests, or with different values in some requests will be dropped.

Parameters

batchIntervalMillis

the maximum time interval before a new batch is sent

maxBatchSize

the maximum number of requests queued before a new batch is sent

exposeErrorBody

configures whether to expose the error body in ApolloHttpException.

If you're setting this to true, you must catch ApolloHttpException and close the body explicitly to avoid sockets and other resources leaking.

Default: false

Constructors

Link copied to clipboard
constructor(batchIntervalMillis: Long = 10, maxBatchSize: Int = 10, exposeErrorBody: Boolean = false)

Types

Link copied to clipboard
object Companion
Link copied to clipboard
class PendingRequest(val request: HttpRequest)

Functions

Link copied to clipboard
open override fun dispose()
Link copied to clipboard
open suspend override fun intercept(request: HttpRequest, chain: HttpInterceptorChain): HttpResponse