David
David6mo ago

Best way to get the type of the first argument for .query or .mutation

I am creating an abstraction in which I expect the consumer to pass the whole object that is passed as the first argument of .query or .mutation. But im not sure if there is a helper type to get this type from our instance?
5 Replies
Alex / KATT 🐱
inferProcedureInput?
David
DavidOP6mo ago
That would return just the input, I assume? I want the type for the whole first argument that gets passed, incl context etc if possible I want to do something like this:
.input(Zod).query(onUploadComplete(({ input, ctx }) => {
...
})
.input(Zod).query(onUploadComplete(({ input, ctx }) => {
...
})
Alex / KATT 🐱
Define Procedures | tRPC
A procedure is a function which is exposed to the client, it can be one of:
David
DavidOP6mo ago
That looks like it can help me get what I need, thanks! Ah, is that only a v11 feature? Maybe its best I just explain what im looking to achieve. For file uploads our current flow is: 1. Get upload token through query 2. Use upload token to upload directly to S3 from browser 3. Call mutation to do something with this finished upload We currently reuse the same logic everywhere for this, but we've gotten to a point where quite often we want to do some type of server-side logic before returning an upload token, or after uploading. So I want to create a function that takes in a couple of arguments to help with this, and returns a router. So we can do something like:
const { upload ] = useUpload(trpc.path.to.specific.upload.router)

// useUpload
const upload = (args) => {
const token = await router.getUploadToken({ args })
// upload to S3
await router.onUploadFinished({ args })
}
const { upload ] = useUpload(trpc.path.to.specific.upload.router)

// useUpload
const upload = (args) => {
const token = await router.getUploadToken({ args })
// upload to S3
await router.onUploadFinished({ args })
}
Alex / KATT 🐱
i'm sorry, but i don't have the capacity to help more here, it requires some wrangling and more back-and-fourth. does your company sponsor trpc?