Skip to content

Commit 3bbba99

Browse files
Frank-IIIAmp
andcommitted
Relax response constraints and expand README
Amp-Thread-ID: https://ampcode.com/threads/T-019c1fb5-9bdc-716e-aee6-e3391dd495c3 Co-authored-by: Amp <amp@ampcode.com>
1 parent e7274c5 commit 3bbba99

2 files changed

Lines changed: 51 additions & 2 deletions

File tree

README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
TanStack Query integration for [Elysia Eden](https://github.com/elysiajs/eden) - type-safe queries and mutations with zero boilerplate.
44

5+
Highlights:
6+
7+
- Auto-generated `queryKey`, `queryOptions`, `mutationOptions`, and cache helpers
8+
- Type-safe data and error inference from your Elysia routes
9+
- Works with any TanStack Query adapter (React, Svelte, Vue, Solid)
10+
511
## Installation
612

713
```bash
@@ -34,6 +40,18 @@ const query = createQuery(() =>
3440
// query.data is typed as your Elysia response type!
3541
```
3642

43+
React example:
44+
45+
```ts
46+
import { useQuery } from '@tanstack/react-query'
47+
48+
const query = useQuery(
49+
eden.users({ id: '123' }).get.queryOptions({
50+
params: { id: '123' }
51+
})
52+
)
53+
```
54+
3755
### Infinite Queries
3856

3957
```ts
@@ -107,6 +125,23 @@ utils.users({ id: '123' }).get.setData({ params: { id: '123' } }, { id: '123', n
107125
const cached = utils.users({ id: '123' }).get.getData({ params: { id: '123' } })
108126
```
109127

128+
### Error Handling
129+
130+
`queryFn` and `mutationFn` throw when the Eden response has `error`, so TanStack
131+
Query error states are populated automatically:
132+
133+
```ts
134+
const options = eden.users({ id: '123' }).get.queryOptions({
135+
params: { id: '123' }
136+
})
137+
138+
try {
139+
const data = await options.queryFn()
140+
} catch (error) {
141+
// error is typed from your Elysia response map
142+
}
143+
```
144+
110145
## API
111146

112147
### `createEdenTQ<App>(domain, config?)`
@@ -137,6 +172,20 @@ Each HTTP method (`get`, `post`, `put`, `delete`, `patch`) has:
137172
| `.setData(queryClient, input, updater)` | Manually set cache data |
138173
| `.getData(queryClient, input)` | Read from cache |
139174

175+
### Query Key Shape
176+
177+
Query keys are deterministic and include routing information:
178+
179+
```
180+
[
181+
...queryKeyPrefix, // default ['eden']
182+
method, // 'get', 'post', ...
183+
pathTemplate, // e.g. ['users', ':id']
184+
params ?? null,
185+
query ?? null
186+
]
187+
```
188+
140189
### Query Options Overrides
141190

142191
You can pass standard TanStack Query options as overrides:

src/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ export interface EdenTQMethod<
155155
Headers,
156156
Query,
157157
Params,
158-
Res extends Record<number, unknown>
158+
Res
159159
> {
160160
<TQueryFnData = ExtractData<Res>>(
161161
input: TQMethodParam<Body, Headers, Query, Params>,
@@ -264,7 +264,7 @@ export interface EdenTQUtilsMethod<
264264
Headers,
265265
Query,
266266
Params,
267-
Res extends Record<number, unknown>
267+
Res
268268
> {
269269
queryKey(input?: OmitQueryInput<TQMethodParam<Body, Headers, Query, Params>>): QueryKey
270270

0 commit comments

Comments
 (0)