tRPC

T

tRPC

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

Join

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

Error types in catch block

Hey! I have a mutation that I want to catch if the procedure throws an error, I'd like to get the code of the error ("UNAUTHORIZED", "FORBIDDEN" etc.) but TRCPClientError doesn't have full types (basically I can't access the code property). I saw a generic that you can pass to the error but I don't know what to pass as the generic to get the types. ```ts...

input using z.or not working properly

i have an input like this let input = z.object({ name: z.string().optional() }).or(z.object({ id: z.number().optional()...

How can I disable batching with fastify adapter?

I cant seem to find a way to disable batching for my server, and this link doesnt help me much https://trpc.io/docs/v9/links#disabling-request-batching what am I missing? I fell like I miss a sentence or 2 from the docs.......

Issue with monorepo architecture ant tRPC

Hi, we had an issue with batched requests that if we batch some requests they produce a TRPCClientError which says Cannot read properties of undefined (reading 'messsage') so I have read that at least error problem was fixed in newer versions, so we tried to update version, but then the builds started to fail. We get this error (photos in the thread) and more information

Using tRPC in CRON jobs

Hey everyone, this might be a very stupid question, but is it possible to use tRPC inside a CRON job? I saw that Vercel now supports them, and since I use tRPC inside a NextJS project, I thought that it could be used. Unfortunately, I wasn't able to find anything online.

async createContext for Express Adapter

Been debugging an odd behavior for the past hour, it seems like that an async function does not work in the express adapter. Is that supposed to work or is that the expected behavior? If this is a bug i can toss together a quick sandbox, but figured I check first whether this is expected or not. If this is expected behavior, should the async calls happen in middleware instead? Seems a bit at odds. Thoughts?...

Is it possible to split the router definition with the imlementation?

I want to define the server router(input\output\meta) in a separate package from the server package I want to have a package that will contain the types I use + the router definition, another for the server itself(will use the router definition like an interface), and lastly the client package which ill only need to import the types package to work is this possible?...

Cache not working for `useQuery`

I have a query like this: ```js const { data: article, isFetching } = api.public.getArticle.useQuery({ id: targetId, });...

Zod File Upload Validation with Open-Api Support?

Hi guys, anyone know how to validate file upload with zod and get also open-api support?

Zod validation and open-api support for File on the server?

Hi guys, anyone know how to validate a File upload using zod? and also have open-api support?

is context cached?

If I put an object on the context that represents the User record from my database... ``` export async function createContext(event: H3Event){ if (!dbUser) { const userService = new UserService();...

JSON inferred router output not matching

Hello. I have a procedure query which is returning Json from a postgresql db using Prisma. The type in the query on the server is showing up as JsonValue (definitions below). The inferred type from the router.procedure.query() on a createTRPCProxyClient instance comes back as expected, but the type definition using inferRouterOutputs<AppRouter> types the Json data as string | null. Any ideas? Thanks. New to tRPC so sorry if this is a no-brainer....

Best way to implement input based validation on a router procedure

Hi guys, bit of a noob. I have already created a 'protectedProcedure', ensuring the user is logged in, but for some of my procedures, I also want to ensure the user is an ADMIN for the account specified on the input. This is my first try with validation just added at the top of the procedure implementation... ``` changeUserAccessWithinAccount: protectedProcedure .input(z.object({ user_id: z.number(), account_id: z.number(), access: z.enum([ACCOUNT_ACCESS.ADMIN, ACCOUNT_ACCESS.OWNER, ACCOUNT_ACCESS.READ_ONLY, ACCOUNT_ACCESS.READ_WRITE]) })) .query(async ({ ctx, input }) => {...