You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/pages/learn/governance-tooling.mdx
+44-39Lines changed: 44 additions & 39 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,12 @@
1
+
import { Callout } from"nextra/components"
2
+
1
3
# Tooling and Automation for Governance
2
4
3
5
Governance practices require supporting infrastructure that automates validation, tracks changes, and provides visibility. This guide shows you how to set up the tools and workflows that make schema governance practical and sustainable.
4
6
5
7
## Set up a schema registry
6
8
7
-
A schema registry stores and versions your GraphQL schemas, acting as the source of truth for what's deployed. Without a registry, teams often discover breaking changes only after deployment, when clients start failing. A registry enables you to compare proposed changes against production schemas before merge, track which schema version each environment runs, and maintain an audit trail of who changed what and when.
9
+
A schema registry stores and versions your GraphQL schemas. Without a registry, teams often discover breaking changes only after deployment, when clients start failing. A registry enables you to compare proposed changes against production schemas before merge, track which schema version each environment runs, and maintain an audit trail of who changed what and when.
8
10
9
11
### Choose registry infrastructure
10
12
@@ -16,6 +18,12 @@ Registry options range from fully managed to DIY, depending on your team's needs
16
18
17
19
Consider data sensitivity, team size, integration with existing CI/CD workflows, federation requirements, and budget when choosing your registry infrastructure.
18
20
21
+
<Callouttype="info">
22
+
23
+
Browse [Tools and Libraries](/community/tools-and-libraries/) for current registry and schema management options. For a deeper look at the tradeoffs of building your own, see [In-House Schema Registry - the Good, the Bad, and the Ugly](https://graphql.org/conf/2024/schedule/af55205b1d68ec3b3d1b1663e4bd2adf/) from GraphQL Conf 2024.
24
+
25
+
</Callout>
26
+
19
27
### Publish schemas automatically
20
28
21
29
Integrate schema publication into deployment pipelines so the registry stays synchronized with deployed code.
This example posts the schema to a registry with version metadata.
34
42
35
-
Add publication as a deployment step after successful builds, include metadata like git commit and author, and fail deployments if publication fails.
43
+
Add publication as a deployment step after successful builds but before deployment. Include metadata like git commit and author, and fail deployments if publication fails.
36
44
37
45
## Automate validation in CI/CD
38
46
39
-
Schema validation catches problems before they reach production. The `graphql` package provides `findBreakingChanges` and `findDangerousChanges` functions that compare two schemas and return lists of differences.
47
+
Schema validation catches problems before they reach production. Tools like [graphql-inspector](https://github.com/graphql-hive/graphql-inspector) provide ready-to-use CLI commands and CI integrations for detecting breaking changes. Under the hood, the `graphql` package provides a `findSchemaChanges` function that compares two schemas and returns a list of differences, each categorized as breaking, dangerous, or safe.
40
48
41
49
**Breaking changes** will cause existing client queries to fail: removing a field, changing a field's type, or removing an enum value. These should block merges by default.
42
50
@@ -45,13 +53,18 @@ Schema validation catches problems before they reach production. The `graphql` p
45
53
Set up validation to run on every pull request that touches schema files. Most teams configure this as a required status check that must pass before merging.
@@ -118,7 +131,7 @@ Configure the workflow as a required status check in your repository settings so
118
131
For federated architectures, each subgraph must compose successfully with others before deployment. Composition failures—like conflicting type definitions or missing entity resolvers—should block merges.
119
132
120
133
```javascript
121
-
import { composeServices} from '@apollo/composition';
134
+
import { composeServices, compositionHasErrors } from '@theguild/federation-composition';
@@ -140,9 +153,15 @@ This example validates that subgraphs compose into a valid supergraph. Run compo
140
153
141
154
For teams using federation, composition validation is critical. A subgraph change that passes its own tests might still break the composed graph. Catch these issues before merge by fetching the latest schemas from other subgraphs and composing them with the proposed changes.
142
155
156
+
<Callouttype="info">
157
+
158
+
See [Federation Resources](/resources/federation/) for composition tools and gateway options.
159
+
160
+
</Callout>
161
+
143
162
## Generate reference documentation automatically
144
163
145
-
GraphQL's introspection makes documentation generation straightforward. Since your schema contains type names, field names, arguments, and descriptions, tools can generate complete API reference docs with litte manual effort.
164
+
GraphQL's introspection makes documentation generation straightforward. Since your schema contains type names, field names, arguments, and descriptions, tools can generate complete API reference docs with little manual effort. Many schema registries include built-in schema explorers that handle this automatically, but teams often want to customize the documentation experience for their API consumers.
146
165
147
166
The key to making GraphQL documentation effective is to make documentation generation automatic. Run it in CI after schema changes merge, and publish to wherever your developers look for docs.
148
167
@@ -190,6 +209,12 @@ This pattern records each field accessed during a request. Integrate it with you
190
209
191
210
For high-traffic APIs, sampling reduces overhead while still providing useful data. A 1-10% sample rate is often sufficient to identify usage patterns. Store usage data in a time-series database or analytics system where you can query trends over time, and build dashboards that show deprecated field usage as clients migrate.
192
211
212
+
<Callouttype="info">
213
+
214
+
See [Monitoring Resources](/resources/monitoring/) for tools that provide usage analytics out of the box.
215
+
216
+
</Callout>
217
+
193
218
## Integrate with developer tools
194
219
195
220
The earlier developers catch issues, the cheaper they are to fix. Integrate governance checks into the places developers already work: editors, CLI tools, and local development environments.
@@ -245,7 +270,7 @@ Automated alerts ensure the right people know about schema issues without manual
245
270
246
271
### Alert on deprecated field usage
247
272
248
-
When clients continue using deprecated fields as the removal deadline approaches, send notifications to the responsible teams.
273
+
Schema-level `@deprecated` directives tell client developers that a field will go away, but they're easy to overlook. Usage-based alerts add concrete impact: which clients are still calling the field, how often, and how close the removal deadline is. This makes the notification actionable rather than informational.
@@ -277,40 +302,20 @@ Configure your CI system to send notifications to a dedicated channel when schem
277
302
278
303
For federated graphs, composition failures in one subgraph can block other teams. Set up alerts that notify affected teams immediately when composition breaks, including which subgraph caused the failure and what types are in conflict.
279
304
280
-
## Plan for rollbacks
281
-
282
-
Even with thorough validation, problematic schema changes occasionally reach production. Prepare rollback procedures before you need them.
283
-
284
-
### Keep previous schema versions accessible
285
-
286
-
Your schema registry should maintain a history of deployed schemas. When issues arise, you need to quickly identify which version was stable and redeploy it.
Even with thorough validation, problematic schema changes occasionally reach production. Treat your API like a database: once a change is live and clients depend on it, always move forward rather than rolling back.
303
308
304
-
This example retrieves a previous schema version and republishes it as the current version.
309
+
### Fix forward
305
310
306
-
### Document rollback procedures
311
+
Rolling back a schema can break clients that already adapted to the new version. Instead, fix issues by shipping a new schema change that corrects the problem while preserving compatibility with existing clients.
307
312
308
-
Create runbooks that describe how to roll back schema changes. Include how to identify the last known good schema version, steps to redeploy the previous schema, how to communicate the rollback to client teams, and post-rollback verification steps.
313
+
When a problematic field is deployed, add the corrected field alongside it and deprecate the broken one. When a type change causes errors, extend the schema to support both the old and new shapes while you migrate clients. This keeps the API moving in one direction and avoids creating a second breaking change for clients that already updated.
309
314
310
-
Test rollback procedures periodically. A rollback process you've never run is a rollback process that might fail when you need it most.
315
+
### Keep schema history for debugging
311
316
312
-
### Handle data-dependent rollbacks
317
+
Your schema registry should maintain a history of deployed schemas. This history is valuable for debugging and auditing, not for rollbacks. When issues arise, you can compare the current schema against previous versions to identify exactly what changed and plan your fix-forward strategy.
313
318
314
-
Some schema changes depend on underlying data changes. Rolling back the schema without rolling back the data can cause errors. Document which schema changes have data dependencies and what order operations must happen during rollback.
319
+
### When rollbacks are an option
315
320
316
-
For complex changes, consider deploying schema and data changes in separate releases. This gives you more granular rollback options if issues arise.
321
+
For internal APIs where you control all clients, or for changes caught before any client adoption, a rollback may be the fastest path to resolution. If your team does need this option, keep previous schema versions accessible in your registry and document the procedure in advance. But for public or widely consumed APIs, fixing forward is almost always the safer choice.
0 commit comments