Support deriving @gqlEnum from const arrays and const objects#225
Merged
captbaritone merged 3 commits intomainfrom Apr 1, 2026
Merged
Support deriving @gqlEnum from const arrays and const objects#225captbaritone merged 3 commits intomainfrom
captbaritone merged 3 commits intomainfrom
Conversation
Add support for two new patterns for defining GraphQL enums with runtime-accessible values: - Const array: `(typeof VALUES)[number]` - Const object: `(typeof OBJ)[keyof typeof OBJ]` The const declaration must be the immediately preceding statement before the @gqlEnum type alias, ensuring it's clear which declarations contribute to the GraphQL schema. This avoids introducing name resolution into the Extractor. Const objects support descriptions and @deprecated on properties. Const arrays share the same limitation as union-of-literal enums (no per-value metadata), since TypeScript doesn't attach JSDoc to array elements. Also fixes TypeContext.findSymbolDeclaration to prefer declarations registered in the GraphQL schema when a symbol has multiple declarations (needed for the `const X` + `type X` same-name pattern). Closes #205. Supersedes #215.
✅ Deploy Preview for grats ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Replace inline code blocks with compiled GratsCode snippets so the examples are validated by the Grats compiler. Also add a comment to the array-with-description test fixture explaining that descriptions on array elements are silently ignored.
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
@gqlEnumfrom const arrays ((typeof X)[number]) and const objects ((typeof X)[keyof typeof X]), allowing runtime-accessible enum values without using TypeScript'senumsyntax.@deprecatedon properties. Const arrays share the same limitation as union-of-literal enums (no per-value metadata).TypeContext.findSymbolDeclarationto prefer declarations registered in the GraphQL schema when a symbol has multiple declarations (needed for theconst X+type Xsame-name pattern).Closes #205. Supersedes #215.
Test plan
as const satisfies, namespace scope, function scope, descriptions,@deprecatedas const, const not preceding, name mismatchgraphQLNameValidationMessageis needed (graphql-js throws unlocated errors without it)