immediately execute mutations

This commit is contained in:
Robert Soriano
2022-10-30 01:52:20 -07:00
parent 025ce7e028
commit b45c613ce7
3 changed files with 4 additions and 28 deletions

View File

@@ -11,14 +11,13 @@ const addTodo = async () => {
const title = Math.random().toString(36).slice(2, 7)
try {
const result = await $client.todo.addTodo.mutate({
const x = await $client.todo.addTodo.mutate({
id: Date.now(),
userId: 69,
title,
completed: false,
})
await result.execute()
console.log('Todo: ', result.data.value)
console.log(x.data.value)
}
catch (e) {
console.log(e)

View File

@@ -11,8 +11,8 @@
"import": "./dist/index.mjs"
},
"./client": {
"require": "./dist/client.js",
"import": "./dist/client.mjs"
"require": "./dist/client/index.js",
"import": "./dist/client/index.mjs"
}
},
"main": "./dist/index.js",
@@ -37,7 +37,6 @@
"dependencies": {
"h3": "^0.8.5",
"ohash": "^0.1.5",
"ohmyfetch": "^0.4.20",
"ufo": "^0.8.6"
},
"devDependencies": {

View File

@@ -1,6 +1,5 @@
import type { CreateTRPCClientOptions, inferRouterProxyClient } from '@trpc/client'
import { createTRPCProxyClient } from '@trpc/client'
import { FetchError } from 'ohmyfetch'
import type {
AnyRouter,
} from '@trpc/server'
@@ -37,13 +36,6 @@ export function createNuxtProxyDecoration<TRouter extends AnyRouter>(name: strin
const queryKey = getQueryKey(path, input)
if (lastArg === 'mutate') {
return useAsyncDataWithError(queryKey, () => (client as any)[path][lastArg](input), {
...asyncDataOptions as Record<string, any>,
immediate: false,
})
}
return useAsyncDataWithError(queryKey, () => (client as any)[path][lastArg](input), asyncDataOptions)
})
}
@@ -79,17 +71,3 @@ export function createTRPCNuxtProxyClient<TRouter extends AnyRouter>(opts: Creat
return decoratedClient
}
export function customFetch(input: RequestInfo | URL, options?: RequestInit) {
return globalThis.$fetch.raw(input.toString(), options)
.catch((e) => {
if (e instanceof FetchError && e.response)
return e.response
throw e
})
.then(response => ({
...response,
json: () => Promise.resolve(response._data),
}))
}