Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Martinsos opened this issue May 15, 2024 · 1 comment
Labels
auth enhancement New feature or request shouldfix We should do/fix this at some point

Comments

@Martinsos
Copy link
Member

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 Martinsos added enhancement New feature or request shouldfix We should do/fix this at some point auth labels May 15, 2024
@Martinsos
Copy link
Member Author

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

@Martinsos Martinsos changed the title Provide helper functions for populating user as part of another Prisma entity Provide a way to user for populating user as part of another Prisma entity May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auth enhancement New feature or request shouldfix We should do/fix this at some point
Projects
None yet
Development

No branches or pull requests

1 participant