Use this tag for tRPC, the TypeScript library for defining and using type-safe APIs for use with TypeScript servers and clients. For Remote Procedure Call, use [rpc] instead.
Questions tagged [trpc.io]
124 questions
2
votes
0 answers
Setting up rate limiter with tRPC
Hey I tried set up express-rate-limit w tRPC but it doesnt work.How can i achive it to work
const test= t.middleware(async ({ next, ctx: { req, res } }) => {
rateLimit({
windowMs: 60 * 60 * 1000, // 1 hour
max: 5,
message: 'Too…

IvonaK
- 119
- 10
2
votes
1 answer
How to make Object Properties flexible with Zod?
New to Typescript, Zod & Trpc.
Say I have a schema for both animals & plants. I want to store all their common properties in the "root" of the schema and then put the more specific properties into a sub-object called custom. (just a made-up example…

antonwilhelm
- 5,768
- 4
- 19
- 45
2
votes
0 answers
how to use mutations in TRPC router?
I'm having a bit of trouble with my mutation code in tRPC v10.
The getCookie query below is working fine, but the setCookie mutation is not coming through to the client side TS, or executing successfully - any idea why?
export const appRouter =…

fotoflo
- 821
- 1
- 9
- 21
2
votes
1 answer
Filtering with React-Query + Prisma - How to pass down filters dynamically & and completely omit them from my prisma call, when they aren't present?
Say I have a filter on my frontend. I have an option to get all the users who are blue or all the users who are red. In the front-end, I pass that filter value into react-query and in the backend I use that passed-down filter value in my prisma call…

antonwilhelm
- 5,768
- 4
- 19
- 45
2
votes
0 answers
Typescript error with tRPC useQuery argument types in Jest test
I have a monorepo which contains a React Native app. Within one of the components I have the following code:
const { data: user, refetch } = trpc.useQuery([
"user.get",
{ id: state.user!.id },
])
// Later I use the user I receive from this…

TempestWindblown
- 31
- 3
2
votes
1 answer
TRPC doesn't react to config / variables passed (e.g.: enabled : false)
New to trpc and am trying to understand how to use useQuery (which I am familiar with from react-query):
const IndexPage = () => {
const { isLoading, data, isIdle } = trpc.useQuery([
"subscriber.add",
{ email: "elsa@prisma.io" },
{
…

antonwilhelm
- 5,768
- 4
- 19
- 45
2
votes
3 answers
tRPC How to encapsulate middleware?
I am trying to put middleware into its own function but I am struggling to get proper typescript typing on it.
At the moment I am typing the middleware as follows, but this isn't ideal because the type information of context and metadata are lost…

manwingbb
- 31
- 5
2
votes
4 answers
useQuery with tRPC wont recieve my query input
I am new to tRPC and react-query. I've been working to test .query (BE) and useQuery (FE) and I tried to pass data from FE to BE. However, since TS is a static typing, I get compile error although the code is working (it's working smoothly if I…

Maria Khelli
- 21
- 1
- 4
2
votes
2 answers
Error when using Prisma with tRPC: Return type of exported function has or is using name 'prisma' from external module
I'm trying to integrate Prisma with tRPC for my backend. Both of them alone work fine but once I try to integrate them with each other an error is thrown.
This is the error message I get:
TS4058: Return type of exported function has or is using…

Nils Haberkamp
- 39
- 1
- 4
1
vote
0 answers
Next.js + tRPC + response with cookie
I'm using Next.js 13 and tRPC 10. For auth purposes, I'm trying to create a specific tRPC endpoint which can set cookies.
I've looked over the tRPC docs but I'm still not clear on what to do.

Meow
- 1,610
- 1
- 14
- 18
1
vote
1 answer
How to make a tRPC server return plain text?
Generally a response from tRPC server looks like:
{
"result": {
"data": "OK!"
}
}
But what I need is only:
OK!
How do I attain this?
Sorry for asking this silly question. I'm new to this tRPC thing and still figuring things out.

stack5
- 430
- 2
- 10
1
vote
1 answer
tRPC query request won't pass my query parameter
Hi when I send request to http://localhost:5000/trpc/test?val=teststring by using below minimal reproducible example, it returns message: "Invalid input: undefined" because as it says, the val really is undefined. What am I doing wrong? I tried to…

Alk
- 313
- 4
- 13
1
vote
0 answers
How can I set up Typescript to import types from another Prisma folder?
We're using Typescript, Prisma and TRPC in two NodeJS services that need to communicate with each other. Both services have their own database, so the generated Prisma client in node_modules is different between the folders. The folder structure is…

Ben Grant
- 305
- 6
- 18
1
vote
2 answers
Custom Zod errors in tRPC
How can I set up tRPC so that when zod throws an error I can handle it instead of tRPC. I have looked everywhere for an answer and I can't find one

Noah -
- 33
- 7
1
vote
0 answers
How to I access an endpoint covered by next-auth through google app script
So recently I decided that I need to access a protected api endpoint in google app script. The only thing I can find is app-script-oauth2, the reason this does not work is because my middleware for the tRPC endpoint (code below) says if there is not…

Noah -
- 33
- 7