update validation readme

This commit is contained in:
Robert Soriano
2022-05-18 09:25:19 -07:00
parent 93bfc241ee
commit 6f1fc6a996

View File

@@ -2,6 +2,8 @@
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).
## Input Validation
```ts
// ~/server/trpc/index.ts
import { z } from 'zod'
@@ -21,3 +23,25 @@ export const router = trpc
},
})
```
## Output Validation
```ts
// ~/server/trpc/index.ts
import { z } from 'zod'
export const router = trpc
.router()
.query('hello', {
// validate output with Zod
output: z.object({
greeting: z.string()
}),
// expects return type of { greeting: string }
resolve() {
return {
greeting: 'hello!',
}
},
})
```