Implementing Schema Versioning

1. Understanding API Versioning

StrategyGraphQL Equivalent
URL versioning (REST)Avoided — single endpoint
Schema evolutionAdd fields, deprecate old
Per-field deprecation@deprecated reason
Namespace typesOptional v2_User for major rewrites

2. Using Field Deprecation

Example: Deprecating with reason

type User {
  fullName: String! @deprecated(reason: "Use firstName + lastName since 2026-01")
  firstName: String!
  lastName: String!
}

3. Implementing Graceful Deprecation

Deprecation Lifecycle

  1. Add new field/type alongside old
  2. Mark old as @deprecated with migration hint
  3. Track usage via Apollo Studio / operation logs
  4. Communicate timeline to clients
  5. Wait for usage to drop near zero
  6. Remove old field in next major release

4. Adding New Fields

RuleDetail
Always safeExisting clients ignore unknown fields
Default nullableAvoid forcing existing data to provide value
DocumentInclude description string

5. Using Optional Arguments

Type of ChangeSafety
Add nullable argSafe
Add required arg without defaultBreaking
Add required arg with defaultSafe
Remove argBreaking

6. Implementing Breaking Changes

ChangeMigration
Type changeAdd new field with new type, deprecate old
Required arg addedUse new field name to opt in
Field removalLong deprecation window
Enum value renameAdd new value, deprecate old, accept both

7. Versioning with Namespaces

Example: Namespace under root

type Query {
  v2: V2Query!
}
type V2Query {
  user(id: ID!): V2User
}
UseDetail
Major rewritesCoexist with v1 fields
Internal vs publicinternal { ... } namespace

8. Using Schema Directives

DirectiveUse
@deprecatedStandard deprecation
@inaccessibleHide from federation supergraph
@tagAnnotate for governance/contracts
@since(version)Custom: indicate when added

9. Communicating Changes

ChannelDetail
Schema changelogAuto-generate via graphql-inspector
Schema diff in PRCI annotation
Client notificationsEmail registered API consumers
Status pageDocument deprecation timeline

10. Migrating Clients

StepTool
Detect deprecated usagegraphql-eslint no-deprecated
Auto-migrateCodemods
Validategraphql-codegen against new schema
DeployUpdate client before server removes