mirror of
https://github.com/ArthurDanjou/trpc-nuxt.git
synced 2026-01-14 20:19:33 +01:00
immediately execute mutations
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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": {
|
||||
|
||||
@@ -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),
|
||||
}))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user