tRPC

T

tRPC

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

Join

Trouble inferring the type of a very simple structure of nested routers

A very simple router results in an inference error, causing the client to not be able to infer the router type. I am using the proxy-beta.24 version along with typescript 4.9.1 `export const app_router = t.router({...

calling trpc endpoints from vanilla nextJs api routes

I'm struggling to find what's the best way to call a trpc endpoint directly from the server. Basically, I have a nextjs api endpoint where I want to call another endpoin that lives in trpc. would I need to create a trpcProxyClient? If so, would it have access to the context?...

Multiple React providers

Good morning! Is there any workaround, how to use multiple trpc-client instances with react-query? I wanted to share react-client between multiple instances, and I ended up with trpc calls to last-provided trpc address....

Mutation type issue

I'm trying to mutate something like this with tRPC and Prisma
const updateColumn = trpc.project.update.useMutation();
updateColumn.mutate({ colId: list.id, cards: list.cards })
const updateColumn = trpc.project.update.useMutation();
updateColumn.mutate({ colId: list.id, cards: list.cards })
...

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....