Gateway: Supergraph schema
Hive Gateway can retrieve a supergraph from a wide range of sources.
This includes:
- Hive Schema Registry
- Apollo GraphOS / Studio
- Custom Sources
- Subgraphs running on your machine, composed by the gateway during development
In addition you can also proxy any GraphQL API, by either introspection or providing a schema file.
Supergraph
Hive Gateway has built in support for fetching supergraphs from the Hive Schema Registry. You can either choose to provide the configuration via CLI parameters, environment variables or a configuration file.
Hive Gateway has built in support for fetching supergraphs from the Apollo GraphOS Registry. You can either choose to provide the configuration via CLI parameters, environment variables or a configuration file.
You can provide a custom supergraph source, along with other options to customize the polling/retry behavior.
You can point to supergraph.graphql located in your file system.
During development, Hive Gateway can compose its own supergraph from subgraphs that are running on
your machine, or whose schema is available as a file, instead of serving a supergraph that was
composed elsewhere. This is the gateway counterpart of the Hive CLI’s
hive dev command: the gateway resolves the
schema of each configured service, composes a supergraph, serves it, and recomposes whenever one of
the schemas changes. Use it to test changes to one or more subgraphs together with the rest of your
graph, without running every subgraph locally and without a separate composition process.
Every service needs a name, which must match the subgraph’s name in the graph, and the url the
gateway routes requests to. The optional source controls where the service’s schema comes from:
source | How the schema is obtained |
|---|---|
federation (default) | The service’s federation _service { sdl } field is queried. |
graphql | A standard GraphQL introspection query is sent and the result is printed as SDL. Use this for services that are not federation aware. |
file | The SDL file given in schema is read from disk. The service is not contacted for its schema, but url is still where requests are routed. Requires Node.js. |
Repeat --dev-service once per service. --dev-service-source and --dev-service-schema are
optional arguments keyed by the same service name.
When --dev-service is given, it defines the services in full and replaces any services
configured in the configuration file.
By default the gateway composes the configured services, and only those, on your machine. To compose them together with the rest of your graph, enable remote composition.
Remote composition through the Hive registry
With remote enabled, the gateway sends the resolved schemas of the configured services to the Hive
registry, which composes them with the latest composable schema version of the given target. A
configured service replaces the target’s subgraph of the same name, or is added if there is none, and
every other subgraph is taken from the registry as it was last published. You only need to run the
services you are changing.
--hive-target accepts either the organization/project/target slug path or the target’s UUID.
| Option | CLI flag | Environment variable | Description |
|---|---|---|---|
remote | --dev-remote | DEV_REMOTE | Compose through the Hive registry instead of locally. Requires token. As an environment variable, 1, true, yes or on enable it and any other value, for example 0, false or off, disables it, overriding remote from the configuration file. |
registry | --dev-registry <endpoint> | DEV_REGISTRY | The registry’s GraphQL API endpoint. Defaults to https://app.graphql-hive.com/graphql (Hive Cloud); set it for self-hosted Hive. |
token | --hive-access-token <token> | HIVE_ACCESS_TOKEN | The registry access token used for composition. |
target | --hive-target <target> | HIVE_TARGET | The target to compose against. In the configuration file, { byId } or { bySelector: { organizationSlug, projectSlug, targetSlug } }. |
These flags overlay the corresponding options of a dev source configured in the configuration
file, so you can keep the services in the file and pass the registry credentials through the
environment.
Local or remote composition
Use remote composition when:
- your graph is published to a Hive target and the result should match what schema checks and production will see
- you want to run only the services you are changing, with every other subgraph taken from the registry as last published
- unrelated subgraphs should always be their latest published versions rather than stale local copies
Use local composition when:
- you are offline or prototyping without a registry
- every subgraph you need is already running locally
- you want the fastest possible feedback loop
Local composition uses the composition engine bundled with your gateway version, which can differ from the one the registry runs. Remote composition is performed by the registry with the same engine that validates your pull requests and publishes to production, so what composes on your machine composes in CI.
Polling, recomposition and failures
The gateway resolves every service’s schema on each polling interval and recomposes
only when a service’s schema or url changed, or a service was added or removed, so it can stay
running while you edit resolvers and schema files. The first fetch after the gateway starts always
composes, even if a persisted cache such as Redis still holds a supergraph from a previous run.
Composition itself is guarded by a circuit breaker; lower volumeThreshold (for example to 1) if
repeated failures, such as an unreachable registry, should pause composition for resetTimeout
milliseconds instead of being retried on every poll.
When composition fails, the error is logged together with the composition errors (local) or the registry’s response (remote). If a supergraph was already being served, the gateway keeps serving it until a later poll composes successfully. If the first composition after start fails, the gateway exits, so start your subgraphs before the gateway.
Restrictions
- The
--dev-*flags require adevsupergraph source, configured either in the configuration file or via--dev-service. They cannot be combined with a supergraph path or URL argument,--hive-cdn-endpointor--apollo-graph-ref. source: "file"reads from the file system and is only available when the gateway runs on Node.js. Services usingfederationorgraphqlwork in every runtime.
Polling
You can configure the polling interval for the supergraph source.
Proxy
Instead of serving a supergraph, you can also use Hive Gateway to proxy any existing GraphQL API. This allows you to add features such as usage reporting or persisted documents without modifying your existing GraphQL API.