BatchingHttpInterceptor
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.apollo3.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
the maximum time interval before a new batch is sent
the maximum number of requests queued before a new batch is sent
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