Hive Gateway
Hive Gateway is a fully open-source, MIT-licensed GraphQL router that can act as a GraphQL Federation gateway, a subgraph or a proxy gateway for any GraphQL API service.
As an alternative to Apollo Router, Hive Gateway provides a flexible, open-source solution tailored to meet the needs of modern GraphQL architectures.
It supports deployment as a standalone binary, a Docker image, or a JavaScript package, making it compatible with environments such as Node.js, Bun, Deno, Google Cloud Functions, Azure Functions, or Cloudflare Workers.
Our GraphQL API Gateway provides the following features on top of your GraphQL schema:
- GraphQL Subscriptions with WebSockets, HTTP Callbacks or SSE
- Automatic query and request batching to reduce the number of HTTP requests to your subgraph
- JSON Web Tokens (JWT) authentication between client and gateway also between gateway and subgraph
- Authorization on specific fields and types using
Federation Auth directives like
@authenticated
and@skipAuth
- Role-based Access Control (RBAC) either
programmatically or with directives
@requiresScope
and@policy
- Response Caching based on either in
memory or Redis for distributed caching optionally with
@cacheControl
directive - Security features such as safelisting, depth limit etc
- Rate Limiting on specific fields and types
either programmatically or declaratively with
@rateLimit
directive - Prometheus and OpenTelemetry integration with fully customizable spans and attributes
- Persisted Documents backed by either Hive Registry or a selfhosting storage
- E2E HTTP Compression from the client to the subgraph for better performance and resource management
- And more
Installation
Hive Gateway can be installed in different ways depending on your preference.
This command will download the appropriate binary for your operating system.
curl -sSL https://graphql-hive.com/install-gateway.sh | sh
Starting the Gateway
Hive Gateway supports two different modes:
- GraphQL Federation. Serve a supergraph provided by a schema registry like Hive Registry, a composition tool like Apollo Rover, GraphQL Mesh or any other Federation compliant composition tool such as Apollo Rover or schema registry (Hive Registry, Apollo GraphOS)
- Proxy a GraphQL API. Hive Gateway can also act as a proxy to an existing GraphQL API.
To serve a GraphQL federation Gateway, we need to point the Gateway to either a local supergraph file or a supergraph served by our schema registry. For this example, we will serve a supergraph from the Hive schema registry.
hive-gateway supergraph \
http://cdn.graphql-hive.com/artifacts/v1/12713322-4f6a-459b-9d7c-8aa3cf039c2e/supergraph \
--hive-cdn-key "YOUR HIVE CDN KEY"
By default, Hive Gateway will start a server on port 4000. You can customize that behavior. For that please refer to our Gateway documentation.
Configuration File
The Hive Gateway config file gateway.config.ts
is used for enabling additional features such as
authorization, authentication caching, rate limiting, and more. The recommended language for the
configuration file is TypeScript.
We can provide the CLI configuration parameters, also via the configuration file.
import { defineConfig } from '@graphql-hive/gateway'
export const gatewayConfig = defineConfig({
supergraph: {
type: 'hive',
// The endpoint of Hive's CDN
endpoint: '<supergraph endpoint>',
// The CDN token provided by Hive Registry
key: '<cdn access token>'
}
})
Hive Gateway will automatically load the default config file and apply the settings.
hive-gateway supergraph
Next steps
After learning the first steps of Hive Gateway, you can explore the following topics.