Documentation
Other Integrations
Apollo Gateway

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.

Installation

npm i @graphql-hive/apollo

We recommend installing Hive Client package as a direct dependency of your project, because it includes a runtime to send usage reports and schemas to Hive registry.

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 gateway = new ApolloGateway({
  // Apollo Gateway will fetch Supergraph from Hive CDN
  supergraphSdl: createSupergraphManager({
    endpoint: 'HIVE_CDN_ENDPOINT',
    key: 'HIVE_CDN_KEY',
    pollIntervalInMs: 15_000
  })
})
 
const server = new ApolloServer({ gateway })
 
const { url } = await startStandaloneServer({ server })
console.log(`🚀 Server ready at ${url}`)

Usage Reporting

💡

For more configuration options, such as sampling, client name and version reporting, please refer to the Hive client configuration reference.

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 gateway = new ApolloGateway({
  // Apollo Gateway will fetch Supergraph from Hive CDN
  supergraphSdl: createSupergraphManager({
    endpoint: process.env.HIVE_CDN_ENDPOINT,
    key: process.env.HIVE_CDN_KEY,
    pollIntervalInMs: 15_000
  })
})
 
const server = new ApolloServer({
  gateway,
  plugins: [
    useHive({
      enabled: true,
      token: 'YOUR-TOKEN',
      usage: true // add this one to report usage and operations
    })
  ]
})
 
const { url } = await startStandaloneServer({ server })
console.log(`🚀 Server ready at ${url}`)
💡

The HIVE_CDN_ENDPOINT variable should NOT include any artifact suffix (for example, /supergraph), it should be in the following format: https://cdn.graphql-hive.com/artifacts/v1/TARGET_ID

Additional Resources