wasp-lang / wasp

The fastest way to develop full-stack web apps with React & Node.js.

Home Page:https://wasp-lang.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.