update readme

This commit is contained in:
Robert Soriano
2022-05-19 01:13:28 -07:00
parent 0211084f5c
commit 50297d4ac0

View File

@@ -34,18 +34,24 @@ Expose your tRPC [routes](https://trpc.io/docs/router) under `~/server/trpc/inde
// ~/server/trpc/index.ts // ~/server/trpc/index.ts
import type { inferAsyncReturnType } from '@trpc/server' import type { inferAsyncReturnType } from '@trpc/server'
import * as trpc from '@trpc/server' import * as trpc from '@trpc/server'
import { z } from 'zod' // yup/superstruct/zod/myzod/custom
export const router = trpc export const router = trpc.router()
.router<inferAsyncReturnType<typeof createContext>>()
// queries and mutations... // queries and mutations...
.query('hello', { .query('getUsers', {
resolve: () => 'world', async resolve(req) {
// use your ORM of choice
return await UserModel.all()
},
}) })
.query('bye', { .mutation('createUser', {
resolve() { // validate input with Zod
return { input: z.object({ name: z.string().min(5) }),
text: 'goodbye', async resolve(req) {
} // use your ORM of choice
return await UserModel.create({
data: req.input,
})
}, },
}) })
``` ```
@@ -55,11 +61,13 @@ Use the client like so:
```ts ```ts
const client = useClient() // auto-imported const client = useClient() // auto-imported
const greeting = await client.query('hello') const users = await client.query('getUsers')
console.log(greeting) // => 👈 world
const farewell = await client.query('bye') const addUser = async () => {
console.log(farewell) // => 👈 goodbye const mutate = await client.mutation('createUser', {
name: 'wagmi'
})
}
``` ```
## useAsyncQuery ## useAsyncQuery