fix(core): migrate deprecated graphql-js APIs for v17/v18 compat - #1667
Open
babbarankit wants to merge 1 commit into
Open
fix(core): migrate deprecated graphql-js APIs for v17/v18 compat#1667babbarankit wants to merge 1 commit into
babbarankit wants to merge 1 commit into
Conversation
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>
|
@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. |
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 thedefault: { value }API (external values), not just the deprecateddefaultValue(internal values).Key insight — the value-shape trap
astFromValue(value, type)takes internal/coerced values (e.g.,2for enumTWO).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
astFromValue→valueToLiteral, we:type.serialize()at build timedefault: { value: serialized }alongside deprecateddefaultValuedefaultAPI in mock-ast, falling back toastFromValue(v16/v17) thenvalueToLiteral+ serialize (v18+)Files changed
core/src/build-cache.tsdefault: { value: serializeDefaultValue(...) }inbuildInputFields()plugin-directives/src/mock-ast.tsastFromValue()withinternalValueToLiteral()helperplugin-add-graphql/src/schema-builder.ts.default?.value ?? .defaultValueplugin-sub-graph/src/index.tsdefaultproperty in config reconstructionconverter/src/index.ts.default?.value ?? .defaultValueBackward compat
All changes are additive — graphql v16 ignores unknown config keys, v17+ uses them. No breaking changes.
Test plan
printSchemaandvalidateSchema)printSchemaproducesenumWithDefault: EN = TWOfor enum with internal value2🤖 Generated with Claude Code