This tutorial teaches you how to expose an existing GraphQL API in Cosmo as a ConnectRPC Service, without rewriting resolvers or changing your underlying Graph.
You'll learn how to compile Trusted Documents into a strongly typed RPC interface, where Cosmo acts as a translation layer. This enables different API consumers to interact with your Graph using the protocol and tooling that fits them best.
Key Concepts:
- Converting GraphQL operations into Protocol Buffer definitions
- Running a ConnectRPC server alongside your GraphQL API
- Consuming the same API through multiple protocols (HTTP/JSON, gRPC, typed SDKs)
- Generating OpenAPI specifications from your operations
This tutorial is for users who already have a monolithic or federated graph running in Cosmo and want to expose it via ConnectRPC.
Teams building and evolving GraphQL schemas who want to:
- Expose APIs to non-GraphQL consumers safely via trusted operations
- Avoid maintaining multiple API implementations for the same domain
Teams consuming APIs who want to:
- Use strongly typed SDKs, OpenAPI, or RPC-style APIs
- Integrate with familiar tooling and workflows
- Gain value from GraphQL-backed services without needing to learn GraphQL
This tutorial is divided into three parts. Each part builds on the previous one:
What you'll learn: How to define GraphQL operations and compile them into Protocol Buffer definitions
Time: ~15 minutes
You'll accomplish:
- Author named GraphQL operations (Trusted Documents)
- Generate a
.protofile from your operations - Understand the mapping between GraphQL and Protocol Buffers
What you'll learn: How to configure and run the Cosmo Router with ConnectRPC enabled
Time: ~10 minutes
You'll accomplish:
- Configure the router for ConnectRPC
- Start the ConnectRPC server
- Verify the service is running correctly
What you'll learn: Multiple ways to interact with your ConnectRPC service
Time: ~20 minutes
You'll accomplish:
- Call your API using
curl(HTTP/JSON) - Call your API using
grpcurl(gRPC) - Generate TypeScript and Go SDKs
- Generate an OpenAPI specification
Before starting this tutorial, you need:
- Completed the Cosmo Cloud Onboarding
- A federated graph named
demoin thedevelopmentnamespace - The
Products,Employee,Mood, andAvailabilitysubgraphs running - Ability to successfully query the federated graph via GraphQL
- The
wgcCLI installed and available in your$PATH - A valid
GRAPH_API_TOKEN
Quick verification:
# Check if wgc is installed
wgc --version
# Verify your graph is accessible
wgc federated-graph fetch demo --namespace developmentBy the end of this tutorial, you will have:
- ✅ Taken an existing federated GraphQL API running in Cosmo
- ✅ Defined trusted GraphQL operations as stable API contracts
- ✅ Generated a strongly typed ConnectRPC service from those operations
- ✅ Served that service using the Cosmo Router
- ✅ Consumed the same API via:
- curl (HTTP/JSON)
- grpcurl (gRPC)
- Generated TypeScript and Go SDKs
- An OpenAPI specification
The goal is to reduce friction between API producers and API consumers. Platform and API teams can continue to design, evolve and govern their APIs in GraphQL, while consumers gain access through strongly typed SDKs, OpenAPI, gRPC - without the need to understand or adopt GraphQL themselves.
Ready to begin? Head to Part 1: Operations to Proto to start the tutorial.