Prompt
How do I combine multiple GraphQL services?
Latest observation
There are a few common ways to combine multiple GraphQL services, depending on whether you want a single unified API, or just to call several GraphQL services from your app.
1) GraphQL Federation
Best when you want multiple teams/services to own parts of one schema.
- Each service exposes its own schema
- A gateway composes them into one supergraph
- Clients query the gateway as if it were one GraphQL API
Pros
- Strong for microservices
- Clear ownership boundaries
- Scales well organizationally
Cons
- More setup and tooling
- Requires federation support in each service
Common tools:
- Apollo Federation
- GraphQL Hive / schema registry tools
- Apollo Gateway
2) Schema Stitching
Best when you already have multiple GraphQL endpoints and want to merge them into one schema without changing services much.
- You combine schemas at the gateway layer
- Resolver functions delegate to downstream GraphQL APIs
Pros
- Can work with existing GraphQL services
- Flexible for customization
Cons
- Can get complex
- Harder to maintain than federation at scale
Common tools:
- GraphQL Tools (
@graphql-tools/stitch) - custom gateway logic
3) Backend-for-Frontend / Aggregation Layer
Best when you only need to combine data for one app or one client type.
- Build a new GraphQL server that calls multiple GraphQL services
- Your resolvers fetch from each service as needed
Pros
- Simple conceptually
- Full control over the API
Cons
- Can become a bottleneck
- Less reusable than federation
4) Client-side Composition
Best when you don’t need a single backend endpoint.
- Your frontend calls multiple GraphQL services directly
- Combine results in the app
Pros
- No gateway needed
- Fast to start
Cons
- More client complexity
- Harder auth/caching/error handling
- Usually not ideal for larger apps
Which should you choose?
- Multiple teams, one API → Federation
- Existing GraphQL APIs you want to merge quickly → Schema stitching
- One app needs unified access → BFF/aggregation layer
- Small/simple setup → Client-side composition
Practical recommendation
If you’re starting fresh and expect growth, GraphQL Federation is usually the best long-term choice. If you already have independent GraphQL services and want to unify them without rewriting, schema stitching is often the quickest route.
If you want, I can also show:
- an example of Apollo Federation
- an example of schema stitching
- or help you choose based on your architecture