PrismaP
Prisma2y ago
2 replies
Florian

How do you organize your Prisma.validator schemas?

I have a bunch of predefined
select
and include schemas. Where do I put them in my project? I need some inspiration.

export function getUserDataSelect(loggedInUserId: string) {
  return Prisma.validator<Prisma.UserSelect>()({
    ...getFollowerInfoSelect(loggedInUserId),
    id: true,
    username: true,
    displayName: true,
    avatarUrl: true,
    bio: true,
    createdAt: true,
    _count: {
      select: {
        posts: true,
        followers: true,
      },
    },
  });
}

export type UserData = Prisma.UserGetPayload<{
  select: ReturnType<typeof getUserDataSelect>;
}>;
Was this page helpful?