Theo's Typesafe CultTTC
Theo's Typesafe Cult4y ago
3 replies
jack

Prisma object undefined on mutation

My schemas look like this
model Idea {
    id          String     @id @default(cuid())
    title       String
    description String
    createdAt   DateTime   @default(now())
    rating      Int        @default(0)
    slug        String     @unique
    ideaNotes   IdeaNote[]
}

model IdeaNote {
    id        String   @id @default(cuid())
    createdAt DateTime @default(now())
    text      String
    idea      Idea     @relation(fields: [ideaId], references: [id])
    ideaId    String
}
and the mutation in question is
  submitIdeaNote: t.procedure
    .input(
      z.object({
        message: z.string(),
        ideaId: z.string(),
      })
    )
    .mutation(async ({ ctx, input }) => {
      if (!input || !input.message) {
        return { error: "Missing title or description" };
      }

      return await ctx.prisma.ideaNote.create({
        data: {
          text: input.message,
          ideaId: input.ideaId,
        },
      });
    }),

can't tell if i'm just being dumb or not
Was this page helpful?