Schema registry and CI checks
Gate every schema change in CI. Diff against the published schema with GraphQL Inspector, fail on breaking changes, and see what a registry adds.
Schema registry and CI checks
The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.
Not started
What you'll learn
- Because the schema is the contract, every change should be compared with the last published schema before it merges.
- A diff tool classifies changes as breaking, dangerous or safe, for example a removed field, an argument that became required, or a new nullable field.
- A purely structural diff cannot tell whether anyone uses the removed field, so a registry that sees real operation traffic can allow breaking changes that nobody depends on.
- In a federated graph, the check also composes the proposed subgraph with the others, so a change that breaks the supergraph fails before deploy.
- Deprecate first, watch usage fall to zero, then remove.
The schema is an API surface you can diff
Evolving a schema without versions set the rules: add freely, deprecate before removing, never change a field’s type in place. Rules need enforcement. A reviewer reading a pull request will miss the one-line change that removes a field a mobile app still queries.
A schema is machine readable, which makes enforcement mechanical. Compare the proposed schema against the one currently live, classify every difference, and fail the build on the dangerous ones.
A diff in CI
GraphQL Inspector does exactly this. I ran @graphql-inspector/cli 7.0.8 on two schema files. The old one:
type Book { id: ID! title: String! subtitle: String }
type Query { books: [Book!]! book(id: ID!): Book }
A careless new version changed a type, dropped a field and added a required argument:
type Book { id: ID! title: Int! }
type Query { books: [Book!]! book(id: ID!, lang: String!): Book }
npx graphql-inspector diff old.graphql new.graphql reported three breaking changes and exited with code 1:
✖ Field subtitle was removed from object type Book
✖ Field Book.title changed type from String! to Int!
✖ Argument lang: String! added to field Query.book
A non-zero exit fails a CI job. Then a careful version:
type Book { id: ID! title: String! subtitle: String @deprecated(reason: "use title") isbn: String }
returned “No breaking changes detected” and exit 0, listing isbn as added and subtitle as deprecated. The tool distinguishes the two, which is the point. In a pipeline, the “old” schema is the one from your main branch, or the last published version, and the “new” one is generated from the code. A GitHub Action wraps the same logic and comments on the pull request.
Three categories matter. Breaking changes can fail existing queries: removing a field, changing a type, making an argument required. Dangerous ones usually work but can change behaviour: adding an enum value that clients do not handle, changing a default. Safe ones, such as a new optional field or a deprecation, pass.
What a diff cannot know
The diff above is correct and still over-cautious. It flagged subtitle as removed, but if nobody has queried subtitle for a year, removing it breaks no one. A file comparison has no idea. This is the gap a schema registry fills.
A registry stores each published schema version and, if your servers or router report operations to it, records which fields real clients use. Then a check can say: this change is technically breaking, but no operation seen in the last thirty days uses the field. Or the reverse: this looks like a safe change in the schema but breaks a persisted operation from the web app. Apollo GraphOS and GraphQL Hive are two hosted registries; both also keep a history and a diff view. I did not use either in this session, so claims about registry behaviour here are documentation-derived, not verified.
That makes the loop for removing a field concrete:
- Mark it
@deprecatedwith a reason. - Ship that. Watch usage in the registry or in your observability.
- When usage reaches zero for long enough, remove it, and let the check pass on the data.
Federation adds composition
For federated subgraphs, one more check applies. A subgraph change must still compose with the others. In Apollo federation basics I changed Product.name to Int! in a second subgraph and composition failed with an incompatible-type error and a non-shareable-field error. A subgraph pipeline should run that composition for every pull request, using the other subgraphs’ latest published schemas.
Rover can do both against Apollo’s registry: it can check a subgraph’s proposed schema and publish it on merge, and a hosted registry composes and distributes the supergraph to routers. Locally, rover supergraph compose and @apollo/composition, both of which I ran, cover the composition half without an account. Hive offers the equivalent flow with its own CLI. The registry-and-checks flow with a hosted account is something I could not run here.
A practical pipeline
- On every pull request: generate the schema from code, diff against main, run composition if federated, run the schema snapshot test.
- On merge to main: publish the schema to the registry or commit the SDL, and update the supergraph.
- Deploy order matters for additive changes: ship the server before the clients that use the new field, and remove fields only after clients have stopped asking.
Pair this with client-side code generation. Client builds validate their operations against the schema, so they fail when the schema stops matching, and server checks fail when the schema is about to stop matching a client. Between them, the contract is checked from both sides.
What the video covers
Jamie Barton’s “Detect breaking GraphQL schema changes with GitHub Actions” is under four minutes, from December 2021. Its chapters are: CLI to check for changes, GraphQL Inspector, and update the schema to remove a field. That is the diff half of this lesson, a good fit for it. It is short and from 2021, so the action’s version and inputs have likely changed; I ran the current CLI above instead. It has no registry content, which is why the 77-minute Hive workshop is listed under “go deeper”, covering the registry, checks and CI/CD integration, and a 2020 Apollo video on registry basics.
Where this fits
The schema now has a gate. The last lesson, deploying GraphQL, is about getting the server itself into production.
Check yourself
Why is changing a field from String! to Int! a breaking change but adding a nullable field is not?
Existing queries that read the field now receive a different type, while a newly added nullable field is something no existing query requests.
What does a registry know that a diff against a file does not?
Which operations real clients send, so it can tell whether a technically breaking change affects anyone.
Why run composition as part of a subgraph's CI?
A subgraph change can be valid alone and still conflict with other subgraphs, and composition is where that is found.
Go deeper
Notes
Notes are saved to your account.
Everything else on this page works without one — progress and bookmarks keep themselves in this browser and come with you when you sign in. Notes are the one thing worth not trusting to a browser you might clear.
Your notes could not be loaded.