Prompt
How do I stitch GraphQL schemas together?
Latest observation
Aug 27, 2026
OpenAI APIWeb search: off
There are a few common ways to “stitch” GraphQL schemas together, depending on what you mean by stitching:
1) Schema Stitching at a gateway
You have multiple GraphQL services and want a single endpoint that merges them.
How it works
- Each service exposes its own schema.
- A gateway combines those schemas into one unified schema.
- The gateway may delegate parts of queries to the appropriate service.
Typical tools
- Apollo Gateway / Federation (most common in modern GraphQL)
- graphql-tools schema stitching
- Mesh / GraphQL Mesh
Example with @graphql-tools/stitch
import { stitchSchemas } from '@graphql-tools/stitch';
import { wrapSchema, introspectSchema } from '@graphql-tools/wrap';
import { makeExecutableSchema } from '@graphql-tools/schema';
import { graphql } from 'graphql';
async function createGateway() {
const userSchema = await introspectSchema(userServiceExecutor);
const postSchema = await introspectSchema(postServiceExecutor);
const stitchedSchema = stitchSchemas({
subschemas: [
{
schema: userSchema,
executor: userServiceExecutor,
},
{
schema: postSchema,
executor: postServiceExecutor,
},
],
});
return stitchedSchema;
}
2) Type merging / extending types
If multiple schemas define related types, you can merge them so the gateway understands they represent the same conceptual entity.
Example
Service A:
type User {
id: ID!
name: String!
}
Service B:
type User {
id: ID!
email: String!
}
With stitching/federation, you can combine fields into one User type:
type User {
id: ID!
name: String!
email: String!
}
3) Using Apollo Federation instead
If you’re starting a new system, Apollo Federation is usually preferred over manual stitching.
Why
- Better ecosystem support
- Built-in entity resolution
- Clear ownership of fields by services
- More scalable than ad hoc stitching
Example
Service A:
type User @key(fields: "id") {
id: ID!
name: String!
}
Service B:
extend type User @key(fields: "id") {
id: ID! @external
email: String!
}
Gateway composes these into one graph.
4) Manual schema merging
If you just have a few schemas and want to merge them locally:
- Parse each SDL string
- Merge type definitions
- Use
mergeTypeDefsfrom@graphql-tools/merge
import { mergeTypeDefs } from '@graphql-tools/merge';
const typeDefs = mergeTypeDefs([schemaA, schemaB]);
This is only schema merging, not full runtime stitching.
Which approach should you use?
- Single endpoint for multiple services → Apollo Federation or schema stitching
- Just combining SDL files locally →
mergeTypeDefs - Need query delegation across services →
@graphql-tools/stitch - Greenfield microservices graph → Apollo Federation
If you want, I can show:
- a real stitched-schema example with two services, or
- the Apollo Federation version, or
- how to stitch schemas in Node.js step by step.