On this page

Apollo Gateway

Apollo-Gateway is the JavaScript Apollo Federation gateway runtime.

Hive integrates with Apollo Gateway to provide the Supergraph schema information required for running a federated graph gateway, once all schemas are published.

CI/CD

Hive

Poll supergraph

Publish supergraph

Report usage data

Publish schemas

Apollo Gateway
(with Hive client)

HA CDN
(on Cloudflare)

Registry

GraphQL subgraph

GraphQL subgraph

GraphQL subgraph

Hive CLI

Installation

npm i @graphql-hive/apollo

The @graphql-hive/apollo package exports a utility function called createSupergraphManager that fetches the Supergraph schema from the Hive’s CDN, and also a Apollo-Server plugin for reporting operations.

Supergraph SDL from the CDN

Once you have all services schemas pushed to Hive, and available in the CDN, you can create a CDN Access Token and gain access to the CDN endpoint.

With the endpoint and CDN access token available, you can integrate Hive with Apollo Gateway:

import { ApolloGateway } from "@apollo/gateway";
import { ApolloServer } from "@apollo/server";
import { startStandaloneServer } from "@apollo/server/standalone";
import { createSupergraphManager } from "@graphql-hive/apollo";

const supergraphManager = createSupergraphManager({
  endpoint: [
    "https://cdn.graphql-hive.com/artifacts/v1/<target_id>",
    "https://cdn-mirror.graphql-hive.com/artifacts/v1/<target_id>",
  ],
  key: "<cdn_access_key>",
  pollIntervalInMs: 15_000,
});

const gateway = new ApolloGateway({
  // Apollo Gateway will fetch Supergraph from Hive CDN
  supergraphSdl: supergraphManager,
});

const server = new ApolloServer({ gateway });

const { url } = await startStandaloneServer(server);
console.log(`🚀 Server ready at ${url}`);

Usage Reporting

To enable Usage Reporting with your Apollo Gateway, you can use the Hive plugin for Apollo Server:

import { ApolloGateway } from "@apollo/gateway";
import { ApolloServer } from "@apollo/server";
import { startStandaloneServer } from "@apollo/server/standalone";
import { createSupergraphManager, useHive } from "@graphql-hive/apollo";

const supergraphManager = createSupergraphManager({
  endpoint: [
    "https://cdn.graphql-hive.com/artifacts/v1/<target_id>",
    "https://cdn-mirror.graphql-hive.com/artifacts/v1/<target_id>",
  ],
  key: "<cdn_access_key>",
  pollIntervalInMs: 15_000,
});

const gateway = new ApolloGateway({
  // Apollo Gateway will fetch Supergraph from Hive CDN
  supergraphSdl: supergraphManager,
});

const server = new ApolloServer({
  gateway,
  plugins: [
    useHive({
      enabled: true,
      token: "YOUR-TOKEN",
      // add this one to report usage and operations
      usage: {
        target: "<YOUR_ORGANIZATION>/<YOUR_PROJECT>/<YOUR_TARGET>",
      },
    }),
  ],
});

const { url } = await startStandaloneServer(server);
console.log(`🚀 Server ready at ${url}`);

Additional Resources