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(); }), });
7 Replies
Froxx
Froxx2y ago
When writing e.g. ctx.prisma.example.findUnique( your IDE should already tell you what your options are thanks to TypeScript (spoiler alert: it's an object with props predefined by prisma). A regular findUnique call looks something like .findUnique({where: id: input.id}) most of the times
ibamsey
ibamsey2y ago
Thanks @Froxx. I kinda got that bit. It's the synax for the publicProcedure.query(({ctx} blar blar {input} bit that has me scratchin'
Froxx
Froxx2y ago
Oh I see. It's just .query(({ ctx, input })
ibamsey
ibamsey2y ago
@Froxx cheers!
Froxx
Froxx2y ago
love
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
ibamsey
ibamsey2y ago
@Koen thanks for that. Helpful.
Want results from more Discord servers?
Add your server