gRPC-GraphQL Gateway
A high-performance Rust gateway that bridges gRPC services to GraphQL with full Apollo Federation v2 support.
Transform your gRPC microservices into a unified GraphQL API with zero GraphQL code. This gateway dynamically generates GraphQL schemas from protobuf descriptors and routes requests to your gRPC backends via Tonic, providing a seamless bridge between gRPC and GraphQL ecosystems.
β¨ Features
Core Capabilities
- π Dynamic Schema Generation - Automatic GraphQL schema from protobuf descriptors
- β‘ Full Operation Support - Queries, Mutations, and Subscriptions
- π WebSocket Subscriptions - Real-time data via GraphQL subscriptions (
graphql-wsprotocol) - π€ File Uploads - Multipart form data support for file uploads
- π― Type Safety - Leverages Rustβs type system for robust schema generation
Federation & Enterprise
- π Apollo Federation v2 - Complete federation support with entity resolution
- π Entity Resolution - Production-ready resolver with DataLoader batching
- π« No N+1 Queries - Built-in DataLoader prevents performance issues
- π All Federation Directives -
@key,@external,@requires,@provides,@shareable - π Batch Operations - Efficient entity resolution with automatic batching
Developer Experience
- π οΈ Code Generation -
protoc-gen-graphql-templategenerates starter gateway code - π§ Middleware Support - Extensible middleware for auth, logging, and observability
- π Rich Examples - Complete working examples for all features
- π§ͺ Well Tested - Comprehensive test coverage
Production Ready
- π₯ Health Checks -
/healthand/readyendpoints for Kubernetes - π Prometheus Metrics -
/metricsendpoint with request counts and latencies - π OpenTelemetry Tracing - Distributed tracing with GraphQL and gRPC spans
- π‘οΈ DoS Protection - Query depth and complexity limiting
- π Introspection Control - Disable schema introspection in production
- π Query Whitelisting - Restrict to pre-approved queries (PCI-DSS compliant)
- β‘ Rate Limiting - Built-in rate limiting middleware
- π¦ Automatic Persisted Queries - Reduce bandwidth with query hash caching
- π Circuit Breaker - Prevent cascading failures
- ποΈ Response Caching - In-memory LRU cache with TTL
- π Batch Queries - Execute multiple operations in one request
- π Graceful Shutdown - Clean shutdown with request draining
- ποΈ Response Compression - Automatic gzip/brotli compression
- π Header Propagation - Forward HTTP headers to gRPC backends
- π§© Multi-Descriptor Support - Combine multiple protobuf descriptors
Why gRPC-GraphQL Gateway?
If you have existing gRPC microservices and want to expose them via GraphQL without writing GraphQL resolvers manually, this gateway is for you. It:
- Reads your protobuf definitions - Including custom GraphQL annotations
- Generates a GraphQL schema automatically - Types, queries, mutations, subscriptions
- Routes requests to your gRPC backends - With full async/await support
- Supports federation - Build a unified supergraph from multiple services
Quick Example
use grpc_graphql_gateway::{Gateway, GrpcClient};
const DESCRIPTORS: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/descriptor.bin"));
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let gateway = Gateway::builder()
.with_descriptor_set_bytes(DESCRIPTORS)
.add_grpc_client(
"greeter.Greeter",
GrpcClient::builder("http://127.0.0.1:50051").connect_lazy()?,
)
.build()?;
gateway.serve("0.0.0.0:8888").await?;
Ok(())
}
Thatβs it! Your gateway is now running at:
- GraphQL HTTP:
http://localhost:8888/graphql - GraphQL WebSocket:
ws://localhost:8888/graphql/ws
Getting Started
Ready to dive in? Start with the Installation guide.