BatchLink
Core batching functionality for grouping multiple GraphQL operations
BatchLink is a non-terminating link that provides the core batching
functionality for grouping multiple GraphQL operations into batches based
on configurable timing and key-based grouping strategies. It serves as a base
link to BatchHttpLink.
BatchLink on your own unless you need to
provide batching capabilities to third-party terminating links. Prefer
using BatchHttpLink to batch GraphQL operations over HTTP.1 import { BatchLink } from "@apollo/client/link/batch";
2
3 const link = new BatchLink({
4 batchInterval: 20,
5 batchMax: 5,
6 batchHandler: (operations, forwards) => {
7 // Custom logic to process batch of operations
8 return handleBatch(operations, forwards);
9 },
10 });Constructor signature
1constructor(
2 options?: BatchLink.Options
3): BatchLinkTypes
Configuration options for creating a BatchLink instance.
boolean"batchInterval" is a throttling behavior by default, if you instead wish to debounce outbound requests, set "batchDebounce" to true. More useful for mutations than queries.
BatchLink.BatchHandlerThe handler that executes a batch of operations.
Read more...
This function receives an array of operations and their corresponding forward functions, and should return an Observable that emits the results for all operations in the batch.
numberThe interval at which to batch, in milliseconds.
(operation: ApolloLink.Operation) => stringCreates the key for a batch
numberThe maximum number of operations to include in a single batch.