On this page
← All product updates

Compose Local Subgraphs Inside Hive Gateway

Jeff Dolle
Jeff Dolle

Hive Gateway can now compose its own supergraph during development. Point the supergraph command at the subgraphs running on your machine and the gateway resolves their schemas, composes them, and serves the result. It recomposes whenever one of the schemas changes, so you can leave it running while you work. There is no hive dev process to start and no supergraph file to watch.

Quick Start

Pass one --dev-service per subgraph, or configure a dev supergraph source in gateway.config.ts:

hive-gateway supergraph \
  --dev-service products=http://localhost:4001/graphql \
  --dev-service reviews=http://localhost:4002/graphql

By default each service’s schema is fetched through its federation _service { sdl } field. Set --dev-service-source <name>=graphql for services that are not federation aware, or <name>=file with --dev-service-schema <name>=./schema.graphql to read the SDL from disk, which lets you compose a schema before a single resolver exists.

Compose With the Rest of Your Graph

Local composition only includes the services you list. To run only the subgraph you are changing, enable remote composition. The gateway sends your local schemas to the Hive registry, which replaces the target’s subgraph of the same name and composes it with every other subgraph as last published:

hive-gateway supergraph \
  --dev-service products=http://localhost:4001/graphql \
  --dev-remote \
  --hive-target my-org/my-project/staging \
  --hive-access-token "$HIVE_ACCESS_TOKEN"

--hive-target and --hive-access-token are the gateway’s standard Hive registry options, so the same target and token also enable usage reporting for that target.

Remote composition uses the same composition engine and project configuration as schema checks and publishes, so what composes on your machine composes in CI. We recommend it whenever your graph is published to a Hive target. Keep local composition for offline work and quick experiments.

The dev source is meant for local development. In deployed environments, keep serving a supergraph from the Hive CDN or one of the other supergraph sources.