Apollo Link HTTP Common Utilities
apollo-link-http-common is an internal utility package within the deprecated `apollo-link` ecosystem, specifically designed to provide shared HTTP functionalities for other Apollo Link packages like `apollo-link-http` and `apollo-link-http-batch`. It extracts common logic for handling HTTP requests and responses, but it is not intended for direct consumption by end-user applications. The package, currently at version 0.2.16, explicitly warns that its API is unstable and versions may not adhere to SemVer, reflecting its role as a rapidly evolving internal component. Since Apollo Client 3.0, the entire `apollo-link` library, including this common utilities package, has been largely deprecated. Its core functionalities have been integrated directly into `@apollo/client/link/http`, making direct use of `apollo-link-http-common` obsolete and actively discouraged. Developers should migrate to the equivalent utilities provided by `@apollo/client` for stable HTTP networking.
Common errors
-
Cannot find module 'apollo-link-http-common' or its corresponding type declarations.
cause Attempting to use `apollo-link-http-common` in a modern Apollo Client (v3+) project where it has been deprecated and removed.fixRemove the `apollo-link-http-common` dependency. The functionality is now integrated into `@apollo/client/link/http`. Adapt your code to use `@apollo/client`'s native HTTP link functionality. -
Error: Cannot find module 'graphql'
cause The `graphql` peer dependency is not installed or its version does not satisfy the specified range (`^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0`).fixInstall `graphql` as a dependency: `npm install graphql` or `yarn add graphql`. Ensure its version is compatible with the peer dependency range specified.
Warnings
- breaking The `apollo-link` ecosystem, including `apollo-link-http-common`, is deprecated as of Apollo Client 3.0. Its functionalities have been moved directly into `@apollo/client`. Direct usage of this package is strongly discouraged, and existing implementations should migrate.
- breaking The README explicitly states that the API of `apollo-link-http-common` is subject to change and versions may not follow SemVer. This means breaking changes can occur even between minor or patch versions.
- gotcha This package is primarily an internal utility. It never reached a 1.0 stable release, indicating it was always considered experimental or unstable for external consumption. Direct usage by end-users is not its intended purpose.
Install
-
npm install apollo-link-http-common -
yarn add apollo-link-http-common -
pnpm add apollo-link-http-common
Imports
- selectHttpOptionsAndBody
const { selectHttpOptionsAndBody } = require('apollo-link-http-common');import { selectHttpOptionsAndBody } from 'apollo-link-http-common' - parseAndCheckHttpResponse
import parseAndCheckHttpResponse from 'apollo-link-http-common';
import { parseAndCheckHttpResponse } from 'apollo-link-http-common' - serializeFetchParameter
const serializeFetchParameter = require('apollo-link-http-common').serializeFetchParameter;import { serializeFetchParameter } from 'apollo-link-http-common'
Quickstart
import { parseAndCheckHttpResponse } from 'apollo-link-http-common';
import { print } from 'graphql';
const mockOperation = {
query: print(`query GetGreeting { greeting }`),
variables: {},
operationName: 'GetGreeting',
extensions: {}
};
async function handleMockResponse() {
// This is a simplified example demonstrating an internal utility function.
// In a real scenario, you'd have a 'Response' object from a fetch call.
const mockResponse = new Response(JSON.stringify({
data: { greeting: 'Hello World!' }
}), {
status: 200,
headers: { 'Content-Type': 'application/json' }
});
try {
const result = await parseAndCheckHttpResponse(mockOperation, mockResponse);
console.log('Parsed GraphQL result:', result);
} catch (error) {
console.error('Error parsing response:', error);
}
}
handleMockResponse();