Access input schema in the client #2021
Replies: 5 comments 3 replies
-
@KATT this feels suboptimal tbh, maybe it's just me but it makes sense that the server will "set the tone" and define its inputs which can be exported to the clients. It's a pretty common scenario where you have a single API serving multiple clients (web/expo/docs), whereas I haven't seen the other way around of having a single client who "demands" from several servers. maybe it's a topic for a whole new discussion but it seems like there's a reasonable demand to develop a best practice that will unify tRPC + zod + prisma schemas. |
Beta Was this translation helpful? Give feedback.
-
You can create your own type InferMutationInput<T extends UseTRPCMutationResult<any, any, any, any>> = NonNullable<
T['variables']
> If that's the kind of interface you're looking for, then |
Beta Was this translation helpful? Give feedback.
-
I tried making and exporting validationSchema from the server and passing it to the It would be great to have a method to get the validation schema from mutation. But when it comes to type only @solaldunckel you can infer type like this: type TEquipmentCreateInput = inferRouterInputs<Router>["create"]; where export type AppRouter = typeof appRouter; |
Beta Was this translation helpful? Give feedback.
-
Hey there, Just to share my solution, I ended up creating a shared folder in Not optimal but at least it solves the problem and is less weird than importing something into the server from the frontend |
Beta Was this translation helpful? Give feedback.
-
Hi !
Would be awesome to have access to the input schema on the client for form validation.
It could be really useful if you pair it with packages such as react-hook-form that supports schema resolvers (zod, yup...).
Maybe it could be exposed through a utility function similar to that ?
Beta Was this translation helpful? Give feedback.
All reactions