Developing your supergraph locally
With the Rover CLI
While you're working on changes to one of your subgraphs, you can run a version of your entire supergraph locally in your development environment! To do this, you use the
rover dev command.
rover dev command monitors each of your subgraph schemas (either via server introspection or by watching a
.graphql file). Whenever it detects a change, it automatically recomposes your router's supergraph schema and raises any errors that might occur. This enables you iterate quickly on schema changes.
Starting your router
rover dev once for each subgraph in your supergraph. The first time you run it, Rover spins up a router on your local machine.
rover dev with an example subgraph like so:
rover dev --url https://flyby-locations-sub.herokuapp.com/ --name locations
You'll see output like the following:
WARN: could not detect a schema in the current working directory. to watch a schema, pass the `--schema <PATH>` argument👂 polling https://flyby-locations-sub.herokuapp.com/ every 1 second⚠️ Do not run this command in production! ⚠️ It is intended for local development.🛫 starting a session with the 'locations' subgraph🎶 composing supergraph with Federation v2.1.2🚀 your supergraph is running! head to http://localhost:3000 to query your supergraph
You can now open
http://localhost:3000 in your browser and run test queries against your local router using the Explorer!
You can replace the example subgraph URL and name in the above command with the details for your own subgraph. You can provide a remote URL or a
Adding a subgraph
To add a subgraph to your local supergraph, run
rover dev again in a separate terminal window.
You can add a subgraph to this article's example supergraph with the following command:
rover dev --url https://flyby-reviews-sub.herokuapp.com/ --name reviews
This command's output is similar to the output for the initial execution, but it includes a line like the following:
🐤 adding the 'reviews' subgraph to the session
This indicates that
rover dev has identified your existing supergraph session and is adding this subgraph to it.
Now if you run test queries in the Explorer, you'll see that they can include fields from both the
rover dev session
To shut down your local supergraph, use
CTRL+C to terminate the first
rover dev process you started. This automatically terminates all secondary
rover dev processes that are part of the same session.
If you terminate a secondary
rover dev process, your session remains active, and the router's schema is automatically updated to reflect the removed subgraph.
For more details on
rover dev options, see the Rover documentation.