Skip to content
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

Support const enums for better interoperability with Prisma and other string values #3348

Open
1 task done
danomatic opened this issue Oct 25, 2024 · 3 comments
Open
1 task done
Labels

Comments

@danomatic
Copy link

Is there an existing issue that is already proposing this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe it

TypeScript enums have known issues:
https://dev.to/ivanzm123/dont-use-enums-in-typescript-they-are-very-dangerous-57bh

This is an example of this with GraphQL types generated by NestJS:
Screenshot 2024-10-25 at 1 03 30 PM

Because if this, if I have a return value from an Prisma enum

Describe the solution you'd like

By default, Prisma generates TS enums as consts, instead of enums. I recommend doing that.

GraphQL Codegen has options to help address this:
https://the-guild.dev/graphql/codegen/plugins/typescript/typescript#constenums
https://the-guild.dev/graphql/codegen/plugins/typescript/typescript#enumsastypes

I propose exposing this and other GraphQL codegen options in the API

Teachability, documentation, adoption, migration strategy

enum consts are backwards compatible, so this shouldn't hurt anything

What is the motivation / use case for changing the behavior?

enum consts just work better all around!

@kamilmysliwiec
Copy link
Member

Would you like to create a PR for this issue?

@danomatic
Copy link
Author

@kamilmysliwiec I ended up finding an existing NestJS GraphQL flag that will output the enums as a union string type and that's fine for my purposes. I don't know if that is documented anywhere and I'm googling it now and can't find anything on it.

@kamilmysliwiec
Copy link
Member

Would you like to create a PR for the docs? Ideally somewhere under this section https://docs.nestjs.com/graphql/quick-start#schema-first

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants