tRPC

T

tRPC

Move Fast & Break Nothing. End-to-end typesafe APIs made easy.

Join

where does opts.path and opts.type came from ? i guess by default it only stores ctx ,next and input

```ts const loggerMiddleware = middleware(async (opts) => { const start = Date.now();   const result = await opts.next();...
Solution:

Passing objects to the next() function of the middle ware

```ts // ------------------------------------------------- // @filename: context.ts // ------------------------------------------------- import type { inferAsyncReturnType } from '@trpc/server';...

opts object passed to mutation , i can not understand where it came from

```ts export const authorizedProcedure = publicProcedure .input(z.object({ townName: z.string() })) .use((opts) => { if (opts.input.townName !== 'Pucklechurch') {...

How do I log thrown errors from the query/ mutation on the server side globally?

I was surprised to find that the server servicing tRPC requests do not log any thrown errors from a query / mutation to the console by default (but the client does capture errors). I want to be able to log all errors on the server side. How would I do this? This page doesn't really give me any clues as I don't know what trpcNext.createNextApiHandler refers to: https://trpc.io/docs/server/error-handling#handling-errors ...

trpc with app dir nextjs

Hello im wondering how to use trpc with nextjs app router now?. I have t3 app but for now its a src/pages directory structure. if i want to switch to app directory is it possible to use trpc with it?...

if I export 'appRouter' instead of 'router' I get error

hey everyone, I have this exact setup https://icflorescu.github.io/trpc-sveltekit/getting-started I created all the files inside of /src/trpc/ besides the hooks.server.ts which is inside /src/trpc/ only difference is that inside the file router.ts I've changed the variable name router in this line:
export const router = t.router({...})
export const router = t.router({...})
to ```ts...

React Native/Expo: Uncaught Error: No QueryClient set, use QueryClientProvider to set one

Found this issue but it just says to use patch-package, I was wondering if there was any changes since then? https://github.com/TanStack/query/discussions/4619...
Solution:
```typescript import { defaultContext } from "@tanstack/react-query" export const api = createTRPCReact<AppRouter>({ reactQueryContext: defaultContext,...

All values in DecoratedProcedureRecord are of type any

I've stumbled across an issue and I'm not sure how to start diagnosing it... Basically in my IDE the return type of my createTRPCProxyClient<AppRouter>(...) call is a DecoratedProcedureRecord where every value is of type any. I'm seeing a lot of issues with TS seemingly struggling to work with this repo, I suspect that the types have become too complex with tRPC and the ORM I'm using. Is it possible that TS has just "given up" so returns any instead of the expected type? Or is it likely something else?...

Detecting batch queries/mutations on the server-side

Hello all, Looking to leverage batching as a means to streamline some of our cross-service requests, both query and mutation. We have a graph of interconnected tRPC services, some of which form trees of calls where service A calls service B, and service B then calls service C. Looking to get some guidance on how to identify on the receiving side whether a particular method invocation is a part of a batch request so that I could then batch requests to a downstream service, eg. I receive 10 queries in a batch to service A, which I would then like to batch in a single call to service B, and so on. Specifically: 1. Is there a mechanism I could introspect to tell that the current method invocation (query or mutation) is part of a batch request?...

VS Code becomes unresponsive

Hello everyone, I've started to experience huge performance issues with my project that's based on create-t3-app. The issue is that after some work the intellisense and every extension becomes unresponsive. I'm aware that tRPC projects have issues with defining query/mutation props as any sometimes. But this is another level. It occurs randomly, after 5-10mins of work. The only solution for now is to quit VS Code. Then I reopen it and it crashes, after the crash I can open it and continue working normally as I usually do. ...

Middleware-ish for client

Hi! I had a quick question about client-side usage: I have users with long-running sessions, and if they tokens expire the backend returns a 401. In the old codebase I'm migrating from there was a check force a token refresh if certain parameters were met, such as status === 401, route is one of x, etc. Is there a way to handle that on the @trpc/client ? something just like: for any requests, if returned status is 401, and route is one of x, force a token refresh? Thanks!...

Why cannot I specify a mutation input with useQueryKey?

It's supported with queries, but for some reason not with mutations. Why is this the case?

how to connect trpc server (t3 stack) from my external nextjs app?

how to connect trpc server (t3 stack) from my external nextjs app?

trpc.legacyRouterName.procedure "does not exist" on type CreateTRPCNextBase, runs anyway

Have reached the end of a massive trpc 9 -> trpc 10 migration, executed using the official guide with conventions copied from the tRPC Prisma starter. (big thanks to @alex / KATT and @Nick Lucas for your support on here while I frustratingly hacked on our massive codebase) When running legacy procedures such as trpc.tasks.getAllTasks.useQuery(...), .tasks will throw the "does not exist on type CreateTRPCNextBase<Router..." type error, but will run successfully anyway. The only procedures I can see are my v10 router's greeting procedure and router methods such as useContext()....

Not getting legacy router ops in merged tRPC 9 router

Followed the guide to merge my large tRPC 9 router with tRPC 10, but now I can't use useQuery or access my old routers off of trpc.. I can see trpc.greeting, though. Even if I omit the MeasurementRouter.build() TRPC router, or merge a basic router, the client still doesn't recognize my legacy procedures. Not sure what to do here, have been hacking on this upgrade for a while and would greatly appreciate a push in the right direction....

createTRPCNext Type Error + useQuery Not Defined

I'm trying to use the conventions for createTRPCNext from https://github.com/trpc/examples-next-prisma-starter after converting a large legacy router a la the v9 -> v10 migration guide, however I keep getting a large type error on config({ ctx }): is not assignable to type '(info: { ctx?: NextPageContext | undefined; }) => WithTRPCConfig<Router<... Additionally, querying with old query syntax gets me this error message, and my apppages error out with a 404. The useQuery error: Property 'useQuery' does not exist on type 'CreateTRPCNextBase In my pages/_app I am doing export default trpc.withTRPC(MyApp); , where trpc is the type error-throwing export const trpc = createTRPCNext ...

Read response headers on the client

Ive been searching for a while trying to figure out how to access response headers on the client. Found this Github issue, but it has no responses (https://github.com/trpc/trpc/discussions/3866). Anyone got an example of how to read the response headers on the client?
Solution:
This seems to be working. but not sure if I break some magic sauce by doing it..

Is it possible to access context in input?

Hi, I have a validator that requires to get context of prisma in the input, Is it possible to get the context in the input? There are some fields that are required for some users, I would like to handle this in validator level using zod....

TRPCContextState not found in v10

In our v9 app, we used TRPCContextState from internals to type out TRPC utils, importing it like import { TRPCContextState } from '@trpc/react-query/dist/declarations/src/internals/context'; and using it in types like trpcUtils: TRPCContextState<AppRouter, any>; Is there a quick alternative to this? Can't find it in the the latest trpc10 code packages....

RateLimiter for fastify tRPC routes

Hi, I would like to add Ratelimiter to a specific fastify trpc route, are there any solutions available yet? Or do we need to write our own solution for this?