prisma relations generated types

So I've ran to a problem where the generated types from prisma don't include my relationships, I've googled a bit more and saw this was an issue for many people but not many people have any answers at all, wondered if anyone here know how to deal with this? I've tried creating my own type with the prims getPayload and including my relationships but when fetching data it is automatically refering to the generated prisma types and I cant go around hardcoding that everywhere it seems like a bad idea... Trying to deploy and it keeps failing because of that 😦
10 Replies
Sybatron
Sybatron2y ago
GitHub
Generated prisma types are missing relationships in their exported ...
Bug description So I am really not sure if this is a bug, my mistake or some really stupid feature. I started using prisma in force a few days ago and so far, I love it, but I am struggling to unde...
Sybatron
Sybatron2y ago
i think it has been already answered if you mean this problem
Sybatron
Sybatron2y ago
Prisma
Operating against partial structures of your model types
This page documents various scenarios for using the generated types from the Prisma namespace
Eylon
EylonOP2y ago
Yes I've read that and used that but on someplaces in my code, the return type of my data is more complex and it's using the generated types by prisma anyways so it doesn't solve that
Eylon
EylonOP2y ago
It still searches for types from prisma
Eylon
EylonOP2y ago
anyone? 😐
jingleberry
jingleberry2y ago
How about using type inference based on the function you’re using which fetches the row + relationships?
Eylon
EylonOP2y ago
What do you mean?
jingleberry
jingleberry2y ago
function getBooks() {
return prisma.books.findMany({ include: { author: true } })
}

type BooksWithAuthor = Awaited<ReturnType<typeof getBooks>>
function getBooks() {
return prisma.books.findMany({ include: { author: true } })
}

type BooksWithAuthor = Awaited<ReturnType<typeof getBooks>>
Something like this
Eylon
EylonOP2y ago
I had to fix my function return value, it was a problem there, which is weird because the type is the same
Want results from more Discord servers?
Add your server