update readme

This commit is contained in:
Robert Soriano
2022-05-18 09:20:29 -07:00
parent 3eda32d33a
commit cec8ea52d6
3 changed files with 78 additions and 77 deletions

23
recipes/validation.md Normal file
View File

@@ -0,0 +1,23 @@
## Validation
tRPC works out-of-the-box with yup/superstruct/zod/myzod/custom validators. Learn more about input validation [here](https://trpc.io/docs/router#input-validation).
```ts
// ~/server/trpc/index.ts
import { z } from 'zod'
export const router = trpc
.router()
.mutation('createUser', {
// validate input with Zod
input: z.object({
name: z.string().min(5)
}),
async resolve(req) {
// use your ORM of choice
return await UserModel.create({
data: req.input,
})
},
})
```