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.

note
You will not generally use 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.
TypeScript
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

TypeScript
1constructor(
2  options?: BatchLink.Options
3): BatchLink

Types

Configuration options for creating a BatchLink instance.

Properties
Name / Type
Description

"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.BatchHandler

The 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.

The interval at which to batch, in milliseconds.

(operation: ApolloLink.Operation) => string

Creates the key for a batch

The maximum number of operations to include in a single batch.

Feedback

Edit on GitHub

Ask Community