tRPC

T

tRPC

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

Join

empty `input` object when using mutation

When using useQuery I have no issues even with input but when using useMutation. The backend is receiving an empty input. What could be the reason? stack is nodejs + express + reactjs + yarn Frontend code...

Returning html with TRPC

Is it possible to return content-types other than JSON, so HTML for example? I have a requirement that needs it.

Specify invalid queries from the server?

I have a TRPC app that I am writing and there are times I would like to invalidate queries on the client from a mutation on the server. I am not talking web sockets or anything like that, but just a standard way to invalidate multiple queries from the server just as part of the return from a mutation ...

Automatically notify about excess queried fields.

Hello! Imagine very common situation: We picking "user" with 10 fields, but using only 3 of them in component. Is there a way to automatically identify unused fields to be able to remove them? Is tRPC Drift about it?...

The inferred type of 'trpc' cannot be named without a reference ...

Hey everyone, I just changed around the structure of my monorepo where I now have my nextjs application inside of apps/nextjs and my trpc server code in packages/api. Doing this however gives me this error which definitely seems related to types not being shared properly between the two packages. I am using yarn (1.22.19) workspaces....
No description

trpc mutations for searching data

Recently was told that using mutations to fetch list data is bad. I can agree with this on a high level from the naming convention, but I'm curious what the deeper reasons are. Are there specific "internal" or architecture related reasons why mutations shouldnt be used to search data at all?

The inferred type of 'trpc' cannot be named without a reference. A type annotation is necessary.

Hello everybody... I have a nodejs + reactjs + yarn monorepo using turbo. I am getting this error when declaring trpc on client side. Please help. I have setup my code following the example here at https://github.com/kuubson/react-cra-trpc/ ...
No description

Is `inferSubscriptionOutput` missing in 10.x?

I'm working on a vue 3 app with reactive state and need to infer the output of a subscription. It looks like 9.x had inferSubscriptionOutput but that appears to be deprecated / not applicable in 10.x and I am not sure what the best alternative is. There is a inferObservableValue but I am not sure how that works / if it is what I am looking for....

is there a way to do client-side "middleware"?

My app uses Firebase Auth for authentication. While the user is logged in, they get an ID token which is valid for 1 hour (non-configurable). The front-end is supposed to call a function await user.getIdToken() to refresh this token. Is there a way that I can have the frontend try a request, examine the response, potentially call this function if the server tells me the token is expired, and then retry? I want this to happen without triggering the onError() callback for all of my queries / mutations if possible....

How to refetch a call made on the server

const section = await api.course.getCourseSection.query({
sectionId: parseInt(params.lesson),
});
const section = await api.course.getCourseSection.query({
sectionId: parseInt(params.lesson),
});
...

How to set cookies in trpc response?

I have an app dir project that was created using this t3-app PR. On the client I have a form and I am using the trpc react client: ```ts import { api } from "~/trpc/react";...

Check if Role is ADMIN

Hey guys I have a private procedure in T3 Stack. I need to check if the user thats doing the action is indeed admin. How can i implement that in this privateProcedure? ```ts...

Can middleware be used on a router?

Given a router where all procedures need to use the same middleware, can the middleware be somehow attached to the router instead of manually to routes? For example, given an "admin" router, it would be quite catastrophic if one of the endpoints was accidentally set up with a publicProcedure instead of adminProcedure = publicProcedure.use(isAdmin)....
Solution:
no, it’s not possible

How can I use `onSettled` in the `experimental_createTRPCNextAppDirClient`?

Context I want to migrate the following trpc/client hook to the experimental version ```ts const searchMandate = api.mandate.search.useMutation({...
No description

Stop initial refetch when prefetched with SSG helpers

Anyone else struggling with this, I want to maintain refetching when the tab is refocused but don't want to "double" fetch on the initial page render. const helpers = createProxySSGHelpers({ router: appRouter, });...

Accessing QueryFunctionContext within server queries

Hello, I know that the field 'direction' is a new addition within react query v5 as part of the QueryFunctionContext object https://tanstack.com/query/v5/docs/react/guides/query-functions#queryfunctioncontext and that work on compatibility with this version is happening in the 'next' release of TRPC. However, this is a more general question about accessing data within the QueryFunctionContext when utilising TRPC, despite my examples including the new field. If I were not to be using TRPC I would have access to that object as an argument in my query function and I would construct my URL with that data included. Obviously the benefits of TRPC include the automatic generation of my query function to a corresponding server procedure, however this process does not provide me access to the fields of the context on the server. Is there a good way to pass this field to my server procedures so that I could determine how to adapt my database queries for cursor based pagination?...

HTTP 431: Input too long

Hi, we're using a complex query (multiple filters etc) with tRPC and react query integration. It happens, that the query is to big and the server returns a 431, due to http uri restrictions. There are some open PRs about this topic, but is there any workaround?...

Function to release context post-batching?

In our application every customer has their own schema, therefore we need a db client per request which I was hoping to leverage with TRPC context. Ideally, we'd be able to: - Connect to the database in context ✅ - Set the search_path to match the client's JWT in context ✅ ...

forwarding headers in solidjs

I have a setup with solidstart, and im trying to forward the client headeres to ttrpc. Here's my setup: ```javascript // This is not forwarding the client headers. export const trpc = createTRPCProxyClient<IAppRouter>({...

Support @tanstack/react-query 5.4.3

will it support 5.4.3 @tanstack/react-query when i install above version with my next.js it unable to start, have to fall back to 4.36.1...
Solution:
sorry just found the post mentioning it https://github.com/trpc/trpc/issues/4218