Quickstart · Examples · Docs · CLI · Community · Changelog · Hiring
WunderGraph Cosmo is a comprehensive Lifecycle API Management platform tailored for Federated GraphQL. It encompasses everything from Schema Registry, composition checks, and analytics, to metrics, tracing, and routing. Whether you’re looking to deploy 100% on-prem or prefer a Managed Service, Cosmo offers flexibility without vendor lock-in, all under the Apache 2.0 license.
This repository contains demo subgraphs implemented as Cosmo Router plugins. These subgraphs are used to onboard users to the Cosmo platform with the wgc demo command.
The subgraphs model part of a fictional e-commerce business with Product and Review entities. The federated graph consists of queries and federated entities that look like this:
The root query exposes product(id: ID!): Product and review(id: ID!): Review. The reviews subgraph contributes an additional field to the Product type, reviews: [Review], which returns the list of reviews for a product.
⚙️How does it work under the hood?
The demo command fetches the plugins/ folder during its setup phase. The command then publishes these plugins to the Cosmo Cloud Plugin Registry. By publishing the plugins, the subgraphs are created in a predefined federated graph.
The command then runs the official Cosmo Router Docker image, which connects to the registry, pulls the published plugins, and executes them so the queries can be resolved with mocked data.
Run wgc demo and make sure you are logged in to your Cosmo Cloud account. Follow the instructions in the web application and CLI.
- Fork this repo.
- Add
ROUTER_TOKENto your CI secrets (TBD - Github workflow) - In
plugins/reviews/src/schema.graphqlexpand the schema file:
@@ -16,6 +16,7 @@ Entity describing a product with reviews
type Product @key(fields: "id") {
id: ID!
reviews: [Review]
+ averageRating: Float
}- Run
make generateinplugins/reviewsdirectory to generate gRPC methods. - Add the new field
AverageRatingto theProductstruct, usingcalculateAverageRatingfunction that is provided:
@@ -62,6 +62,7 @@ func (s *ReviewsService) LookupProductById(ctx context.Context, req *service.Loo
Items: items,
},
},
+ AverageRating: wrapperspb.Double(calculateAverageRating(items)),
}
}
return &service.LookupProductByIdResponse{Result: result}, nil- Create a pull request in your fork. Ensure checks pass.
- Merging the pull request will publish new version of the schema and plugin to Cosmo Cloud Plugin Registry.
- Query the new field! 🎉
Make sure you have make and pnpm installed. You will also need a Go toolchain, ideally with golangci-lint as well.
This project uses pnpm@10.29.3 (defined in packageManager). The easiest way to get the right version is via Corepack, which ships with Node.js:
corepack enable
corepack install- Run
pnpm installto install the dependencies. - Run
make startto build and run the router image. - Visit http://localhost:3002 to use the playground.
- Optional: execute an example query with
curl:
curl -s -X POST http://localhost:3002/graphql -H 'Content-Type: application/json' -d '{"query":"query GetProductWithReviews($id: ID\u0021) { product(id: $id) { id title price { currency amount } reviews { id author rating contents } } }","variables":{"id":"product-1"}}'This workflow is useful if you want to test the plugins against a local instance of the Cosmo platform. For more information, see how to develop the Cosmo platform locally.
Run the following steps in the directory where you cloned wundergraph/cosmo:
- Start the Cosmo platform.
- Create federated graph (documentation):
pnpm wgc federated-graph create --routing-url http://localhost:3002/graphql onboarding - Create subgraphs (documentation):
pnpm wgc subgraph create --routing-url http://localhost:3002/graphql products
pnpm wgc subgraph create --routing-url http://localhost:3002/graphql reviews- Publish the subgraphs (documentation). Replace
<cosmo-onboarding-repo-path>with a relative path to the directory where you cloned this repository:
pnpm wgc subgraph publish products --schema <cosmo-onboarding-repo-path>/plugins/products/src/schema.graphql
pnpm wgc subgraph publish reviews --schema <cosmo-onboarding-repo-path>/plugins/reviews/src/schema.graphql- Create a router token and store it in a secure place.
Run the following steps in the directory where you cloned this repository:
- Build the image with
make docker-local. - Run the image. Replace
<token>with the token you generated in step 5 above.
docker run --rm -p 3002:3002 -e GRAPH_API_TOKEN=<token> -e LOG_LEVEL=info cosmo-demo-localOther useful make targets:
make build- build the plugins and router configurationmake compose- generate the router execution configmake docker-local- build a development version of the Docker image

