tRPC
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.
Join ServerCommunity questions
Channels
Basic Inference not Working
This is what my server-side router is returning from the
list
method:export const organizationRouter = router({
list: adminProcedure.query(async () => {
const response = await listOrganizations.all();
return response;
}),
Where, if I hover over the
response
in the return, it says the type is:```
const response: {
id: number;
name: string;
description: string | nu...
tRPC Websockets with a standalone Bun Server?
Experiementing with setting up a standalone tRPC Server using Bun. The HTTP part is great - i'm wondering if anyone has succeeded getting it to work with Bun's websocket server? if not, i'll continue figuring it out and hopefully add an adapter to tRPC.
Infinite session query when tab is in background
How to return a stream? like open ai api
https://github.com/openai/openai-node#streaming-responses
how can i do it?
Thanks
was wondering if anyone got a chance to use Ajv as input/output validator?
state change does not refetch the query and the app freezes
I am not sure if linking is allowed but I opened a discussion in the repo and have gotten no responses. I am hoping someone here can help me.
It is very likely a mistake on my part and would really appreciate it if someone could point me in the right direction.
trpc subscription with react-query
having error when use subscription with react-query
import { createTRPCReact } from "@trpc/react-query";
export const trpc = createTRPCReact<AppRouter>();
const wsClient = createWSClient({
url:
ws://localhost:8080/ws
,});
const trpcClient = trpc.createClient({
transformer: SuperJSON,
links: [
httpLink({
url:
/trpc
,}),
wsLink({
client: wsClient,
}),
],
});
<trpc.Provider client={trpcClient} queryClient...
Unable to get mutation to trigger subscription because EventEmitter not being shared
Been struggling with this for a few hours now hopelessly and trying random things - read all related posts in this forum, on github issues, and stackoverflow - and still don't understand what is going on.
I have a next app with a custom HTTP server and using tRPC. WSLink etc is all fine - i'm doing everything the proper way.
I have a router with these two functions:
```ts
sendMessage: protectedProcedure
.input(z.string())
.mutation(async ({ ctx, input }) => {
try {...
Is there a guide of how to test?
I'm frontend trying to create my first api 🙂
Thanks
Modify the payload before mutating
My only solution would be redefining mutate and mutateAsync that are modified to do this preprocessing.
Thanks!
is there a simple boilerplate that has everything ready to deploy?
I use turborepo, so can be an internal package.
But I want to see how the project configuration looks for the deploy.
It's the first time I am creating a server, for now it will be deployed on a PC on an intranet.
It's just a server to everyone in the intranet can access and modify a json file.
Thanks
Context is not fully globally accessed? [ probably newbie question ]
opts.ctx
doesn't exist before I create it, although I've used .context()
upon initializing trpc
, but that's no big deal.Context defined by a procedure cannot be seen by another procedure?? how do I get around that?
```ts
const trpc = initTRPC.context<{
userSession: { id: string, authenticated: boolean }
}>().create();
const baseP...
Using tRPC for server to server requests
The core of these functions is encrypting + compressing requests to the separate server as well as decrytping + decompressing on the separate server and then again on the way back (the response).
T...
ReferenceError: FormData is not defined
ReferenceError: FormData is not defined
in /node_modules/@trpc/server/dist/adapters/node-http/content-type/form-data/index.mjs
for: const formData = new FormData();
const parts = streamMultipart(Readable.toWeb(request), boundary);
Can anyone save me?
TRPCError that has TRPCError as cause
What I'm doing is basically having a mutation that does:
something: t.procedure
.input(mySchema)
.mutation() => Promise.reject(new Error('oh no'))),
and then, the onError handler has:
onError({ error }) {
console.log('onError', error.name, error.cause.name)
},
which logs:
onError TRPCError TRPCError
. If I then go further with error.cause.cause.name
, I can see my er...How do you make use of custom input validation?
export function contextInputValidation(
callback: (options: { ctx: Context }) => zod.Schema,
) {
return middleware(async ({ next, ctx, rawInput }) => {
const schema = callback({ ctx });
const input = schema.parse(rawInput);
const stack = await next({
rawInput: input,
});
return stack;
});
}
However, how can I pass the value of this input...
Why useQuery() tries to refetch when error occurs while useMutation() doesn't?
test: publicProcedure.input(z.string().min(5)).query(async () => {
return "hi!";
}),
const { error } = api.user.test.useQuery("test");
(it should return a Zod validation error)
the client tries to refetch 3 times and then returns the error (4-5 seconds of delay), throughout the process the error is logged by the
loggerLink
, but the error
returned takes a while, but when I switch to useMutation()
the error is returned rather instantly, what...In a monorepo can I have 2 packages each one with different trpc server, and use both in 1 app?
Thanks