Apollo HTTP Link with DataLoader Batching

0.1.6 · abandoned · verified Wed Apr 22

http-link-dataloader is an Apollo Link designed to provide efficient HTTP requests for GraphQL by leveraging Facebook's DataLoader for automatic batching and caching. It distinguishes itself from `apollo-link-batch-http` by using an event-loop-based batching mechanism, consolidating consecutive GraphQL queries into a single HTTP request payload. The package currently sits at version 0.1.6, with its last release in 2018, indicating a lack of active development or a very slow release cadence. It was primarily developed for use cases involving `graphql-yoga` servers and `prisma-binding` (now largely deprecated in favor of Prisma Client), supporting array-based GraphQL batching on the server side. It ships with TypeScript types, but its age raises significant compatibility concerns with modern Apollo Client (v3+) and GraphQL ecosystems.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to import and instantiate the `HTTPLinkDataloader` with basic and authenticated configurations, and integrate it into an Apollo Client instance for querying.

import { ApolloClient, InMemoryCache } from '@apollo/client';
import { HTTPLinkDataloader } from 'http-link-dataloader';

// Basic instantiation without options
const basicLink = new HTTPLinkDataloader();

// Instantiation with URI and headers
const token = process.env.AUTH_TOKEN ?? ''; // Securely get your auth token
const httpLink = new HTTPLinkDataloader({
  uri: `https://your-graphql-api.com/graphql`,
  headers: { Authorization: `Bearer ${token}` },
});

// Example of setting up an Apollo Client with the dataloader link
// Note: This package might not be compatible with modern Apollo Client versions (v3+).
// This example assumes compatibility or a legacy Apollo Client setup.
const client = new ApolloClient({
  link: httpLink,
  cache: new InMemoryCache(),
});

// Example query using the client (requires your GraphQL schema)
async function fetchData() {
  try {
    const { data } = await client.query({
      query: `
        query GetItems {
          items {
            id
            name
          }
        }
      `,
    });
    console.log('Fetched data:', data);
  } catch (error) {
    console.error('Error fetching data:', error);
  }
}

fetchData();

view raw JSON →