mirror of
https://github.com/ArthurDanjou/trpc-nuxt.git
synced 2026-02-02 21:27:53 +01:00
update validation readme
This commit is contained in:
@@ -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).
|
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
|
```ts
|
||||||
// ~/server/trpc/index.ts
|
// ~/server/trpc/index.ts
|
||||||
import { z } from 'zod'
|
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!',
|
||||||
|
}
|
||||||
|
},
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user