Compare commits

..

4 Commits

Author SHA1 Message Date
Robert Soriano
7f44e049c0 release v0.1.16 2022-05-23 12:41:55 -07:00
Robert Soriano
5a71bbf1fe refactor: use trpc url from config 2022-05-23 12:41:49 -07:00
Robert Soriano
285487e9bf release v0.1.15 2022-05-23 11:24:10 -07:00
Robert Soriano
2cfa64fcc6 fix: unresolvable runtime config 2022-05-23 11:24:07 -07:00
5 changed files with 13 additions and 16 deletions

View File

@@ -1,7 +1,7 @@
{
"name": "trpc-nuxt",
"type": "module",
"version": "0.1.14",
"version": "0.1.16",
"packageManager": "pnpm@7.1.1",
"license": "MIT",
"main": "./dist/module.cjs",

View File

@@ -1,12 +1,12 @@
<script setup lang="ts">
const client = useClient()
const { $client } = useNuxtApp()
const { data: todos, pending, error, refresh } = await useAsyncQuery(['getTodos'])
const addTodo = async () => {
const title = Math.random().toString(36).slice(2, 7)
try {
const result = await client.mutation('addTodo', {
const result = await $client.mutation('addTodo', {
id: Date.now(),
userId: 69,
title,

View File

@@ -42,8 +42,8 @@ export async function createContext(event: CompatibilityEvent) {
// Will be available as `ctx` in all your resolvers
// This is just an example of something you'd might want to do in your ctx fn
// const x = useCookies(event)
console.log('Headers', event.req.headers)
const x = useCookies(event)
console.log(x)
return {

View File

@@ -51,14 +51,11 @@ export default defineNuxtModule<ModuleOptions>({
getContents() {
return `
import { createTRPCHandler } from 'trpc-nuxt/api'
import { useRuntimeConfig } from '#imports'
import * as functions from '${trpcOptionsPath}'
const { trpc: { trpcURL } } = useRuntimeConfig().public
export default createTRPCHandler({
...functions,
trpcURL
trpcURL: '${finalConfig.trpcURL}'
})
`
},

View File

@@ -3,15 +3,15 @@ import * as trpc from '@trpc/client'
import { defineNuxtPlugin, useRequestHeaders, useRuntimeConfig } from '#app'
import type { router } from '~/server/trpc'
type AppRouter = typeof router
const config = useRuntimeConfig().public.trpc
const client = trpc.createTRPCClient<AppRouter>({
url: `${config.baseURL}${config.trpcURL}`,
headers: useRequestHeaders(),
})
declare type AppRouter = typeof router
export default defineNuxtPlugin(() => {
const config = useRuntimeConfig().public.trpc
const client = trpc.createTRPCClient<AppRouter>({
url: `${config.baseURL}${config.trpcURL}`,
headers: useRequestHeaders(),
})
return {
provide: {
client,