-
Notifications
You must be signed in to change notification settings - Fork 382
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enums with one key are treated as String literals #3025
Labels
Comments
Would you like to create a PR for this issue? |
I could, but I'm not exactly sure of the best way to work around this. The simplest change would be to add another flag check here, but I'm not sure if that's the best way to go about it. |
This is a regression, it was fine with v11.0.5 but I'm getting this issue with v12.0.0 and onward. It makes us unable to update to Nest v10... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is there an existing issue for this?
Current behavior
When defining a field for an object, using an enum with exactly 1 key will result in that field being seen as a String, rather than an enum.
Example
Where the resulting schema will provide a reference to
MultipleEnum
, but seesingleEnum
as just a string.The type information for this the single-keyed enum field sets its
flags
as 1152, or 1024 | 128, or EnumLiteral | StringLiteral.When it's then parsed, it will check if it's a string first before checking if it's an enum.
I can also see that (with local edits of the plugin) removing this check restores original functionality, although I imagine it's still useful to have.
Minimum reproduction code
https://github.com/IodizedGabe/nestjs-graphql-enum-as-string
Steps to reproduce
yarn install
yarn build
_GRAPHQL_METADATA_FACTORY
forClassA
in./dist/graphql.entity.js
For me, I see:
Expected behavior
An enum with one key should be treated like any other enum and given a proper type / reference in the schema.
Package version
12.0.9
Graphql version
graphql
: 16.8.1NestJS version
10.2.7
Node.js version
18.15.0
In which operating systems have you tested?
Other
typescript
: 5.1.6The text was updated successfully, but these errors were encountered: