refactor(client): 合并 orpc.ts 和 query-client.ts 为单文件,遵循 ORPC 官方模式

This commit is contained in:
2026-03-05 11:05:53 +08:00
parent 0cd8b57d24
commit 02bdfffe79
5 changed files with 34 additions and 36 deletions

View File

@@ -1,6 +1,7 @@
import { createORPCClient } from '@orpc/client'
import { RPCLink } from '@orpc/client/fetch'
import { createRouterClient } from '@orpc/server'
import { createTanstackQueryUtils } from '@orpc/tanstack-query'
import { createIsomorphicFn } from '@tanstack/react-start'
import { getRequestHeaders } from '@tanstack/react-start/server'
import { router } from '@/server/api/routers'
@@ -21,4 +22,32 @@ const getORPCClient = createIsomorphicFn()
return createORPCClient<RouterClient>(link)
})
export const orpc: RouterClient = getORPCClient()
const client: RouterClient = getORPCClient()
export const orpc = createTanstackQueryUtils(client, {
experimental_defaults: {
todo: {
create: {
mutationOptions: {
onSuccess: (_, __, ___, ctx) => {
ctx.client.invalidateQueries({ queryKey: orpc.todo.list.key() })
},
},
},
update: {
mutationOptions: {
onSuccess: (_, __, ___, ctx) => {
ctx.client.invalidateQueries({ queryKey: orpc.todo.list.key() })
},
},
},
remove: {
mutationOptions: {
onSuccess: (_, __, ___, ctx) => {
ctx.client.invalidateQueries({ queryKey: orpc.todo.list.key() })
},
},
},
},
},
})