Entity variations
Is there a way to create variations of generated Prisma entity types?
(See docs: https://www.prisma.io/docs/orm/prisma-client/type-safety/operating-against-partial-structures-of-model-types#problem-using-variations-of-the-generated-model-type)
I have a
User
entity that has a Role
entity relation and would like to create a Wasp query that fetches both user data and the user role, returning it as 1 merged response object.
Currently I'm manually defining the query response type but would love to learn if and how Prisma/Wasp can automatically take care of this for me by using the Prisma.validator
approach as outlined in the docs.Operating against partial structures of your model types | Prisma D...
This page documents various scenarios for using the generated types from the Prisma namespace
11 Replies
Hi @WWWillems. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Hmm, I don't know enough to give you a confident answer yet. The knowledge sources provided do not contain specific information about creating variations of generated Prisma entity types using the
Prisma.validator
approach in Wasp.
However, Wasp Entities directly correspond to Prisma's data model and Wasp uses Prisma ORM to implement all database functionality. You can use Entities in your Wasp queries and Wasp will inject the specified Entity into the Query's context
argument, giving you access to the Entity's Prisma API. This might be a starting point for you to explore how to achieve your goal.
For more detailed information, you might want to check out the following resources:
- Wasp Entities (https://wasp-lang.dev/docs/data-model/entities)
- Using Entities in Queries (https://wasp-lang.dev/docs/data-model/operations/queries#using-entities-in-queries)
- Prisma's CRUD API (https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-client/crud)
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @WWWillems, 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?🥺
I'm pretty sure we expose the Prisma object somewhere. Let me check the docs
ok it seems like you can just
import { Prisma } from '@prisma/client'
in your server-side files.
then you should be able to try out the validator
method @WWWillems
FYI, I always just create the type myself, as shown here https://www.prisma.io/docs/orm/prisma-client/type-safety/operating-against-partial-structures-of-model-types#solutionok I just gave it a try and it does work @WWWillems
I used to always define the types manually, so that's for bringing this to our attention (cc: @sodic )
Interesting, I had no idea about this and will be taking a look for sure!
Thanks @Vinny (@Wasp) and @WWWillems
Hmz thought i tried it this way, travelling atm but will have another look when i get home. Thanks! 🙏
cool. let me know how it goes
Added this to the issue talking about full stack Prisma entities
Got it to work now @Vinny (@Wasp), thanks!
nice!