Skip to content

Commit 67ce889

Browse files
author
tiesen243
committed
feat: added mutate and query
1 parent 66000aa commit 67ce889

4 files changed

Lines changed: 50 additions & 0 deletions

File tree

‎.tegami/2026-08-16-msvkm335.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
packages:
3+
npm:@tiesen/effect-tanstack-query: patch
4+
---
5+
6+
## Add direct `query` and `mutate` support
7+
8+
- Added the `query` method to allow executing `GET` endpoints directly.
9+
- Added the `mutate` method to support executing `non-GET` mutation endpoints directly.

‎README.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,13 @@ const queryClient = useQueryClient()
138138
void queryClient.invalidateQueries({
139139
queryKey: api.group.hello.getQueryKey(),
140140
})
141+
142+
// Call Query / Mutate Directly Example
143+
const result = await api.group.hello.query({
144+
params: { name: 'John' },
145+
query: { greeting: 'Hi' },
146+
})
147+
const result2 = await api.group.goodbye.mutate({ payload: { name: 'John' } })
141148
```
142149

143150
## Downloads

‎src/create-proxy.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ export function createTanstackQueryOptionsProxy<TServiceTag, TService>(
125125
...(inp ? [inp] : []),
126126
]
127127

128+
if (action === 'query' || action === 'mutate') return execute(input)
129+
128130
if (action === 'queryOptions')
129131
return {
130132
...options,

‎src/types.ts‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,22 @@ export type TanstackQueryOptionsProxy<T> =
3232
infer _Requires
3333
>
3434
? {
35+
query: Method extends 'GET'
36+
? (
37+
input: MakeOptionalInput<
38+
([Params] extends [never]
39+
? unknown
40+
: { params: UnwrapCodec<Params> }) &
41+
([Query] extends [never]
42+
? unknown
43+
: { query: UnwrapCodec<Query> }) &
44+
([Headers] extends [never]
45+
? unknown
46+
: { headers: UnwrapCodec<Headers> })
47+
>
48+
) => UnwrapCodec<Success> | Promise<UnwrapCodec<Success>>
49+
: never
50+
3551
queryOptions: Method extends 'GET'
3652
? <TQuery = QueryOptions<UnwrapCodec<Success>, UnwrapCodec<Error>>>(
3753
input: MakeOptionalInput<
@@ -79,6 +95,22 @@ export type TanstackQueryOptionsProxy<T> =
7995
>
8096
: never
8197

98+
mutate: Method extends 'GET'
99+
? never
100+
: (
101+
input: MakeOptionalInput<
102+
([Params] extends [never]
103+
? unknown
104+
: { params: UnwrapCodec<Params> }) &
105+
([Headers] extends [never]
106+
? unknown
107+
: { headers: UnwrapCodec<Headers> }) &
108+
([Payload] extends [never]
109+
? unknown
110+
: { payload: UnwrapCodec<Payload> })
111+
>
112+
) => UnwrapCodec<Success> | Promise<UnwrapCodec<Success>>
113+
82114
mutationOptions: Method extends 'GET'
83115
? never
84116
: <

0 commit comments

Comments
 (0)