tRPC

T

tRPC

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

Join

Can I redirect the user from inside my router?

I have a query protectedProcedure, which returns an object from my prisma planetscale db What's the best way to redirect the user to a 404 page if the item doesn't exist on the db? I wanted something like res.redirect("/404") but can't seem to find a way to do it Should I just handle it in the front-end with a useEffect?...

Which http library trpc uses in the frontend?

I was wondering iftrpc uses the Fetch API or uses something like Axios to do API calls from the frontend. I recently added supertokens to an app and I need to add a middleware for session refreshment depending on the tool I'd be using

useQueryClient is not working as expected

So before v10 I was simply using useQueryClient and had my queryClient strongly typed. Now I moved to v10 and for some reason, the documentation says that the queryClient was removed from the context so I should use the useQueryClient hook directly from @tanstack but if I do so then the queryClient returned by that hook is not the queryClient trpc is using, it's just empty. I made it work by using the trpc.useContext hook coming from my client utils but I definitely think that the docs a...

Infer the type of ctx for a specific procedure

Let's say I had a helper function that I wanted to pass the context to, I can't use the default Context type, because this helper is only used for procedures that add things to the context. Is it possible to infer the type of the context after a specific procedure runs?

CORS in standalone server

Hi, I'm trying to get CORS working in standalone server. Attempted this solution but unfortunately it no longer works with v10 https://github.com/trpc/trpc/issues/623...

Test example for react-testing-library

Does trpc has any example of doing tests with react-testing-library? We need to wrap the app using trpc.withTRPC. The docs doesn't have a section refering to test, just an example of using context inner, but that also doesn't work in case we actually need to have the req or the res in the context (in NextJS context), for example, to set cookies, etc. Would be welcome to add a section about testing and how to wrap components with react testing library and actually run tests where we actually need the next req, res in the context? (It might not be necessary to have the entire req,res in the context but utility to set cookies in the response to handle auth, for example, etc)...

Queries break when in production on Vercel; work on localhost

The query is called like this: ```javascript const { data } = api.useQuery(["user.!getCount"], { refetchInterval: interval * 1000, onSuccess: () => ......

Can't get client to work

Hi, I can't get my client to work I'm using Next.js but I have also tried the React method from the docs. mutations and query property is missing....

Request context inside middleware?

Hi, Is it possible to get the request context inside a middleware somehow? I'm trying to migrate a Express Based API ...

data becomes never[] when destructuring with a fallback value

Currently it doesn't seem possible to set a fallback value on a destructured data property, for example: ```ts const { data = [] } = trpc.useQuery(['company.listIds']); // expecting data to be the inferred type { id: string }[] but instead it's never[] ...

SyntaxError Unexpected token u in JSON at position 0 with mutations

I'm trying to use trpc client to await a mutation and just keep getting this error. everything works if i change the mutations into queries

Losing the type between the client and server

Hello everyone, I am new to tRPC and the magic of types in typescript so I am looking for ideas as to what is happening, the client is receiving any type instead of a string

Mobile app with tRPC

What's the suggested way of working with tRPC when it comes to mobile apps? How do you ensure that your CI doesn't let you push a new backend to production if it breaks the mobile app in production?

How to use trpc react hooks from an external data source

Hi, I have a monorepo, nextjs and keystone cms. The cms has trpc running, and I managed to get it connected to my nextjs. Is it possible for example to use the useQuery hook with that connection? Atm I use
createTRPCProxyClient
createTRPCProxyClient
from "@trpc/react", but it seems to be the same as I would import it from "@trpc/client". See screenshot Thanks for any help! 🙂...

V10. How to infer types on V10?

https://trpc.io/docs/v9/infer-types I am trying to infer types to use the inputs on my yup forms in the front end but can't get this working and did not find an example docs for that. The current example available at https://trpc.io/docs/v9/infer-types is depreciated on v10. ...

NextJS & Keystone CMS, issues when connecting both in a monorepo

Hello everyone, so I have a monorepo with NextJS and keystone cms, both are running trpc v10beta.15. Screenshot 1: I receive a type error when trying to use the CmsAppRouter type in my NextJS when calling createTRPCProxyClient....

Best practices for implementing an offline application

Hey there! I'm building a full stack react-native app with Expo and a tRPC backend. I'd like for this app to be functional offline. Currently I'm accomplishing this via a simple optimistic update like: ``` const createUser = trpc.userCreate.useMutation({ onMutate: async () => {...

somehow when move typed function out of the router files, frontend infer type to be any ?

this is inferred corrected since they are in the same file. ``` getX: t.procedure.query(() => { return getX() }) ...

Big companies that use tRPC?

Some of my fellow colleagues were wondering if there are any big companies that use tRPC and how mature you would say it is for production in "real" projects?

SSG on nextJS when appRouter is made with fastify adapter?

```js export const getStaticProps: GetStaticProps = async () => { const ssg = await createSSGHelpers({ router: appRouter //This app router is in fastify ctx: await createContext(),...