tRPC

T

tRPC

Join the community to ask questions about tRPC and get answers from other members.

Join

is it possible to use trpc without the app router?

is there a pattern to define mutations/queries as individual routers and then import an individual router for that procedure into my frontend? the AppRouter type is blowing up the compiler

Why not create queryClient and trpcClient outside of React?

From the docs: https://trpc.io/docs/client/react/setup#4-add-trpc-providers Relevant excerpt:```jsx export function App() { const [queryClient] = useState(() => new QueryClient())...
Solution:
I'm so goddamn stupid, i literally asked the same question this June already: <#1253685017931022347> And also they even explain this in the docs below the code snippet... I AM INCAPABLE OF READING ๐Ÿคฌ...

Invalid hook call using useQuery

Hello, I am trying to implement a common component that accepts a function props that will fetch data from the server. For example, see the code below: ``` export const UsersTable = () => { return (...

Is it possible to change the base path?

I have my trpc server on an endpoint: api.examples.com/trpc - this should be the root, and trpc handles anything subsequent. But querying this with a client, I get the error: ``` TRPCError: No procedure found on path "trpc/me.details"...

when using utils.x.y.getData, is there a way to get when the query was fetch / last updated ?

when using utils.x.y.getData, is there a way to get when the query was fetch / last updated ?

"Failed to load response data: No data found for resource with given identifier" in the network tab

I started a new project, but I can't read the results from my queries in the network tab on my browser. This makes the developer experience (DX) poor since I can't see my query calls. Sometimes (around 20% of the time) it works on Safari, but the JSON formatting looks off (see screenshot). It never works on Chrome. What's strange is that the queries are fetched properly and when I log the query results in my console in my Next.js app, I can clearly see them....
No description

throw custom error

I use @trpc/client as the backbone of a backend. This backend throws custom exceptions based on httpexception. How can I customize exceptions throw in the client? ``` const client = createTRPCClient<RegistrationAppRouter>({ links: [...

Automatically decode custom errors on client

Hi! We're using tRPC v10.45.2 with React Query in a Next.js app. I'm looking for a nice way to pass custom error payloads to the browser. What I've done so far is have something like this: ``` export type MyAppErrorDetails = { $type: 'ILL_FORMED_BANANA'; shape: BananaShape; } | { $type: 'NOT_HUNGRY' }; export class MyAppError extends TRPCError {...

Infer query type of `data`

Using trpc version 11, how can I infer data? ``` const { isLoading, isError, error, data } = trpc.patient.list.useQuery();...

Streaming is not working

Hi, I've set up unstable_httpBatchStreamLink in my app but the streaming is not working. The batching occurs, but nothing is streamed back from the server. It looks like the request still resolves after the slowest request has been sent. Can anyone help me troubleshoot this? I'm using a Fastify server.

How to opt out of caching an API in trpc NEXT/SSR?

I faced an issue where all the data's being fetched from my server component are not the latest, they seem to be the latest on dev, but not on production. I have tried to set a header in the responsemeta and also tried to add a stale time of 0 , below are the screenshots for the server...
No description

How to get pageParam from useInfiniteQuery()?

How would I write a tRPC call equivalent to this traditional useInfiniteQuery? My primary concern here is that I need to pass in a cursor to my procedure, and upon each successive query I need to update this cursor for the next call. ```TypeScript const { data: posts,...

NextJS App Routers with tRPC: can't call query on server component

Hi all, I'm folloing this guidline to setup nextjs with tRPC but it didn't work when I call the query on server componet: https://trpc.io/docs/client/react/server-components#getting-data-in-a-server-component ...

Using duplex stream as transport?

I'm using a framework that gives me a node duplex stream for communication between front and back end. Can I somehow wrap that stream with tRPC?

How to get line number in errors?

Hi, we are currently doing this: ```ts onError: (info) => { if (isEnv("local")) { console.error(...

Auth in context is initially null leading to TRPCClientError: UNAUTHORIZED

im trying to get some images in my server component using a protected procedure ``` import { api } from '@/app/_trpc/server'; import Images from '@/components/images'; ...

Background tasks

Hi, how to return response and do some background tasks. Like this ```js app.get('/', (req, res) => { res.on('finish', () => {...

edge runtime config router specific

does the edge config have to be in app/api/trpc/[trpc]/route.ts? is it possible to have it only for a specific route?...

[V11] BFF Monorepo setup

Hello! I have a monorepo with several apps, every app has its tRPC endpoint setup like this. ```typescript // app/api/trpc/[trpc].ts...

Is there any way to know which objects in a list got updated from a useQuery refetch ๐Ÿค”

Or through another API type Have some larger calculations that happen after the list is set that I donโ€™t want to recalculate...