update router location

This commit is contained in:
Robert Soriano
2022-05-17 16:50:41 -07:00
parent 81d8497f20
commit 2f19d63e5c
4 changed files with 7 additions and 13 deletions

View File

@@ -21,10 +21,10 @@ export default defineNuxtConfig({
## Usage
Create your tRPC [routes](https://trpc.io/docs/router) and [context](https://trpc.io/docs/context) under `server/fn/index.ts`:
Create your tRPC [routes](https://trpc.io/docs/router) and [context](https://trpc.io/docs/context) under `~/trpc/index.ts`:
```ts
// ~/server/fn/index.ts
// ~/trpc/index.ts
import type { inferAsyncReturnType } from '@trpc/server'
import * as trpc from '@trpc/server'

View File

@@ -1,18 +1,12 @@
<script setup lang="ts">
const { data, pending } = useLazyTrpcQuery('getUser', {
const client = useClient()
const data = await client.query('getUser', {
name: 'roberts',
})
watchEffect(() => {
console.log(data.value)
})
</script>
<template>
<div v-if="pending">
Loading...
</div>
<div v-else>
<div>
{{ data }}
</div>
</template>

View File

@@ -38,7 +38,7 @@ export default defineNuxtModule<ModuleOptions>({
await fs.writeFile(clientPath, `
import * as trpc from '@trpc/client'
import { createTRPCComposables } from 'trpc-nuxt/client'
import { router } from '~/server/fn'
import type { router } from '~/trpc'
const client = trpc.createTRPCClient<typeof router>({
url: process.browser ? '/trpc' : 'http://localhost:3000/trpc',
@@ -61,7 +61,7 @@ export default defineNuxtModule<ModuleOptions>({
await fs.writeFile(handlerPath, `
import { createTRPCHandler } from 'trpc-nuxt/api'
import * as functions from '~/server/fn'
import * as functions from '~/trpc'
export default createTRPCHandler({
router: functions.router,