Rover supergraph commands
For use in a federated architecture
A supergraph (also called a federated graph) is a graph composed of multiple subgraphs:
You can use the
supergraph compose command to compose a supergraph schema based on a supergraph configuration file, like so:
rover supergraph compose --config ./supergraph.yaml
You can also pass config via stdin:
cat ./supergraph.yaml | rover supergraph compose --config -
The supergraph configuration file (often referred to as
supergraph.yaml) includes configuration options for each of your subgraphs. The following example file configures a supergraph with two subgraphs,
subgraphs:films:routing_url: https://films.example.comschema:file: ./films.graphqlpeople:routing_url: https://people.example.comschema:file: ./people.graphql
In the above example, The YAML file specifies each subgraph's public-facing URL (
routing_url), along with the path to its schema (
It's also possible to pull subgraphs from various sources and specify them in the YAML file. For example, here is a configuration that specifies schema using Apollo Registry refs (
graphref) and subgraph introspection (
subgraphs:films:routing_url: https://films.example.comschema:file: ./films.graphqlpeople:routing_url: https://example.com/peopleschema:subgraph_url: https://example.com/peopleactors:routing_url: https://localhost:4005schema:graphref: mygraph@currentsubgraph: actors
To use Rover with a Federation 2 supergraph, you need to add
federation_version: 2 to your YAML configuration file.
federation_version: 2subgraphs:films:routing_url: https://films.example.comschema:file: ./films.graphql
The first time you run
rover supergraph compose with Federation 2 on a particular machine, you're prompted to accept the terms and conditions of the ELv2 license. On future invocations, Rover remembers that you already accepted the license and doesn't prompt you again (even if you update Rover).
⚠️ Important: CI systems wipe away any persisted Rover configuration on each run, and they can't accept the interactive ELv2 prompt. To automatically accept the prompt in CI, do one of the following:
- Set the environment variable
APOLLO_ELV2_LICENSE=acceptin your CI environment.
--elv2-license acceptin your
rover supergraph composecommand.
yes | rover supergraph compose
You can also save the output to a local
.graphql file like so:
# Creates prod-schema.graphql or overwrites if it already existsrover supergraph compose --config ./supergraph.yaml > prod-schema.graphql
For more on passing values via
stdout, see Using
Apollo Gateway fails to start up if it's provided with a supergraph schema that it doesn't support. To ensure compatibility, we recommend that you test launching your gateway in a CI pipeline with the supergraph schema it will ultimately use in production.
rover supergraph compose command generates a supergraph schema via composition. For Federation 1, this algorithm was implemented in the
@apollo/federation package. For Federation 2, this algorithm is implemented in the
rover supergraph compose supports composing subgraphs with both Federation 1 and Federation 2. By default, Rover uses Federation 2 composition if and only if at least one of your subgraph schemas contains the
@link directive. Otherwise, it uses Federation 1.
When Apollo releases new versions of composition for Federation 1 or Federation 2, Rover downloads the new package to your machine. Rover then uses the new composition package to compose your subgraphs. Our aim is to release only backward-compatible changes across major versions moving forward. If composition breaks from one version to the next, please submit an issue, and follow the instructions for pinning composition to a known good version.
⚠️ If you need to pin your composition function to a specific version (not recommended), you can do so by setting
federation_version: =2.0.1 in your
supergraph.yaml file. This ensures that Rover always uses the exact version of composition that you specified. In this example, Rover would use
Versions of the
supergraph plugin (built from this source) are installed to
~/.rover/bin if you installed with the
curl | sh installer, and to
./node_modules/.bin/ if you installed with npm.
If you set
federation_version: 1 or
federation_version: 2, you can run
rover supergraph compose with the
--skip-update flag to prevent Rover from downloading newer composition versions. Rover instead uses the latest major version that you've downloaded to your machine. This can be helpful if you're on a slow network.
If any subgraph schema contains the
@link directive and you've specified
federation_version: 1, you either need to revert that subgraph to a Federation 1 schema or move your graph to Federation 2.
Prior to Rover v0.5.0,
rover supergraph compose shipped with exactly one version of composition that was compatible with Federation 1. This function was sourced from the
|Rover version||Gateway version|
|<= v0.2.x||<= v0.38.x|
|>= v0.3.x||>= v0.39.x|
This requires first authenticating Rover with Apollo Studio.
You can use Rover to fetch the supergraph schema of any federated Studio graph and variant it has access to. Run the
supergraph fetch command, like so:
rover supergraph fetch my-graph@my-variant
my-graph@my-variant in the example above specifies the ID of the Studio graph you're fetching from, along with which variant you're fetching.
You can omit
@ and the variant name. If you do, Rover uses the default variant, named