fix(schema): emit enum default values as enum values, not strings - #525
Merged
Conversation
value() checked `val instanceof Symbol` to decide whether to emit Kind.ENUM.
Symbols are primitives, so that is never true — the branch was unreachable and
there was no way to express an enum default at all.
Enum defaults passed as plain strings therefore fell into the STRING branch and
printed as `mutationMode: MutationMode = "STRICT"`. That is an invalid default
value for an enum: graphql 16 tolerated it, graphql 17 rejects it with
'Enum "X" cannot represent non-enum value', which blocks schema generation
entirely on graphql 17.
Fix the check to `typeof val === 'symbol'` so `defaultValue: Symbol('STRICT')`
prints as `= STRICT`. Value is already `unknown`, so no type change is needed,
and nothing can depend on the old behaviour because the branch never ran.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
nicola-smartive
marked this pull request as ready for review
July 16, 2026 17:00
|
🎉 This PR is included in version 29.2.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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.
The bug
value()insrc/schema/utils.tsdecides whether to emitKind.ENUMwith:Symbols are primitives, so
Symbol('X') instanceof Symbolis alwaysfalse. That branch has never been reachable — meaning there is currently no way to express an enum default value at all.So an enum default written the natural way,
defaultValue: 'STRICT', falls into thetypeof val === 'string'branch above and prints as:That is an invalid default for an enum. graphql 16 tolerated it; graphql 17 rejects it:
Which means schema generation fails outright on graphql 17 — a hard blocker for consumers upgrading. Found while triaging a graphql 17 bump in zwei-wealth-platform.
Worth noting the SDL we emit today is already invalid; graphql 16's leniency is the only thing hiding it. So this is a correctness fix independent of 17.
The fix
One line —
typeof val === 'symbol'— restoring the branch's evident intent.Valueis alreadyunknown, soSymbol('STRICT')is accepted.defaultValue: Symbol('STRICT')→ prints= STRICT.Tests
Added
tests/unit/enum-default-values.spec.tscovering enum-vs-string and symbols-in-lists. Verified it genuinely catches the bug: reverting the one-line fix turns it 2 failed / 1 passed, restoring it 3 passed. Full unit suite green (132 tests), lint clean.Possible follow-up (deliberately not in this PR)
A string default on an enum-typed field still silently produces invalid SDL. Making
value()type-aware (emitKind.ENUMwhen the field's type is an enum) would remove the footgun entirely, but needs the enum registry threaded into the generic AST builders — a design call for the maintainers rather than something to smuggle into a bug fix.