tRPC

T

tRPC

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

Join

standaloneMiddleware: Merge ctx/meta/input types

Using standaloneMiddleware, it would be great to merge the types (ctx, input, meta) with what is already there when passing that middleware. In our case: ```ts experimental_standaloneMiddleware<{ ctx: { user: { id: number } } }>()...

Does `fetchRequestHandler()` automatically opt out of /app Route Handler caching?

I noticed that Next.js always skips cache for my TRPC API Route Handlers even though the request URLs are identical and the cache/revalidate config calls for persistent caching. I feel confident it has nothing to do with the fetch() calls within the Route Handlers as the same fetch() calls are happening separately within SSR via createCaller() and are being cached within Next's Data Cache as expected. However, I just read this from Route Handler docs:
You can opt out of caching by: Using the Request object with the GET method.
And I see that fetchRequestHandler() takes in the Request as a param:...

Cold Boot Optimizations

I have a next.js app that uses trcp for all of the routes. I am noticing cold boots are slow. It is likely I am doing something wrong, or is there an optimization to be made? I also want to understand how next.js creates the underlying lambda functions with trcp. Is each router its lambda or something else? 
This is a mono repo I have a services package containing all of the service functions and unit tests. I then have an api package that wraps functions from the service package inside routers. The service package contains classes, for example, userService, notificationsService, and more. Each of these classes takes in a configuration. Almost everyone takes in a database connection, but some take in secrets to interact with external APIs. I have a factory that instantiates all of the classes, takes in every secret, and returns an instance of the services. Example:...

Cancel useQueries with single function

is there a way to abort useQueries with function call (e.g. cancel, abort)?

There is a logger middleware like morgan for express?

There is a package with a nice logger middleware? Thanks...

Implementing wsLink causes issues on React

I get an error within the console stating ``` Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'onError') at Object.onError (createHooksInternal-f1d4019d.mjs:454:41) at Object.error (index.mjs:80:17)...
Solution:
Found my issue! The solution it to change App.tsx ```tsx import routes from "./pages/_routes"; import { RouterProvider } from "react-router-dom"...

Understanding how too reuse TRPC with React Server Components

Hopefully I am understanding this correctly, but I have created a experimental_createTRPCNextAppDirServer server to reuse my router with Next.js Server Components.
export const api = createTRPCNextAppDirServer<typeof appRouter>({ ... })
export const api = createTRPCNextAppDirServer<typeof appRouter>({ ... })
...

What would be considered best practice for getting data and invalidating queries?

I have a really simple task management app (doing it to learn stuff). Tasks are grouped in projects and have tags. I opted to load all projects, including the tasks and the tags on the tasks with a single query. When I add a new task or a tag, what would be the recommended way to update the data? - Invalidate the query to the big procedure and reload everything? - Separate the loading the data into different queries?...

Calls to specific table not working in production, fine locally

I am having a strange issue since yesterday. I am using nextjs TRPC and Prisma to connect to a planetscale DB. Since yesterday calls to a specific table are not working in production. All other calls are fine. I'm not getting any errors, the call is just never resolving. It doesn't fail or succeed, it never even gets a status code if I check it in the network tab....

anyone else getting a failed to fetch in latest next versions

not sure if this is happening to more people, I tried literally everything, changing to 127.0.01, updating next@canary, not sure if the error is on trpc side, no logs shown, but man I'm completely blocked by this. ``` ✓ Compiled /secrets/page in 483ms (1262 modules) ⨯ Internal error: TypeError: fetch failed at Object.fetch (node:internal/deps/undici/undici:11576:11)...

Missing keys in TRPCError when returning as JSON

Hey all! I am returning a TRPCError from a custom TRPC server but only the code and name keys seems to be serialized and returned to the client. It's quite strange. If I directly return a key such as error.message I get the string no problem, but if I return the entire error object I only recieve error.code and error.name . Any idea why this is? Here's a little code snippet: ```ts catch (error) {...

How to close a Standalone adapter server?

I want to run some integration tests with Vitest and for some reason I don't want to use the createCaller() API. Is there a way to close the Standalone server when tearing down the tests?

tRPC Client within Next.js but with external standalone server?

Hi, I have an old Next.js project that used tRPC and we're currently in the process of separating out the frontend and backend parts of it for various reasons. To reuse code, I was hoping to set up a standalone tRPC Server In that case, what's the recommended method of setting up a tRPC Client on the Next side? using @trpc/next or @trpc/react ? ...

Review of inner and outer context with express

Hello, I didn't find any example that uses inner (for testing) and outer context with express. That's how I implemented it for my express trpc boilerplate, I wanted to know if I did it right, or if there was some error. Thank you so much...

Wrapper Component: Unable to retrieve application context.

Hello tRPC-Community, I have ran into a funny "issue" while gaining my first experiences with tRPC. If I want to use tRPC in a React Component the documentation states that the Component should be wrapped by some Helper-Component from react-query. Now I want to be as flexible as possible and only want to "declare" the Wrapper-Component once:...
No description

handling errors server side

How do you guys handle server side errors 500 request on production

it sound like handle upload/download file need build new http server or endpoint?

I have scan all posts i can about solution for handle upload/download file with trpc.So there is no great solution for this with trpc for now? If no, i can only build new nestjs server to handle files specially but i need implement permission management again and can't reuse middleware that used in trpc. By the way, trpc is a Wonderful project for ts full stack developer!...
Solution:
not sure what you're using for file storage. we use S3 Buckets on our project and we have our tRPC endpoitn generate a pre-signed URL for S3 Uploads that gets sent to the frontend, and the file is uploaded directly from client to S3 downloads work similarly where we can generate presigned url's if the bucket is not public, or just give them the public link if it is...

tRPC queries running on the server

Environment: - bun 1.0.2 - next 13.4.16 - trpc 10.37.1 ...