Prisma generates enums as string while NestJS GraphQL generates as real enum.
See original GitHub issueProblem
enums are scalar types in Prisma & generated like this;
export const Continent: {
Asia: 'Asia',
Europe: 'Europe',
America: 'America',
Africa: 'Africa'
};
export type Continent = (typeof Continent)[keyof typeof Continent]
However, for instance in Nestjs GraphQL, the same enum is generated as enum like this;
export enum Continent {
Asia = "Asia",
Europe = "Europe",
America = "America",
Africa = "Africa",
Australia = "Australia"
}
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!)
Issue Analytics
- State:
- Created a year ago
- Reactions:11
- Comments:9 (2 by maintainers)
Top Results From Across the Web
Using enums from prisma in nestJS graphQL models
When running this code, I'm getting the following error: UnhandledPromiseRejectionWarning: Error: Cannot determine a GraphQL output type for the ...
Read more >Unions and Enums | NestJS - A progressive Node.js framework
To define an enumerator in the schema first approach, simply create a GraphQL enum with SDL. Sometimes a backend forces a different value...
Read more >Data model (Reference) - Prisma
Learn about the concepts for building your data model with Prisma: Models, scalar types, enums, attributes, functions, IDs, default values and more.
Read more >Enums - TypeGraphQL
Creating enum. Let's create a TypeScript enum. It can be a numeric or string enum - the internal values of enums are taken...
Read more >prisma-nestjs-graphql - npm
Generate object types, inputs, args, etc. from prisma schema file for usage with @nestjs/graphql module. Latest version: 17.0.2, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
have exactly the same issue!