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);
}
}),
});
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,
});
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"
❌ 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?
9 Replies
dopeinc
dopeinc2y ago
How are you calling the trpc mutation ? Also are you using mongo or sqlserver ?
nickparks
nickparksOP2y ago
Sure, for now its pretty simple
const { mutate } = api.activity.startRace.useMutation({});
const { mutate } = api.activity.startRace.useMutation({});
and
<button onClick={() => mutate({ id: id })}>Start</button>
<button onClick={() => mutate({ id: id })}>Start</button>
Using SQLServer (planetscale)
dopeinc
dopeinc2y ago
Okay pscale is mysql i dont think its sql server , but all of this seems fine let me keep digging prisma says you cant use skipduplicate on sqlserver but I don't think its that since pscale is mysql . But you could try without it I would go step by step and comment out stuff inside the mutation. make it simple just logging input data and from there expand. I have no clue. everything seems fine at first glance
nickparks
nickparksOP2y ago
unfortunately seems to still hit the same error 😦
dopeinc
dopeinc2y ago
you can just call a clog mutation console.log*
nickparks
nickparksOP2y ago
thanks, yeah let me try this 🙂 agree, seems odd cause its as i always call other mutations.
dopeinc
dopeinc2y ago
did you restart you server ? just in case and or update the libs if there are update.
nickparks
nickparksOP2y ago
Damn, I think I found it! Diving into the console log - kept showing 404s (even on new routes I added to my TPRC file). Made me wonder whether 'activity' (as I called it) was a reserved namespace of sorts - seems thats exactly it. Assumed typescript/vscode wouldve complained if it was. Working now with a different name. thanks for the help
dopeinc
dopeinc2y ago
Oh interesting…. I wonder why ill look into it thanks for clarifying
Want results from more Discord servers?
Add your server