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)16mo 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
MrDiamond16mo ago
Thanks
Vinny (@Wasp)
Vinny (@Wasp)16mo ago
did that work?
MrDiamond
MrDiamond16mo ago
yep
MEE6
MEE616mo ago
Wohooo @MrDiamond, you just became a Waspeteer level 1!
martinsos
martinsos16mo 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)16mo 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
MrDiamond16mo ago
It didn’t include user by default so it looks like it only includes primitive types by default
martinsos
martinsos16mo ago
right that makes sense! These are connections at the end so they are more expensive to fetch
fossfighter
fossfighter16mo 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
martinsos16mo ago
Ouh blurgh! What do they say, do they have any solution in the plans for this?
fossfighter
fossfighter16mo 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