Cosmo Cloud Onboarding
Learn how to deploy your first federated graph and integrate it with your Cosmo Router.
Getting Started
Prerequisites
- If you donβt have one, create a free account at https://cosmo.wundergraph.com/login.
- You need to have Node.js LTS (or higher), npm, and docker installed.
- Curl is needed to download files.
Prepare your Organization
After signing up, a personal organization is automatically created for you. You can use this for the demo, but we recommend creating a separate organization once you complete the tutorial. To do this, open the organization dropdown, select βCreate a new organizationβ, and choose a relevant name and slug for your new organization.
Install the CLI
Install the CLI to interact with the control plane and manage resources like graphs and API keys:
Log in with:
This opens your browser and prompts you to sign into your Cosmo account. Once logged in, youβll receive a terminal prompt to select your organization.
After logging in, verify your session and ensure youβre in the correct organization by running:
Create the Demo
Create a Namespace
A namespace helps separate resources and prevents unintended modifications between environments. Namespaces can also be used to create isolated environments for better organization and management.
To create a development namespace, run:
Create a Federated Graph
A federated graph represents your unified, federated GraphQL schema. Each federated graph is assigned a URL and can be mapped to a single router instance.
For this demo, youβll point to a demo router. The URL doesnβt need to be valid for the demo, but in a production environment, you would specify the URL of your deployed router.
Run the following command to create a federated graph:
The CLI documentation provides detailed explanations of the parameters. If necessary, the parameters can be changed later.
Create Subgraphs
A federated graph requires subgraphs to function. Without subgraphs, it cannot serve a valid GraphQL schema.
For this demo, youβll use pre-deployed demo subgraphs on a serverless platform. Follow the order below to ensure proper configuration:
Products
Employee
Mood
Availability
- Create the subgraph:
- Download the schema and publish it:
- Create the subgraph:
- Download the schema and publish it:
- Create the subgraph:
- Download the schema and publish it:
Expected Composition Errors
Before publishing, be aware that you will see errors indicating that the composition was unsuccessful. This is expected and will be resolved once the remaining subgraphs are published.
Your router will never deploy an invalid composition. Instead, it will continue running the latest valid composition schema.
- Create the subgraph:
- Download the schema and publish it:
After publishing the Mood subgraph schema, several composition errors have been resolved. Next, publish the Availability subgraph.
- Create the subgraph:
- Download the schema and publish it:
After publishing the schema, there should be no composition errors. Your graph has been successfully composed and is now ready to be retrieved by the router.
To verify, open the Cosmo Overview page for your graph.
Create a Router Token
After publishing all subgraphs, you need to generate a Router Token. This token allows the router to communicate with the control plane and fetch the latest valid graph composition.
Run the following command to create a router token:
-
Replace
myName
with a meaningful name for your token. -
The command returns a confirmation message and token, similar to:
-
Copy and store the token securely, as it will not be shown again. You will need it in the next step.
Run the Router
Finally, go to the Overview page of your federated graph in Cosmo Cloud and click βRun Router Locallyβ to copy the command needed to start the router.
Make sure to replace <graph-api-token>
with the token you copied set in the previous step.
Alternatively, you can use the following command:
Open the Playground
Open http://localhost:3002 and run your first GraphQL operation with WunderGraph Cosmo! The same playground is also available on Cosmo Cloud.
Example Query that involves all subgraphs
Bonus
After executing the Example Query, use the dropdown on the right to see how the router processed the request and distributed it across subgraphs. Inspect the generated query plan to understand execution details, troubleshoot issues during development, and ensure optimal performance in production.
If you want to learn more about it, please take a look at ART and Query Plans.
Prevent breaking changes
Each time you interact with the router, schema usage data is collected and centralized on our platform. This data helps you manage federation at scale and, more importantly, identify potential impacts on your customers before making changes.
To integrate this into your workflow, use the check command to assess the impact of any schema modifications.
Download the schema of the Employees subgraph
Run the following command to download the schema:
Locate and open the schema file
By default, the file is saved in your current working directory. Verify its location with:
If you need to search for the file, use:
Once youβve located the file, open it in your preferred text editor modify it.
Modify the Schema and Run the Check Command
Remove the OPERATIONS
enum value from the schema:
Run the check command:
Breaking change detected with client usage
You should see an output similar to the following. The change is flagged as breaking because the departments
field was queried in an example query, meaning its removal would impact existing clients.
Click the Open in studio
link to review the schema check in Cosmo Studio.
Release your changes
Once youβre confident about the impact of your changes, publish them to automatically update your router fleet:
Clean up
To remove all resources, delete the namespace with:
Summary
In this tutorial, you learned how to run a router with a functional federated graph consisting of four subgraphs and safely release production changes.
Now is the perfect time to visit your Dashboard to gain insights into your usage.
Was this page helpful?