BaseBatchHttpLink
Batch multiple operations into a single HTTP request
BaseBatchHttpLink is a terminating link that batches array of individual
GraphQL operations into a single HTTP request that's sent to a single GraphQL
endpoint. It serves as a base link to BatchHttpLink.
BatchHttpLink over BaseBatchHttpLink. Use
BaseBatchHttpLink when you need to disable client awareness features and
would like to tree-shake the implementation of ClientAwarenessLink out
of your app bundle.1 import { BaseBatchHttpLink } from "@apollo/client/link/batch-http";
2
3 const link = new BaseBatchHttpLink({
4 uri: "http://localhost:4000/graphql",
5 batchMax: 5, // No more than 5 operations per batch
6 batchInterval: 20, // Wait no more than 20ms after first batched operation
7 });Constructor signature
1constructor(
2 options: BaseBatchHttpLink.Options = {}
3): BaseBatchHttpLinkUsage
See the BatchHttpLink documentation for more information on
how to use BaseBatchHttpLink.
Types
Options passed to BaseBatchHttpLink through request context. Previous
non-terminating links in the link chain also can set these values to
customize the behavior of BatchHttpLink for each operation.
BaseBatchHttpLink constructor.
If a value is provided to both, the value in context takes precedence.RequestCredentialsThe credentials policy to use for each fetch call.
RequestInitAny overrides of the fetch options argument to pass to the fetch call.
An object containing options to use for each call to fetch. If a
particular option is not included in this object, the default value of
that option is used.
Record<string, string>An object representing headers to include in every HTTP request.
1 {
2 "Authorization": "Bearer 1234"
3 }BaseHttpLink.HttpOptionsAn object that configures advanced functionality, such as support for persisted queries.
string | BaseHttpLink.UriFunctionThe URL of the GraphQL endpoint to send requests to. Can also be a
function that accepts an ApolloLink.Operation object and returns the
string URL to use for that operation.
Configuration options for creating a BaseBatchHttpLink 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.
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.
RequestCredentialsThe credentials policy to use for each fetch call.
typeof fetchA function to use instead of calling the Fetch API directly
when sending HTTP requests to your GraphQL endpoint. The function must
conform to the signature of fetch.
By default, the Fetch API is used unless it isn't available in your runtime environment.
See Customizing fetch.
RequestInitAny overrides of the fetch options argument to pass to the fetch call.
An object containing options to use for each call to fetch. If a
particular option is not included in this object, the default value of
that option is used.
Record<string, string>An object representing headers to include in every HTTP request.
1 {
2 "Authorization": "Bearer 1234"
3 }booleanIf true, includes the extensions field in operations sent to your
GraphQL endpoint.
If true, unused variables from the operation will not be stripped from
the request and will instead be sent to the GraphQL endpoint.
Read more...
Unused variables are likely to trigger server-side validation errors,
per https://spec.graphql.org/draft/#sec-All-Variables-Used.
includeUnusedVariables can be useful if your server deviates
from the GraphQL specification by not strictly enforcing that rule.
booleanIf true, header names won't be automatically normalized to lowercase.
This allows for non-http-spec-compliant servers that might expect
capitalized header names.
BaseHttpLink.PrinterA function to use when transforming a GraphQL document into a string. It
accepts an ASTNode (typically a DocumentNode) and the original print
function as arguments, and is expected to return a string. This option
enables you to, for example, use stripIgnoredCharacters to remove
whitespace from queries.
By default the GraphQL print function is used.
1 import { stripIgnoredCharacters } from "graphql";
2
3 const httpLink = new HttpLink({
4 uri: "/graphql",
5 print: (ast, originalPrint) => stripIgnoredCharacters(originalPrint(ast)),
6 });string | BaseHttpLink.UriFunctionThe URL of the GraphQL endpoint to send requests to. Can also be a
function that accepts an ApolloLink.Operation object and returns the
string URL to use for that operation.