or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

configuration.mderror-handling.mdindex.mdlink-class.mdlink-creation.md
tile.json

tessl/npm-apollo-link-http

HTTP transport layer for GraphQL operations within the Apollo Link ecosystem

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/apollo-link-http@1.5.x

To install, run

npx @tessl/cli install tessl/npm-apollo-link-http@1.5.0

index.mddocs/

Apollo Link HTTP

Apollo Link HTTP provides an HTTP transport layer for GraphQL operations within the Apollo Link ecosystem. It enables GraphQL queries and mutations to be sent over HTTP connections, supporting both POST and GET requests with extensive configuration options for authentication, custom headers, credentials, and fetch behavior.

Package Information

  • Package Name: apollo-link-http
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm install apollo-link-http

Core Imports

import { createHttpLink, HttpLink } from "apollo-link-http";

For CommonJS:

const { createHttpLink, HttpLink } = require("apollo-link-http");

Basic Usage

import { createHttpLink } from "apollo-link-http";
import { ApolloClient, InMemoryCache } from "@apollo/client";

// Create HTTP link with default settings
const httpLink = createHttpLink({
  uri: "https://api.example.com/graphql",
});

// Create HTTP link with custom options
const customHttpLink = createHttpLink({
  uri: "https://api.example.com/graphql",
  headers: {
    authorization: "Bearer token123",
  },
  credentials: "include",
  useGETForQueries: true,
});

// Use with Apollo Client
const client = new ApolloClient({
  link: httpLink,
  cache: new InMemoryCache(),
});

Architecture

Apollo Link HTTP is built around several key components:

  • HTTP Link Factory: createHttpLink() function that creates configured Apollo Link instances
  • HTTP Link Class: HttpLink class providing an alternative class-based interface
  • Context Integration: Seamless integration with Apollo Link's context system for per-operation customization
  • Request Processing: Dynamic URI resolution, header management, and fetch option configuration
  • Error Handling: Comprehensive error categorization (network, server parse, client parse errors)
  • Cancellation Support: AbortController integration for request cancellation

Capabilities

HTTP Link Creation

Factory function for creating HTTP transport links with comprehensive configuration options.

function createHttpLink(linkOptions?: HttpLink.Options): ApolloLink;

HTTP Link Creation

HTTP Link Class

Class-based interface for creating HTTP transport links, extending Apollo Link base functionality.

class HttpLink extends ApolloLink {
  constructor(opts?: HttpLink.Options);
  requester: RequestHandler;
}

HTTP Link Class

Configuration Options

Comprehensive configuration system for customizing HTTP transport behavior.

namespace HttpLink {
  interface Options extends HttpOptions {
    useGETForQueries?: boolean;
  }
  
  interface UriFunction {
    (operation: Operation): string;
  }
}

interface HttpOptions {
  uri?: string | UriFunction;
  includeExtensions?: boolean;
  fetch?: WindowOrWorkerGlobalScope['fetch'];
  headers?: any;
  credentials?: string;
  fetchOptions?: any;
}

Configuration

Error Handling

Structured error types for different failure scenarios in HTTP transport.

type ServerError = Error & {
  response: Response;
  result: Record<string, any>;
  statusCode: number;
};

type ServerParseError = Error & {
  response: Response;
  statusCode: number;
  bodyText: string;
};

type ClientParseError = InvariantError & {
  parseError: Error;
};

Error Handling

Type Definitions

Core Types

interface Body {
  query?: string;
  operationName?: string;
  variables?: Record<string, any>;
  extensions?: Record<string, any>;
}

interface HttpConfig {
  http?: HttpQueryOptions;
  options?: any;
  headers?: any;
  credentials?: any;
}

interface HttpQueryOptions {
  includeQuery?: boolean;
  includeExtensions?: boolean;
}

Legacy Type Aliases

type FetchOptions = HttpLink.Options;
type UriFunction = HttpLink.UriFunction;