wasp-lang / wasp

The fastest way to develop full-stack web apps with React & Node.js.
https://wasp-lang.dev
MIT License
12.76k stars 1.14k forks source link

Provide a way to user for populating user as part of another Prisma entity #2033

Open Martinsos opened 1 month ago

Martinsos commented 1 month ago

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.

Martinsos commented 1 month ago

Discord convo that inspired this issue: https://discord.com/channels/686873244791210014/1240036869723525183/1240036869723525183 .