Skip to content

fix(core): migrate deprecated graphql-js APIs for v17/v18 compat - #1667

Open
babbarankit wants to merge 1 commit into
hayes:mainfrom
babbarankit:fix/graphql-v18-deprecated-apis
Open

fix(core): migrate deprecated graphql-js APIs for v17/v18 compat#1667
babbarankit wants to merge 1 commit into
hayes:mainfrom
babbarankit:fix/graphql-v18-deprecated-apis

Conversation

@babbarankit

Copy link
Copy Markdown

Summary

Closes #1637

Fixes enum and custom scalar default values breaking in graphql v17+. The root cause: graphql v17 validates default values using getDefaultValueAST() which requires the default: { value } API (external values), not just the deprecated defaultValue (internal values).

Key insight — the value-shape trap

astFromValue(value, type) takes internal/coerced values (e.g., 2 for enum TWO).
valueToLiteral(value, type) takes external values (e.g., "TWO").
Naive swap silently corrupts enum and custom scalar defaults.

Approach: serialize internal→external at build time

Rather than swapping astFromValuevalueToLiteral, we:

  1. Serialize internal values to external form via type.serialize() at build time
  2. Emit default: { value: serialized } alongside deprecated defaultValue
  3. Prefer stored AST literals from v17+ default API in mock-ast, falling back to astFromValue (v16/v17) then valueToLiteral + serialize (v18+)

Files changed

File Change
core/src/build-cache.ts Emit default: { value: serializeDefaultValue(...) } in buildInputFields()
plugin-directives/src/mock-ast.ts Replace 3x astFromValue() with internalValueToLiteral() helper
plugin-add-graphql/src/schema-builder.ts Read from .default?.value ?? .defaultValue
plugin-sub-graph/src/index.ts Copy default property in config reconstruction
converter/src/index.ts Read from .default?.value ?? .defaultValue

Backward compat

All changes are additive — graphql v16 ignores unknown config keys, v17+ uses them. No breaking changes.

Test plan

  • 155 tests pass across 8 packages (core, directives, prisma, sub-graph, add-graphql, relay, federation, converter)
  • Fixes 2 pre-existing test failures in plugin-directives (enum default values in printSchema and validateSchema)
  • New test: validates printSchema produces enumWithDefault: EN = TWO for enum with internal value 2
  • Existing test validates AST structure for enum/boolean/string/ID/list defaults

🤖 Generated with Claude Code

Fixes enum and custom scalar default values breaking in graphql v17+.
The root cause: graphql v17 requires `default: { value }` (external form)
instead of just `defaultValue` (internal form) for enum/scalar types.

Changes:
- build-cache.ts: emit `default: { value: serialized }` alongside
  `defaultValue` — serializes internal→external via type.serialize()
  for enums (e.g., internal 2 → external "TWO") and custom scalars
- mock-ast.ts: replace 3x astFromValue() calls with internalValueToLiteral()
  helper that prefers stored AST literals (v17+ default API), falls back
  to astFromValue (v16/v17), then valueToLiteral+serialize (v18+)
- plugin-add-graphql: read default values from both v17+ .default?.value
  and deprecated .defaultValue
- plugin-sub-graph: copy v17+ 'default' property in config reconstruction
- converter: read default values from both API forms

Backward compat: all changes are additive — v16 ignores unknown config
keys, v17 uses them. No breaking changes.

Fixes 2 pre-existing test failures in plugin-directives (enum default
values in printSchema and validateSchema).

Closes hayes#1637

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@vercel

vercel Bot commented Sep 6, 2026

Copy link
Copy Markdown

@babbarankit is attempting to deploy a commit to the Michael Hayes' projects Team on Vercel.

A member of the Team first needs to authorize it.

@changeset-bot

changeset-bot Bot commented Sep 6, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 5420506

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrate off graphql APIs deprecated in 17 / removed in 18 (defaultValue, astFromValue, scalar coercion)

1 participant