tRPC

T

tRPC

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

Join

calling api endpoints from within a trpc api endpoint?

Hey all. I have a series of api endpoints which may have to be reused across other api endpoints. I was wondering if this is possible? ```ts...

TRPC waiting until the query has completed

Hey. I've just found out about TRPC and I love it. However, I was wondering if there is a way to make it so the code below my query doesn't run until the query has completed, without having to make an external function or make use of a useeffect hook in order to use await? Is there a property of some sort which I can use to stop the page from rendering? The code below causes an infinite signIn loop due to the data not being there on the initial page render. But, I can't check if !guilds.data, because sometimes it wont return anything, due to an invalid token. Which means there is no good way to identify when to force a signIn for the user....

JSON Parse error Unexpected token R on react native

I keep getting this error on react native expo

trpc with headless cms

Hello, Is there any example with trpc and headless CMS or is there anypoint to use trpc for project that gets data from external source? For example existing api / headless CMS. And what would be the advantage over using for example react query and creating and getting data from api endpoint instead...

Is it possible to call a query from another query defined in the same router?

Say I have some code like the following: ``` t.router({ compute_all: t.procedure .query(async ({ctx, input})=>{...

Testing with React Testing Library

Hi! I am trying to test my
DestinationForm
DestinationForm
component using react testing library. My test is simply rendering the component: ```ts test('contains 2 input fields and a submit button', () => { const view = render(<DestinationForm />)...

Can I cache a response server-side?

For my project one of the trpc requests in my app works as an API Gateway to another API. I make a request to TRPC server, that makes a request with a secret API key to a 3rd party API, and returns the response to my user. In my case this 3rd party API has a rate limit that I'm going to be hitting soon....

Proxy TRPC server to another client

I've two TRPC servers, one essentially acts like a proxy, it validates auth and based on a specific property it forwards you to the destined server (with that one property removed). Now I have to write all those queries and mutation twice, is there a simpeler way to do this? Is there any way to bind a specific TRPC client to a server?...

Unexpected token

hi, kindly help me on this one

Throw custom TRPCError with specific cause

Hello everyone ! I'm trying to throw a custom TRPCError with a specific cause that i can differentiate from other trpc errors. My use case is to be able to catch error on client and display an error message if the error code is 'BAD_REQUEST' and a specific cause. After investigating i find that something like this should work in my mutation procedure: ``` throw new TRPCError({ message: 'Password changed too recently', code: 'BAD_REQUEST',...

Delay IsLoading....

i'm trying to delay a loading spinner from appearing if the api takes less than 200ms to get the data. I've tried a number of implementations and failed, can anyone help? ```js const { isLoading, isError, data } = trpc.ticketDomain.getByTicketId.useQuery(...

Clearing Cache

How do I clear the queryCache for a particular query using the trpc context? If that's not possible, how can I do that using queryClient?
queryClient.getQueryCache().clear()
queryClient.getQueryCache().clear()
I've tried the above but it clears the entire cache. I just want to clear the cache of particular key....

context at times empty

am new to trpc. i am usin iron-session with nextjs and its awesome. am forwarding the context. but sometimes session is empty. then it reload and session is not empty. tried it with static data. this doesnt happen with static data. any ideas? i have followed the trpc docs for adding trpc to an existing nextjs application.

query and mutate promise on next

I've followed the guide "Usage with Next.js" and now I only have the useQuery and use useMutation hooks exposed when I want to call a route. How do I also expose the regular query and mutate promises on these routes? Edit: Solution: ```...

testing a trpc hook

i'm brand new to testing and need some help with writing a test for a hook that is returning an object. im stuck with the error messages. i'm using trpc and react query ```js export function useGetTenantTickets() { const setTickets = useTenantStore((state) => state.setTickets); const { isLoading, isError } = trpc.ticketDomain.getByTenantId.useQuery(...

CAS Authentication

So long story short. My University is using CAS as authentication provider. I was thinking that I could use NextAuth with it to authenticate my users but I have no clue how am I supposed to do that. They don't support OAuth2 because they have old version of CAS. I asked on GH discussion in NextAuth for help but didn't get any. I also tried seeking help on Theo's discord twice this month but no luck. I don't know what to do and I feel like people working there have no clue what to do. I really want to be using TRPC with NextJS as I love this combo but how on earth can I authenticate my users using something like this? I was told I could use this lib https://www.npmjs.com/package/node-cas-client...

save return type to type var

Hello, I want to save the type that return from useQuery to type variable. For example, I have this complex return type from the query and would like to do something like type userInfoType = object. Please point me to some direction. Thank youuuuu ❤️...

Difference in type inference for vanilla client?

Hello, querying an endpoint with the vanilla tRPC client but at runtime the actual result isn't the inferenced type but {json: ..., meta: ...}, am I doing something wrong?

Zod Error Middleware

Hey lovely people. At Cal.com we make heavy use of zod for data validation. I was wondering if there's a way to create some kind of "error middleware" that can catch all Zod specific errors and serve the proper TRPC error back to the client. This would allow us to just use schema.parse instead of having to manually check schema.safeParse or having to use try/catch everywhere. Thanks for any input! 🙏...