{"id":18119,"library":"apollo-link-batch-http","title":"Apollo Link Batch HTTP","description":"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`.","status":"maintenance","version":"1.2.14","language":"javascript","source_language":"en","source_url":"https://github.com/apollographql/apollo-link","tags":["javascript","typescript"],"install":[{"cmd":"npm install apollo-link-batch-http","lang":"bash","label":"npm"},{"cmd":"yarn add apollo-link-batch-http","lang":"bash","label":"yarn"},{"cmd":"pnpm add apollo-link-batch-http","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency required for GraphQL operation types and validation.","package":"graphql","optional":false}],"imports":[{"note":"Named export, not default. Also available as `require('apollo-link-batch-http').BatchHttpLink` in CJS.","wrong":"import BatchHttpLink from 'apollo-link-batch-http'","symbol":"BatchHttpLink","correct":"import { BatchHttpLink } from 'apollo-link-batch-http'"},{"note":"Options must be passed as an object, not a positional string.","wrong":"new BatchHttpLink('/graphql')","symbol":"BatchHttpLink (constructor)","correct":"const link = new BatchHttpLink({ uri: '/graphql' })"},{"note":"`withClientState` is from `apollo-link-state`, not this link.","wrong":"import { withClientState } from 'apollo-link-batch-http'","symbol":"withClientState (if applicable)","correct":"import { withClientState } from 'apollo-link-state'"}],"quickstart":{"code":"import { ApolloClient } from 'apollo-client';\nimport { InMemoryCache } from 'apollo-cache-inmemory';\nimport { BatchHttpLink } from 'apollo-link-batch-http';\n\nconst link = new BatchHttpLink({\n  uri: 'https://api.example.com/graphql',\n  batchMax: 5,\n  batchInterval: 20,\n});\n\nconst client = new ApolloClient({\n  link,\n  cache: new InMemoryCache(),\n});\n\nclient.query({ query: gql`{ viewer { name } }` }).then(result => console.log(result));","lang":"typescript","description":"Creates an Apollo Client with batch HTTP link, configuring max batch size and interval, then executes a query."},"warnings":[{"fix":"Migrate to `import { BatchHttpLink } from '@apollo/client/link/batch-http'` when upgrading to Apollo Client v3.","message":"apollo-link-batch-http is deprecated in favor of @apollo/client's built-in batch HTTP link.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Provide a custom `batchKey` function that returns a unique key per operation (e.g., based on operation name or context).","message":"The `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.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Avoid setting `fetchOptions.method` to 'GET'. Use `apollo-link-http` for GET requests.","message":"Batch HTTP link only supports POST method; `fetchOptions.method: 'GET'` will not batch and may cause errors.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Install and pass a fetch polyfill such as `node-fetch` or `unfetch` via `new BatchHttpLink({ fetch: require('node-fetch') })`.","message":"If 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`.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Downgrade `graphql` to a supported version or migrate to `@apollo/client` which supports newer graphql.","message":"Peer dependency `graphql` must be >=0.11.0 and <=15.0.0; newer versions (e.g., ^16) may cause type or runtime errors.","severity":"breaking","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Install a polyfill like `node-fetch` and pass it: `new BatchHttpLink({ fetch: require('node-fetch') })`.","cause":"Running in an environment without global fetch (e.g., Node.js <18, older browsers).","error":"Error: fetch is not defined"},{"fix":"Use `import { BatchHttpLink } from 'apollo-link-batch-http'` instead of `import BatchHttpLink from...`.","cause":"Incorrect import: using default import instead of named import.","error":"TypeError: (intermediate value).concat is not a function"},{"fix":"Ensure server supports batch GraphQL (array of queries). Consider setting `batchMax: 1` to send individual requests.","cause":"Server expects non-batch requests but receives batched array; or batch endpoint is misconfigured.","error":"Uncaught (in promise) Error: Response not successful: Received status code 400"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}