DevThoughts
DevThoughts
TtRPC
Created by Jonathan on 11/22/2023 in #❓-help
Type 'QueryClient' is missing the following properties from type 'QueryClient': queryCache, mutation
@Jonathan What was the slutation? I am using "@trpc/react-query": "^10.38.5",
6 replies
TtRPC
Created by DevThoughts on 4/23/2023 in #❓-help
Delete item {0: {json:{id: 12324}}}
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 ?
17 replies
TtRPC
Created by DevThoughts on 4/23/2023 in #❓-help
Delete item {0: {json:{id: 12324}}}
Btw, what is the best to send server error to the client, if i want to show toast or notification?
17 replies
TtRPC
Created by DevThoughts on 4/23/2023 in #❓-help
Delete item {0: {json:{id: 12324}}}
I was getting undefind but not error, for some reason it is working now, but unclear why it didn't work. thank you!
17 replies
TtRPC
Created by DevThoughts on 4/23/2023 in #❓-help
Delete item {0: {json:{id: 12324}}}
yes, then i can not understand when i am not able to delete item by it id.
17 replies
TtRPC
Created by DevThoughts on 4/23/2023 in #❓-help
Delete item {0: {json:{id: 12324}}}
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) return https://${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>; `
17 replies
TtRPC
Created by DevThoughts on 4/23/2023 in #❓-help
Delete item {0: {json:{id: 12324}}}
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, });
17 replies
TtRPC
Created by DevThoughts on 4/23/2023 in #❓-help
Delete item {0: {json:{id: 12324}}}
I did nothing with batching i have normal Nextjs app configured with TRPC.
17 replies
TtRPC
Created by DevThoughts on 4/20/2023 in #❓-help
where is useQuery [key]?
Yes, i have been reading the docs. How do i invalidateQueries when i use useMutation? i don't know my queryKey name? Thank you.
7 replies
TtRPC
Created by DevThoughts on 4/19/2023 in #❓-help
Nextjs http endpoint (no prisma)
yes, it did show up 🙂 Now i am unsure if this is right way to add types getAllTodos: publicProcedure.query(() => { const data = fetch(url).then( (res): Promise<{ id: number; title: string; completed: boolean }[]> => res.json() ); return data; }),
9 replies
TtRPC
Created by DevThoughts on 4/19/2023 in #❓-help
Nextjs http endpoint (no prisma)
Making a todos route but not getting type completion.
9 replies
TtRPC
Created by DevThoughts on 4/19/2023 in #❓-help
Nextjs http endpoint (no prisma)
I started to understand: import { z } from "zod"; import { createTRPCRouter, publicProcedure } from "~/server/api/trpc"; const url = "https://jsonplaceholder.typicode.com/todos"; export const exampleRouter = createTRPCRouter({ hello: publicProcedure .input(z.object({ text: z.string() })) .query(({ input }) => { return { greeting: Hello ${input.text}, }; }), getAllTodos: publicProcedure.query(async () => { const res = await fetch(url); const data = await res.json(); return data as Todo[]; }), });
9 replies
TtRPC
Created by DevThoughts on 4/19/2023 in #❓-help
Nextjs http endpoint (no prisma)
Thank you!
9 replies