question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Prisma generates enums as string while NestJS GraphQL generates as real enum.

See original GitHub issue

Problem

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:open
  • Created a year ago
  • Reactions:11
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
kokokenadacommented, May 7, 2022

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.

3reactions
jeckvldcommented, Apr 14, 2022

have exactly the same issue!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found