backend receiving empty input object when using mutation in tRPC

147 Views Asked by At

When using useQuery I have no issues even with input but when using useMutation the backend is receiving an empty input. What could be the reason?

stack is nodejs + express + reactjs + yarn

Frontend code:

const devCompanyMutation = trpc.devCompany.create.useMutation();

const onSubmit = (latestDoc: T_Insert_DevCompany) => { 
    console.log({latestDoc}); 
    devCompanyMutation.mutate(latestDoc); 
};

Backend code:

export const devCompanyRouter = router({
    create: publicProcedure 
        .input(z.object({ name: z.string().nullish() }).nullish()) 
        .mutation(({ input }) => { 
            console.log({input}) 
            return input; 
        }) 
})

I setting up tRPC for the first time for my new project... so possible that I am doing something basic or config level wrong. Any help would be great. Thanks!

1

There are 1 best solutions below

0
On

If you're using superjson in server make sure to add it in client also, the docs specify how to use it https://trpc.io/docs/server/data-transformers#using-superjson.