tRPC

T

tRPC

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

Join

Using generics duplicates the types instead of referring to the existing types

Hi! I'm creating a backend API using TRPC, where I'm encountering a slight problem. TL;DR; when defining procedures with a generic type, instead of referring to the existing type, it copies the definition of the existing type when building the types. -...

Set custom header for fetchRequestHandler

Is this possible? currently getting cors issue. Trying to use nextjs's edge function with trpc.. ```ts import { type NextRequest } from "next/server"; import { appRouter, createContext } from "api";...

How to enforce usequery as NonNullable

I have a custom hook with infinite query. I check for undefined at the app first render and then it is reused so I know by then, the type should not be undefined. I would like to be able to infer its type without undefined conditionally. Can I do that? How to if so?? ``` export const useAppContext = (enabled = true) => api.appContext.getAppContext.useQuery(undefined, {...

How to call useQuery with params inside JSX

How can i achieve this? Thanks ``` export function MemberQueryList({ list }: Props) { ...

Sharing Enum

On the backend: I have colocated files with types and procedures (index.ts - procedures, schemas.ts - zod/ts types). If I define an Enum on the backend in the schemas.ts and would like to use it on the client(frontend) does it meat that importing that enum would boundle this file in my client? With type I can just do import type { SomeType } from '../backend/schemas' and that would be stripped If I understand correctly. But what about enum?...

Meta - unable to create default meta

Trying to follow https://trpc.io/docs/server/metadata#default-meta-chaining-and-shallow-merging I set the type of the meta add it to the builder and want to set default but seems there is no typing for the meta in the create to set the default. Am I missing something ? ``` "@trpc/client": "10.16.0", "@trpc/react-query": "10.16.0",...

trpc/react-query batching

Hi. How do you deal with batching? If I don't put any maxURLLength then I get an error 404 since it cuts of some of the requests urls... If I put url length then some requests just does not get executed since url is getting too long. I was thinking about max batching size however react-query does not have that... Any ideas on how to best deal with this?

middleware error with minimal-react example

hello! I tried to use the minimal-react version, but I get an error - it says that 'middleware' does not exist on CreateHTTPHandlerOptions<...>. Am I doing something wrong or is it broken?

how to use the same Zod validation both client and server's procedure input

When submitting forms, I need the same validation. How to reduce the repeated code?

pipe/unstable_pipe

I cant seem to find it? according to the docs I can chain middlewares using pipe in v10 but the feature isn't there this is a simple example from the docs `const t = initTRPC.context<Context>().create(); ...

Implementation of bi-directional cursor-based pagination

I'm looking at the example for useInfiniteQuery and I'm trying to make it bi-directional. I know I need to pass getPreviousPageParam that returns the second cursor, but I don't see any obvious way to pass the direction information to the procedure. What would be the recommended way to do it?

How to ignore `input` validation and just pass in an object with interfaces?

For my input I just want to pass in an interface rather than using a Zod schema. Either that or if somebody can let me know how to pass in an external interface as a z.object() param

Where can I add a query key?

I tried to follow as in useQuery from Tanstack, but Typescript started complaining ```js api.prompts.tags.useQuery(undefined, { cacheTime: 60 * 60 * 40, });...

async inside link next handler possible ?

Hey everyone, Today I had to do a bit of refactor, and I'm wondering something. I had to turn a synchronous function into an asynchronous one, and ended up needing async into the trpc "link" like so: ```ts...

tRPC doesn't support redirect

I use tRPC & @trpc/server/adapters/express. procdure.query({ctx: { res }} => { res.redirect('xxx') })...

How to get external key other than INPUT from RESTFUL request?

SSO callback my api like api/trpc/user.login?token=abc...

application/octet-stream response

Im refactoring my old backend to trpc so far it was a pleasure and fairly straight forward process ❤️ Im amazed. Now I faced the issue with the files. I have one endpoint from external API that returns the data as application/octet-stream. (csv/xlsx) Can I handle this with trpc?? Probably I can't pass directly the response from the API throught trpc procedure and read it on client. I was thinking if I could parse response on backend (read it as text) and send text to client and download it? Would that work? Is it some kind of security? One problem could occur if the file would be big I guess??...

Discriminated union handle

How Do I handle Input type if its discriminated union?? ``` export const batchTasksRouter = createTRPCRouter({ requestExport: procedure...

Hit external APIs ...

I'm new to tRPC, I need to hit an external API (OpenAI) directly from the client-side. Can I still use tRPC for that? If not do I have to wrap my app in Nextjs with React-Query wrapper?...