How to use Prisma model type in tRPC mutation w/ Zod

I have some models defined in my schema.prisma file. Let's say they look like this:
model Art {
  id        String @id @default(cuid())
  // Some other fields
  creators Creator[]
}

model Creator {
  id        String @id @default(cuid())
  creatorId String
  artId    String
  art      Art   @relation(fields: [artId], references: [id])
}

I am using a tRPC mutation to create an "Art" in my Planetscale database. So, since I'm using Zod, I am doing something like this:
create: privateProcedure
    .input(
      z.object({
        // Some other fields
        creators: (this is where I'm confused)
      })
    )
    .mutation(async ({ input }) => {
      const artistId = ctx.userId;

      const art = await ctx.prisma.art.create({
        data: {
          // Some other fields
          creators: input.creators,
        },
      });

      return art;
    }),

I know I can get the Creator type from Prisma, but I don't know how to tell Zod to expect those properties as the input so that the tRPC procedure will run. I hope I'm explaining this ok because it's kinda hard to put into words lol
Was this page helpful?