Skip to content

Commit 6caa093

Browse files
committed
fix prettier and feedback
1 parent 9504173 commit 6caa093

2 files changed

Lines changed: 46 additions & 41 deletions

File tree

src/pages/learn/_meta.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ export default {
3737
performance: "",
3838
security: "",
3939
federation: "",
40-
"-- 3": {
40+
"-- 3": {
4141
type: "separator",
4242
title: "Schema Governance",
4343
},
44-
"governance-tooling": "",
44+
"governance-tooling": "",
4545
}

src/pages/learn/governance-tooling.mdx

Lines changed: 44 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
import { Callout } from "nextra/components"
2+
13
# Tooling and Automation for Governance
24

35
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.
46

57
## Set up a schema registry
68

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.
810

911
### Choose registry infrastructure
1012

@@ -16,6 +18,12 @@ Registry options range from fully managed to DIY, depending on your team's needs
1618

1719
Consider data sensitivity, team size, integration with existing CI/CD workflows, federation requirements, and budget when choosing your registry infrastructure.
1820

21+
<Callout type="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+
1927
### Publish schemas automatically
2028

2129
Integrate schema publication into deployment pipelines so the registry stays synchronized with deployed code.
@@ -32,11 +40,11 @@ await fetch(`${registryUrl}/schema/publish`, {
3240

3341
This example posts the schema to a registry with version metadata.
3442

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.
3644

3745
## Automate validation in CI/CD
3846

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.
4048

4149
**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.
4250

@@ -45,13 +53,18 @@ Schema validation catches problems before they reach production. The `graphql` p
4553
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.
4654

4755
```javascript
48-
import { findBreakingChanges, findDangerousChanges } from 'graphql';
56+
import {
57+
findSchemaChanges,
58+
BreakingChangeType,
59+
DangerousChangeType,
60+
} from 'graphql';
4961

5062
const currentSchema = await fetchFromRegistry('production');
5163
const proposedSchema = await loadLocal('./schema.graphql');
5264

53-
const breaking = findBreakingChanges(currentSchema, proposedSchema);
54-
const dangerous = findDangerousChanges(currentSchema, proposedSchema);
65+
const changes = findSchemaChanges(currentSchema, proposedSchema);
66+
const breaking = changes.filter(c => c.type in BreakingChangeType);
67+
const dangerous = changes.filter(c => c.type in DangerousChangeType);
5568

5669
if (breaking.length > 0) {
5770
console.log('Breaking changes:', breaking.map(c => c.description));
@@ -118,7 +131,7 @@ Configure the workflow as a required status check in your repository settings so
118131
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.
119132
120133
```javascript
121-
import { composeServices } from '@apollo/composition';
134+
import { composeServices, compositionHasErrors } from '@theguild/federation-composition';
122135

123136
const subgraphs = [
124137
{ name: 'users', typeDefs: usersSchema },
@@ -128,7 +141,7 @@ const subgraphs = [
128141

129142
const result = composeServices(subgraphs);
130143

131-
if (result.errors?.length > 0) {
144+
if (compositionHasErrors(result)) {
132145
console.error('Composition failed:', result.errors);
133146
process.exit(1);
134147
}
@@ -140,9 +153,15 @@ This example validates that subgraphs compose into a valid supergraph. Run compo
140153

141154
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.
142155

156+
<Callout type="info">
157+
158+
See [Federation Resources](/resources/federation/) for composition tools and gateway options.
159+
160+
</Callout>
161+
143162
## Generate reference documentation automatically
144163

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.
146165

147166
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.
148167

@@ -190,6 +209,12 @@ This pattern records each field accessed during a request. Integrate it with you
190209

191210
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.
192211

212+
<Callout type="info">
213+
214+
See [Monitoring Resources](/resources/monitoring/) for tools that provide usage analytics out of the box.
215+
216+
</Callout>
217+
193218
## Integrate with developer tools
194219

195220
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
245270
246271
### Alert on deprecated field usage
247272
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.
249274
250275
```javascript
251276
async function checkDeprecationDeadlines(usageData, deprecations) {
@@ -277,40 +302,20 @@ Configure your CI system to send notifications to a dedicated channel when schem
277302
278303
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.
279304
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.
305+
## Handle production issues
287306
288-
```javascript
289-
async function rollbackSchema(environment, targetVersion) {
290-
const previousSchema = await registry.getSchema(environment, targetVersion);
291-
292-
await registry.publish({
293-
environment,
294-
schema: previousSchema,
295-
metadata: {
296-
type: 'rollback',
297-
rolledBackFrom: await registry.getCurrentVersion(environment),
298-
reason: 'Production issue detected'
299-
}
300-
});
301-
}
302-
```
307+
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.
303308
304-
This example retrieves a previous schema version and republishes it as the current version.
309+
### Fix forward
305310
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.
307312
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.
309314
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
311316
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.
313318
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
315320
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

Comments
 (0)