Entity in Typescript does not have all properties

I have this entity
entity Module {=psl
id Int @id @default(autoincrement())
name String
user User @relation(fields: [userId], references: [id])
userId Int
notebooks Notebook[]
tasks Task[]
psl=}
entity Module {=psl
id Int @id @default(autoincrement())
name String
user User @relation(fields: [userId], references: [id])
userId Int
notebooks Notebook[]
tasks Task[]
psl=}
and a query to get modules from a user
export const getModules: GetModules<void, Module[]> = (args: any, context: any) => {
if (!context.user) {
throw new HttpError(401);
}

return context.entities.Module.findMany({
where: {user: {id: context.user.id}}
});
};
export const getModules: GetModules<void, Module[]> = (args: any, context: any) => {
if (!context.user) {
throw new HttpError(401);
}

return context.entities.Module.findMany({
where: {user: {id: context.user.id}}
});
};
but when I use this on the frontend, it returns an entity that does not match the prisma entity. It is missing the tasks, user, and notebooks properties.
No description
12 Replies
Vinny (@Wasp)
Vinny (@Wasp)2y ago
In your return statement, add a ‘select’ property and explicitly state the Module fields you want returned, e.g: where: {}, select: { id: true, … user: true, tasks, true, }
MrDiamond
MrDiamondOP2y ago
Thanks
Vinny (@Wasp)
Vinny (@Wasp)2y ago
did that work?
MrDiamond
MrDiamondOP2y ago
yep
MEE6
MEE62y ago
Wohooo @MrDiamond, you just became a Waspeteer level 1!
martinsos
martinsos2y ago
@Vinny (@Wasp) so prisma by default returns no fields? Interesting, I thought that by default it would return all of them!
Vinny (@Wasp)
Vinny (@Wasp)2y ago
i think it just doesn't return lists by default. not sure this might actually be a better solution;
const posts = await prisma.post.findMany({
include: {
comments: true, // this will include the list of related comments
},
})
const posts = await prisma.post.findMany({
include: {
comments: true, // this will include the list of related comments
},
})
MrDiamond
MrDiamondOP2y ago
It didn’t include user by default so it looks like it only includes primitive types by default
martinsos
martinsos2y ago
right that makes sense! These are connections at the end so they are more expensive to fetch
fossfighter
fossfighter2y ago
right, Prisma by default does not include any connections, you have to specify which one you need. And it's pain when you have self-relations e.g. categories, you have to specify which depth level you need even though you can't know it at compile time if you need all of them
martinsos
martinsos2y ago
Ouh blurgh! What do they say, do they have any solution in the plans for this?
fossfighter
fossfighter2y ago
I found an issue from 2020 related to this https://github.com/prisma/prisma/issues/3725, it is upvoted enough but didn't receive any feedback from Prisma team neither there is something similar in their roadmap https://pris.ly/roadmap
GitHub
Issues · prisma/prisma
Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server, SQLite, MongoDB and CockroachDB - Issues · prisma/prisma
Prisma on Notion
Prisma ORM Roadmap
Our roadmap shares our current priorities. It displays an Initiatives board, showing what we are currently working on, and plan to do next.
Want results from more Discord servers?
Add your server