W
Wasp•2w ago
Noah

How to import enums from prisma?

I have an enum defined in my prisma file, but import { User , OrganizationUserRole} from 'wasp/entities'; isn't working
9 Replies
kapa.ai
kapa.ai•2w ago
Hi @Noah. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- I apologize, but based on the provided knowledge sources, there isn't currently direct support for importing Prisma enums in Wasp. The ability to use Prisma enums is a feature that is not yet implemented in Wasp, but it's on their roadmap for future development. According to the Github issue tracking Prisma support expansion, support for enum declarations in PSL (Prisma Schema Language) is one of the items they plan to add in the future. As a workaround, one user suggested creating a seeder function that uses $executeRawUnsafe to create the enum in the database, and upgrading to Prisma 5.10.2. However, this is not an official solution and may have limitations. The Wasp team is aware of this limitation and plans to address it in future updates. They're working on a larger overhaul of how Prisma is used in Wasp, which should unlock many features including enum support. For now, you may need to find alternative ways to represent the data in your Wasp project without using Prisma enums. If this feature is critical for your project, you might want to keep an eye on Wasp's upcoming releases or consider reaching out to the Wasp team on their Discord channel for more specific advice on workarounds. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @Noah, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
Vinny (@Wasp)
Vinny (@Wasp)•2w ago
is the bot right here @miho ?
miho
miho•7d ago
The bot is not 100% correct, we support enums in the Prisma file. You can't import them from wasp/entities... you can import them from @prisma/client but only on the server. e.g. import { Enum } from '@prisma/client';
genyus
genyus•7d ago
@miho Can I just check something? I'm importing Prisma enum types in client-side code for type checking, e.g. JobActions.tsx:
import type { JobListingStatus as PrismaJobListingStatus } from '@prisma/client';

interface JobActionsProps {
handleStatusChange: (id: string, status: PrismaJobListingStatus) => Promise<void>;
status: PrismaJobListingStatus;
}
import type { JobListingStatus as PrismaJobListingStatus } from '@prisma/client';

interface JobActionsProps {
handleStatusChange: (id: string, status: PrismaJobListingStatus) => Promise<void>;
status: PrismaJobListingStatus;
}
Is this a practise I should avoid?
miho
miho•7d ago
If you are importing them using import type you are good đź‘Ť Typescript strips away the type imports which then can't cause issues in the browser. Imports of server-side values like enum values can't be stripped and cause issues.
genyus
genyus•7d ago
Great, thanks. I did try importing the enums initially and discovered that wouldn't work, so I use const object literals with the same values for value checking instead.
Vinny (@Wasp)
Vinny (@Wasp)•7d ago
what would be an example of that? so if, e.g., an enum had a value API_KEY: process.env.API_KEY it would strip that out when using import type on the client?
miho
miho•7d ago
import type can only be used to import types and not values. Typescript compiler strips out all type info when compiling to Javascript. For example, our full-stack type safety relies on this. Normally we aren't allowed to import stuff from the server on the client, but if it's only types when the code reaches the browser - it no longer has type imports and it's completely valid to run in the browser. import type is a nice way of giving extra info to the Typescript compiler "hey, I'm only importing types here, you can get rid of this whole import statement"
Vinny (@Wasp)
Vinny (@Wasp)•4d ago
ah ok. I use it all the time and never knew the difference 🙂

Did you find this page helpful?