Theo's Typesafe CultTTC
Theo's Typesafe Cult3y ago
15 replies
nickparks

Any ideas why TRPC doesnt find the mutation?

I have am trying to use a create many Prisma call in a TRPC mutation as follows:

import { z } from "zod";

import { clerkClient } from "@clerk/nextjs/server";
import { filterUserForClient } from "~/server/helpers/filterUserForClient";
import type { TeamMember } from "@prisma/client";

import {
  createTRPCRouter,
  privateProcedure,
  publicProcedure,
} from "~/server/api/trpc";
import { TRPCError } from "@trpc/server";

export const activityRouter = createTRPCRouter({
  startRace: privateProcedure
    .input(z.object({ id: z.string() }))
    .mutation(async ({ ctx, input }) => {
      try {
        const race = await ctx.prisma.race.findFirst({
          where: { id: input.id },
        });

        const createMany = await ctx.prisma.activeTask.createMany({
          data: [
            {
              taskId: "clgzk25a30000q74rrov7jvnm",
              teamId: "clgzep8kl0000q7vkbngr1ecm",
            },
            {
              taskId: "clgzk25a30000q74rrov7jvnm",
              teamId: "clgzep8kl0000q7vkbngr1ecm",
            },
            {
              taskId: "clgzk25a30000q74rrov7jvnm",
              teamId: "clgzep8kl0000q7vkbngr1ecm",
            },
          ],
          skipDuplicates: true,
        });

        return createMany;
      } catch (error) {
        console.log(error);
      }
    }),
});


Which is exported via the following router:

export const appRouter = createTRPCRouter({
  race: raceRouter,
  team: teamRouter,
  location: locationRouter,
  task: taskRouter,
  activity: activityRouter,
});


This is how I have setup all my mutations elsewhere. However, this one consistently gives a TRPC error as follows:

 ❌ tRPC failed on activity.startRace: No "mutation"-procedure on path "activity.startRace" 


Any ideas why this could be happening? My deepdive leads me to believe that this is due to CreateMany but not sure what teh best way to structure such is?
Was this page helpful?