tRPC

T

tRPC

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

Join

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

Cannot get subscription event to fire

Ripping my hair out here trying to get Websockets working with tRPC and Next. Everything seems to be working and the frontend client is connecting to my websocket server, however triggering the addFact mutation does not not successfully emit the new catFact despite there not being any errors. I've looked at various repos that achieve similar functionality and haven't been able to spot the problem, does anyone have any guidance? ```ts export const catFactsRouter = createTRPCRouter({ fact: publicProcedure.query(({ ctx }) => {...

How to organise reusable functions

How do you guys organize functions that all need the same context (usually from tRPC)? For example let's say that you have 10 functions you use multiple times across multiple routers and they all share the same context. Do you use a class?...

How to get response type depending on the input params?

Simple example of a normal JS function with generics: ``` const example = <T extends unknown>(params: T): T => { return params }...

how to build tRPC and Prisma with express?

I am using TSC as the official docs example does. But when I use paths in tsconfig.json, It does not work because of not transforming paths . Should I add webpack like nestjs doing?...

How to infer types from input?

When I call my procedure from the client I send an array of strings as an input. How can I infer the strings so they are returned in the response (see client code comment) On server: ``` example: publicProcedure...

How to infer types of a query

Coinsider the example const hello = trpc.hello.useQuery(); I would like to export the type we get on hover(on hello). ...

Data Visualisation/Charts

is anyone using tRPC on data visualisation (say bar chart/line chart) in a scenario close to a banking app or Yahoo finance? would love to see some examples

trpc + AWS Lambda (through cdk)

Hi all, has anyone successfully integrated tRPC with AWS Lambda? My current stack is API Gateway + Lambda, all created through cdk. I am trying to figure out how to hook up the tRPC router and client to the lambda code. This is my first time using tRPC 😅

Is it possible to narrow an output schema if the query optionally doesn't return all fields?

I have a router procedure that has an input schema that has an optional filter that changes the shape of the data to only include those fields (like sql select), but those records will fail the output schema which contains all of the fields as required. is there a way to construct a .output() specification that narrows the type, possibly using z.partial() so that these partial "rows" will pass output validation?

Fetching different server url than defined in config

Is it possible to access the reactQuery instance and fetch different server url? I would like to use reactQuery to get data from my server which is at say /address-middleware instead of hitting /trpc/.... Can I do that? I dont want to setup separate reactquery provider or something just to call one separate endpoint