Theo's Typesafe CultTTC
Theo's Typesafe Cult4y ago
8 replies
ibamsey

tRPC query syntax

Can someone please help a Noob here. I'm struggling to work out how to modify the create-T3-app code below for a findUnique or findFirst query where I will need both {ctx} and {input}. Apologies, I'm new to TypeScript !

import { z } from "zod";
import { router, publicProcedure } from "../trpc";

export const exampleRouter = router({
hello: publicProcedure
.input(z.object({ text: z.string().nullish() }).nullish())
.query(({ input }) => {
return {
greeting: Hello ${input?.text ?? "world"},
};
}),
getAll: publicProcedure.query(({ ctx }) => {
return ctx.prisma.example.findMany();
}),
});
Was this page helpful?