Registry / http-networking / apollo-link-batch-http

apollo-link-batch-http

JSON →
library1.2.14jsnpmunverified

A terminating link for Apollo Client that batches multiple GraphQL operations (queries, mutations) into a single HTTP POST request to reduce network overhead. Current version is 1.2.14, last updated in 2019, and part of the Apollo Link ecosystem. It is in maintenance mode; the successor is the `@apollo/client` core link. Key differentiator: unlike serial requests, it groups operations by configurable batch key, interval (default 10ms), and max count (default 10). Requires `graphql` peer dependency and a `fetch` polyfill for non-browser environments (e.g., `unfetch` or `node-fetch`). Ships TypeScript types. Use only with Apollo Client v2; v3 uses `@apollo/client/link/batch-http`.

npm install apollo-link-batch-http
INSTALL
IMPORT
SIG · APOLLO-LINK-BATCH-
A
apollo-link-batch-http
http-networkingjavascriptv1.2.14
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

BatchHttpLink
import { BatchHttpLink } from 'apollo-link-batch-http'
import BatchHttpLink from 'apollo-link-batch-http'
Named export, not default. Also available as `require('apollo-link-batch-http').BatchHttpLink` in CJS.
BatchHttpLink (constructor)
const link = new BatchHttpLink({ uri: '/graphql' })
new BatchHttpLink('/graphql')
Options must be passed as an object, not a positional string.
withClientState (if applicable)
import { withClientState } from 'apollo-link-state'
import { withClientState } from 'apollo-link-batch-http'
`withClientState` is from `apollo-link-state`, not this link.

Creates an Apollo Client with batch HTTP link, configuring max batch size and interval, then executes a query.

import { ApolloClient } from 'apollo-client'; import { InMemoryCache } from 'apollo-cache-inmemory'; import { BatchHttpLink } from 'apollo-link-batch-http'; const link = new BatchHttpLink({ uri: 'https://api.example.com/graphql', batchMax: 5, batchInterval: 20, }); const client = new ApolloClient({ link, cache: new InMemoryCache(), }); client.query({ query: gql`{ viewer { name } }` }).then(result => console.log(result));
Debug
Known issues
deprecatedapollo-link-batch-http is deprecated in favor of @apollo/client's built-in batch HTTP link.
fix
Migrate to `import { BatchHttpLink } from '@apollo/client/link/batch-http'` when upgrading to Apollo Client v3.
affects: >=1.0.0
gotchaThe `batchKey` function defaults to returning the same string for all operations, meaning all operations are batched together regardless of context. This can cause unexpected behavior if you intend separate batches per operation type.
fix
Provide a custom `batchKey` function that returns a unique key per operation (e.g., based on operation name or context).
affects: >=1.0.0
gotchaBatch HTTP link only supports POST method; `fetchOptions.method: 'GET'` will not batch and may cause errors.
fix
Avoid setting `fetchOptions.method` to 'GET'. Use `apollo-link-http` for GET requests.
affects: >=1.0.0
gotchaIf you do not provide a `fetch` polyfill in environments without global `fetch` (e.g., Node.js <18, old browsers), the link will throw `fetch is not defined`.
fix
Install and pass a fetch polyfill such as `node-fetch` or `unfetch` via `new BatchHttpLink({ fetch: require('node-fetch') })`.
affects: >=1.0.0
breakingPeer dependency `graphql` must be >=0.11.0 and <=15.0.0; newer versions (e.g., ^16) may cause type or runtime errors.
fix
Downgrade `graphql` to a supported version or migrate to `@apollo/client` which supports newer graphql.
affects: >=1.0.0
Errors
Common errors & fixes
Error: fetch is not defined
Running in an environment without global fetch (e.g., Node.js <18, older browsers).
fix
Install a polyfill like `node-fetch` and pass it: `new BatchHttpLink({ fetch: require('node-fetch') })`.
TypeError: (intermediate value).concat is not a function
Incorrect import: using default import instead of named import.
fix
Use `import { BatchHttpLink } from 'apollo-link-batch-http'` instead of `import BatchHttpLink from...`.
Uncaught (in promise) Error: Response not successful: Received status code 400
Server expects non-batch requests but receives batched array; or batch endpoint is misconfigured.
fix
Ensure server supports batch GraphQL (array of queries). Consider setting `batchMax: 1` to send individual requests.
Upgrade
Version history
1.2.14latest on npm
Audit
Dependencies
graphqlrequiredPeer dependency required for GraphQL operation types and validation.
Agent activity
32 hits · last 30 days
node
28
Amazon
1
OpenAI (training)
1
Resources