Delete item {0: {json:{id: 12324}}}

DDevThoughts4/23/2023
When i try to mutate/delete item with id i am geting this payload {0: {json:{id: 12324}}}, without trpc everything working fine, dont understand where the {0: {json:{id: 12324}}} coming from? what is batch 1?
Nnlucas4/23/2023
Have you enabled batching on the frontend but not the backend?
Nnlucas4/23/2023
This is a normal tRPC payload
DDevThoughts4/23/2023
I did nothing with batching i have normal Nextjs app configured with TRPC.
DDevThoughts4/23/2023
pages/api/[trpc].ts

import { createNextApiHandler } from "@trpc/server/adapters/next"; import { env } from "~/env.mjs"; import { createTRPCContext } from "~/server/api/trpc"; import { appRouter } from "~/server/api/root"; // export API handler export default createNextApiHandler({ router: appRouter, createContext: createTRPCContext, onError: env.NODE_ENV === "development" ? ({ path, error }) => { console.error(❌ tRPC failed on ${path ?? "<no-path>"}: ${error.message}); } : undefined, });
Nnlucas4/23/2023
What does you client setup look like?
Nnlucas4/23/2023
If you're using httpBatchLink you have enabled batching on the frontend
DDevThoughts4/23/2023
It look like this:

iimport { httpBatchLink, loggerLink } from "@trpc/client"; import { createTRPCNext } from "@trpc/next"; import { type inferRouterInputs, type inferRouterOutputs } from "@trpc/server"; import superjson from "superjson"; import { type AppRouter } from "~/server/api/root"; const getBaseUrl = () => { if (typeof window !== "undefined") return ""; // browser should use relative url if (process.env.VERCEL_URL) returnhttps://${process.env.VERCEL_URL}`; // SSR should use vercel url
return http://localhost:${process.env.PORT ?? 3000}; // dev SSR should use localhost
};

export const api = createTRPCNext<AppRouter>({
config() {
return {
transformer: superjson,

links: [
loggerLink({
enabled: (opts) =>
process.env.NODE_ENV === "development" ||
(opts.direction === "down" && opts.result instanceof Error),
}),
httpBatchLink({
url: ${getBaseUrl()}/api/trpc,
}),
],
};
},

ssr: false,
});

export type RouterInputs = inferRouterInputs<AppRouter>;

export type RouterOutputs = inferRouterOutputs<AppRouter>;

`
DDevThoughts4/23/2023
yes, then i can not understand when i am not able to delete item by it id.
Nnlucas4/23/2023
Nnlucas4/23/2023
You should enable batching on the backend
Nnlucas4/23/2023
I think it's actually on by default though
Nnlucas4/23/2023
What's your error exactly?
DDevThoughts4/23/2023
I was getting undefind but not error, for some reason it is working now, but unclear why it didn't work.

thank you!
DDevThoughts4/23/2023
Btw, what is the best to send server error to the client, if i want to show toast or notification?
DDevThoughts4/23/2023
Is it a bad to create createTRPCRouter function for every route, like GetAllPost, create, delete, update ? or all the route should be in same file in createTRPCRouter ?