Provide a way to user for populating user as part of another Prisma entity
Martinsos opened this issue · comments
Imagine we have User and we have Task and User has Tasks.
If we want to fetch all the Tasks but also get info on each of their user, something like name, or email, or similar, this is not so easy to do in Wasp right now.
You have to manually do that complicating inclusion:
export const getAllTasks = (async (args, context) => {
return context.entities.Task.findMany({
orderBy: { id: 'desc' },
select: {
id: true,
title: true,
user: {
include: {
auth: {
include: {
identities: {
// Including only the `providerName` and `providerUserId` fields
select: {
providerName: true,
providerUserId: true,
},
},
},
},
},
},
},
})
})
We explain this in the docs now, but still, it is a lot of code to write and easy to make a mistake.
We should look into providing a helper function for this, that would cover this auth -> identities -> ...
part for them.
Discord convo that inspired this issue: https://discord.com/channels/686873244791210014/1240036869723525183/1240036869723525183 .