update merging routers example

This commit is contained in:
Robert Soriano
2022-05-19 10:54:08 -07:00
parent c48556e24e
commit 812ceda4a0

View File

@@ -2,21 +2,11 @@
Writing all API-code in your code in the same file is not a great idea. It's easy to merge routers with other routers.
Define your routes:
```ts
// ~/server/trpc/routes/posts.ts
export const posts = trpc.router()
.mutation('create', {
input: z.object({
title: z.string(),
}),
resolve: ({ input }) => {
// ..
return {
id: 'xxxx',
...input,
}
},
})
.query('list', {
resolve() {
// ..
@@ -45,3 +35,12 @@ export const router = trpc.router()
.merge('user.', users) // prefix user procedures with "user."
.merge('post.', posts) // prefix post procedures with "post."
```
and use it like this:
```html
<script setup lang="ts">
const { data: users } = await useAsyncQuery(['user.list'])
const { data: posts } = await useAsyncQuery(['post.list'])
</script>
```