Prerequisites
Node.js (>= 22.11.0 LTS)
Docker
Project setup
Clone the example project, which includes two subgraphs (Posts
and Users
) as well as a Router.
The example project is available here: https://github.com/wundergraph/cosmo-demo, or you can clone it with the following command:
Step 1: Install the Cosmo CLI tool
Install the latest version of the Cosmo CLI.Step 2: Set Up and Run the Subgraphs
The cloned project contains preconfigured subgraphs and a script to run them.Ensure the script is executable
In the project’s root directory, run this to ensure thestart-subgraphs.sh
script is executable:
Start the subgraphs
Run the following command to install dependencies and start the subgraphs in the background:Verify the subgraphs are running
Once the script finishes, check the subgraphs are running by visiting: If both load correctly, the servers are running.Test Queries
You can run the following queries to confirm the subgraphs are functioning correctly.Posts Subgraph (localhost:4001)
To retrieve all posts, run the following query:id
, run the following query:
Users Subgraph (localhost:4002)
To retrieve all users, run the following query:id
, run the following query:
Stop the Subgraphs
You will need to keep the script running in the background for this tutorial, but if it is necessary to stop it, run:Step 3: Generate the Router Configuration
The repository includes agraph.localhost.yaml
configuration file for the wgc
CLI tool to introspect and generate a router configuration.
Setup Considerations
-
For Docker-based subgraphs, use
graph.yaml
instead ofgraph.localhost.yaml
. - For custom subgraphs, update the configuration file to match your setup.
Generate the Router Configuration
Open a new terminal and run the following command to navigate to therouter
directory.
Step 4: Run the router
While still in therouter
directory, start the router using Docker. Make sure Docker is running on your machine before proceeding.
We recommend using Docker to prevent dependency conflicts and maintain a consistent environment.