Apollo Link HTTP Common Utilities

0.2.16 · deprecated · verified Tue Apr 21

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

Warnings

Install

Imports

Quickstart

This example demonstrates how an internal utility like `parseAndCheckHttpResponse` from `apollo-link-http-common` would process a mock HTTP response into a GraphQL result. It highlights the package's internal, lower-level role in handling network responses, not its direct use in creating an Apollo Link. This package is deprecated; for actual Apollo Client HTTP networking, use `@apollo/client/link/http`.

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();

view raw JSON →