-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Prisma generates enums as string while NestJS GraphQL generates as real enum. #12659
Comments
have exactly the same issue! |
Same issue here. Maybe prisma could also generate an Enum* form to keep everyone happy and maintain compatibility. E.g. add export EnumContinent { ... Alternatively nestjs could update registerEnumType to also take the const form that prisma generates. Until then, I can't seem to find any work around except for duplicating the definition in enum form. |
Completely agree on this! |
Same issue for me! |
Same issue. |
Same for MongoDB, it converts enum names to strings instead of scalars, despite the documentation stating that they're scalars. |
Can you point out that part of documentation @matteopolak? |
It looks like the official documentation says scalar (includes string), but in a few GitHub issues like this one says they're stored as integers. However, the generated enum values in prisma-client-js are strings, and they're stored in the database as strings too. It doesn't look like there's a way (at least that I could find) to represent them as integers, unless I define the enums in TypeScript and use an Int field in my Prisma schema. |
Enums being stored as integers is an internal implementation detail of the databases. Prisma just uses the enum implementation of a database usually. "Prisma scalars" in the context of the documentation differentiates them from relations. This issue is about changing what Prisma Client returns from strings to "real" JS/TS enums as suggested in the original issue description. I don't think the documentation currently defines either behavior. |
Any update on this? |
Have exactly the same issue! Maybe exists solutions? |
If using graphql-codegent setting |
Problem
enums are scalar types in Prisma & generated like this;
However, for instance in Nestjs GraphQL, the same enum is generated as enum like this;
As a result, these two Continents are not assignable, Prisma one is string, GraphQL one is enum. This causes problems is resolvers when we return them.
Suggested solution
In my opinion, Prisma should create enums as a real enum! At least, we sould be able to overwrite the default enum generation in Prisma. (If it's not already available. I hope it is!)
The text was updated successfully, but these errors were encountered: