tRPC

T

tRPC

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

Join

UseQuery iterator not working for me

I am on tRPC v11. Using the example provided in the documentation under "streaming responses using async generators" (re: https://trpc.io/docs/client/react/useQuery) I get the following error in the client:
Cannot use stream-like response in non-streaming request - use httpBatchStreamLink
Cannot use stream-like response in non-streaming request - use httpBatchStreamLink
...

Endpoints lose Input and Output Types on tRPC Client

Environment: Node with Bun package manager What's wrong: The problem I am facing is that on the trpc client I am able to type safely access the routes, however the type annotation of the output and input gets lost. What I have: https://github.com/trpc/trpc/discussions/5881 left here all the relevant information on my pov...

Where put transformer on custom link? (upgrading to V11 with T3-Setup)

In the Screenshot are the changes I made to the TRPC-Server client. Question: Where do i put the transformer on a custom link? Question2: The callTRPCProcedure-function now gives a type error: Unsafe return of an any typed value....
No description

client server counication with webSockets

Hi, I would like to be able to send data via ws api from my frontend. Still, I don't seem to be able to send any data from the frontend to the trpc backend, I tried to do it in a way that I make mutation and I open ws connection in this procedure. Still, it reconnects me on every request and I need this connection to stay open and just send the data, is there a way to send data from trpc client - frontend to the subscription precedure? On the client, apart from onData there are only onComplete, onError, onSarted, and onStopped. ws API offers ws.send() and it seems that I can only receive data from the server, is trpc client lacking this functionality or am i missing something? Many Thanks...

How do you call a router procedure from another router procedure?

.query(async ({ ctx, input }) => {
const wikiQuery = await routerFromAnotherFile.queryWikiTable(input);
.query(async ({ ctx, input }) => {
const wikiQuery = await routerFromAnotherFile.queryWikiTable(input);
...

Cannot figure out the correct type

I am trying to use tRPC outside of React. I use it in React, but I need a separate way to use it. I found out about trpc.useUtils().client, which is perfect. But I want to make it a global object for CSR components. I cannot figure out the right type to include in to the declaration. Thank you...
Solution:
export const api = createTRPCClient<AppRouter>({ ... })

Trying to get the return type of a procedure.

Using TRPC v11. I am failing to return the type. I get the error Type alias 'ProtectedProcedureType' circularly references itself. Any ideas?...

Having great difficulty using Streaming

I wanted to use the stream api with tRPC to handle a response with alot of return values and I looked at the docs for this https://trpc.io/docs/client/react/useQuery#streaming, and when trying to use the example TypeScript gives me the error: Property 'map' does not exist on type 'AsyncGenerator<number, void, unknown>'. and my JavaScript console gives me this error as well, TypeError: _myQuery_data.map is not a function. I am using the T3 Stack with tRPC running Bun 1.1.3 with Next.js v14.2.4...
Solution:
Uhh, I think bun update did the trick, since I didn't change anything and everything worked. When people say if it ain't broke, don't fix it, this is what they mean.

Unable to abort Suspense queries

I am using trpc@11 with react-query@5. I was under the impression that as long as abortOnUnmount is true, all queries that haven't completed yet will be cancelled. Is there anything I am missing? Provider ```tsx export const TrpcReactProvider = ({ children }: { children: React.ReactNode }) => {...

Authorization and Authentication while using unstable_httpSubscriptionLink

I'm wondering what best practices are for specifying headers like bearer tokens when using httpSubscriptionLink. Currently, it looks like the API doesn't support this....

Custom data transformer and input/output schema

Hello 👋 I would like to code a data transformer, but I would this data transformer to be aware of the input and output Schema of the procedure. why:...

Property 'error' does not exist on type 'MiddlewareOKResult<any>'.

Hello, I am building an trpc adapter for nestjs, and I am trying to extend some of trpc's functionality, specifically the procedure middleware by creating a procedure class. ```typescript import {...

I'm unable to make a GET request in postman. But able to make post requests

I get: expected object received undefined what could i be doing wrong? these are my routes, the problem is with testRoute: ```typescript...
No description

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

I have a monorepo setup like this: root -tsconfig.json -frontend...

Update a query with setData avoid calling invalidateQueries ?

I have this code, which is cancelling all the queries for an specific router, then it's updating the cache, then it's doing a mutation. I have this global overrides, but when i have this setData logic, it's not fetching again the data, when i comment that part, it's refetching. Is this the normal behavior?
No description

sending messages via WebSockets

Hi, do I have the possibility to send messages via wsLink? I want to connect to Binance and be able to place orders via WebSockets, so far I've only been receiving market data like so: ``` useEffect(() => { const socket = client.binance.marketDataStream.subscribe( { symbol },...

My TRPC hooks are getting typed as `any`

I'm using a Typescript + Express backend (Node.js, version 18), and a React Native (Typescript) frontend. For some reason by TRPC tanstack-query hooks don't seem to be typing things correctly. I am trying to understand why. I have a monorepo setup with a file structure like this: root...

Subscription error: TRPCClientError: Subscriptions should use wsLink

this is my trpc client: ```js export const trpc = createTRPCNext<AppRouter>({ /** * @link https://trpc.io/docs/v11/ssr...

tRPC typings not working - Cannot import @trpc/server on client

hi guys, my structure is the following: - Turborepo TS compiling to cjs - A common packcage which defines the tRPC router - A server service which imports it & runs on expressjs...