tRPC

T

tRPC

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

Join

Accepting a DecoratedProcedure with inputs and outputs that extend some given types

Is there any way to accept a DecoratedProcedure that extends { mutate: Resolver<TProcedure> } where TProcedure is guaranteed to have its inputs be something that extend the object { nextFollowerId: string }, and the outputs are a string?

useEffect and useMutation error about conditional rendering of hooks

I am using t3 stack with tRPC, and I am trying to mark all emails as seen when the page loads by using useEffect, but this seems to give me an error about conditional rendering of hooks. Are there any other ways I can accomplish this? ```...

Guide to create an adapter

Is there a guide on the docs that explains the basics to create an adapter?

Does tRPC websocket client supports wss protocol?

After changing the websocket client url from ws to wss, it fails to connect. Tested out the connection on postman works fine

Get the type of context after middleware

How can I get the type of the context of adminProcedure from export const adminProcedure = publicProcedure.use(isAdmin)? https://trpc.io/docs/server/middlewares...

[How To] Properly use trpc UseQuery based on currently selected item

I have a component with a video element and a flatlist. I want to utilize a trpc query to get the videoUri based on the currently selected item. Here is my working component: ```...
Solution:
const query = trpc.lesson.videoUri.useQuery(currentItem?.id as string, {
enabled: !!currentItem?.id,
});
const query = trpc.lesson.videoUri.useQuery(currentItem?.id as string, {
enabled: !!currentItem?.id,
});
...

Data from useQuery is inferred as data: {} | undefined

My server query returns data from database via ElectroDB. TypeScript can statically infer all properties. However, on the client, the returned data is always inferred as data: {} | undefined.

Cannot access 't' before initialization

Hi, I'm migrating my app to a mono repo but I just can't get past this error for some reason Cannot access 't' before initialization when using the tRPC instance anywhere be it a middleware or router The server is a standalone node server useAuthenticaton.ts...

tRPC Middleware consuming memory limit on Vercel

Hi all, I'm running into a weird error where my tRPC middleware to enforce that a user is authed, is reaching the memory limit on the request. I've used tRPC with the exact same middleware before and never ran into any of these issues, here's what the middleware looks like: ```typescript /** Reusable middleware that enforces users are logged in before running the procedure. */ const enforceUserIsAuthed = t.middleware(({ ctx, next }) => {...

Using react-query parameters in tRPC for useQuery

Hello, the useQuery from react-query can take parameters such cacheTime, staleTime, refetchOnWindowFocus etc. , but as far as I can see we cannot give these parameters to the useQuery provided by tRPC. In this case, how can we set these values, and what are the defaults for such values? Thank you....

tRPC type error on turborepo

Types of property 'query' are incompatible.
Type 'inferHandlerFn<{}>' is not assignable to type 'inferHandlerFn<any>'.
Types of parameters 'path' and 'path' are incompatible.
Type 'TPath' is not assignable to type 'never'.
Type 'string' is not assignable to type 'never'.
Types of property 'query' are incompatible.
Type 'inferHandlerFn<{}>' is not assignable to type 'inferHandlerFn<any>'.
Types of parameters 'path' and 'path' are incompatible.
Type 'TPath' is not assignable to type 'never'.
Type 'string' is not assignable to type 'never'.
...

Stack for expo?

Can someone recommend a stack for an expo project? I'm considering trpc + fastify + fly.io, but have zero experience with any of those technologies. I'm set on using trpc, though. I'll need websockets....

Implementing a "Prisma model converter middleware"

Bit of a fancy name, but if you've ever worked with Symfonys param converters (especially the DoctrineParamConverter) you get the idea. It's basically just automatically converting input to models. Currently trying to implement this, but can't find a way for proper types. Implementation so far: ```...

Senior Full Stack Developer is Ready.

✍️ Skill Set HTML/CSS/JS, TS React/Next.js, Angular/RxJs, Tailwind CSS WordPress/Laravel/CI Blockchain/Smart Contract/Solidity ...

Suggested way to invalidate queries on a component that is used on multiple pages.

Please suggest me a way I can handle the following situation in the best possinle manner. Coinsider a Component - used in multiple pages - has mutations, which requires query invalidation on other components of the page. ...

Setting up trpc behind AWS API gateway and authorizing using a lambda

Current setup: - trpc api, containing both public an private procedures. Let's call them posts.list (public) posts.create (private) - API gateway routes GET /trpc/{proxy+} and POST /trpc/{proxy+} that invoke a lambda handler for trpc (let's call it trpc.handler) ...

setMutationDefaults for optimistic updates

I have a preferences router, with a get query and a set mutation. I had optimistic updates set up in the onSuccess of the useMutation hook, wherever I used it, like this: ```ts const preferences = api.preferences.get.useQuery(); const savePreferences = api.preferences.set.useMutation({...

Using tRPC in React SPA with Django backend

is that possible? Do I need to create an AppRouter and put that inside my django backend files? How can I use procedures already defined in Django?

Typing a shared TRPC provider for testing

Context: - We have a monorepo with several micro-frontends which use Next. - We're moving to using tRPC to communicate between the front end and Next backend - We test our components with React Testing Library - We have a shared package for our testing utils, including a render method that renders a component for testing with all required providers (Theme, i18n, etc etc)...

Response promise resolves before endpoint finished processing

I want to interact with OpenAI's API in my Next.js + tRPC app. It seems that the my frontend is not waiting for the backend to finish the API call before using the response, leading to an error because the response is still undefined. This is my endpoint: ```typescript export const llmRouter = createTRPCRouter({...