@uiwwsw/react-query-helper 1.3.0 โ 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +50 -0
- package/README.md +109 -362
- package/README_EN.md +165 -0
- package/dist/cli.d.ts +0 -1
- package/dist/cli.js +681 -2081
- package/dist/config-loader.d.ts +10 -6
- package/dist/config-loader.js +201 -0
- package/dist/config.d.ts +2 -3
- package/dist/core/analyzer.d.ts +3 -1
- package/dist/core/analyzer.js +109 -55
- package/dist/core/generator.d.ts +4 -3
- package/dist/core/generator.js +97 -85
- package/dist/index.d.ts +2 -3
- package/dist/index.js +98 -91
- package/dist/utils/query.d.ts +59 -50
- package/package.json +39 -27
- package/dist/cli.d.ts.map +0 -1
- package/dist/config-loader.d.ts.map +0 -1
- package/dist/config.d.ts.map +0 -1
- package/dist/core/analyzer.d.ts.map +0 -1
- package/dist/core/generator.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/utils/query.d.ts.map +0 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 2.0.2
|
|
4
|
+
|
|
5
|
+
- Shorten the README to what works, what is not done, and how it compares with OpenAPI-based generators; move the details into docs/GUIDE.md. No code changes.
|
|
6
|
+
|
|
7
|
+
## 2.0.1
|
|
8
|
+
|
|
9
|
+
The v2.0.0 tag was not published to npm. This release includes all of the 2.0.0
|
|
10
|
+
changes below, including the breaking changes for applications upgrading from 1.x.
|
|
11
|
+
|
|
12
|
+
- Simplify Korean/English onboarding and move detailed configuration and recipes into reference guides.
|
|
13
|
+
- Introduce the Q symbol, light/dark README banners, and documented brand assets.
|
|
14
|
+
- Add regression tests for documentation links, SVG assets, and generated/typechecked README examples.
|
|
15
|
+
- Refresh release guidance and source-install examples for 2.0.1.
|
|
16
|
+
|
|
17
|
+
## 2.0.0
|
|
18
|
+
|
|
19
|
+
### Breaking Changes
|
|
20
|
+
|
|
21
|
+
- Require TanStack Query >=5.102.8 <6. Node 22 remains the minimum CLI runtime.
|
|
22
|
+
- Generated path keys now include filenames. Query/infinite keys use separate kind segments and nested argument tuples. Invalidate persisted 1.x caches and update manually constructed keys.
|
|
23
|
+
- Remove forced infinite cache/stale times and disabled focus refetching. QueryClient defaults now apply.
|
|
24
|
+
- Single-array mutation payloads are passed intact. Direct multi-argument helpers require an explicit mapper or tuple mode.
|
|
25
|
+
- Refuse to overwrite output without this generator's ownership marker. Move legacy generated files aside and regenerate.
|
|
26
|
+
- Built-in generation rejects private imports, invalid identifiers, duplicate names and invalid configuration.
|
|
27
|
+
|
|
28
|
+
### Fixed
|
|
29
|
+
|
|
30
|
+
- Starter configs no longer reference missing plugins or assume an application alias.
|
|
31
|
+
- Correct InfiniteData, pageParam, select, default error, cache data-tag and optimistic rollback inference.
|
|
32
|
+
- Forward query/mutation context, including QueryClient and AbortSignal, to custom callbacks.
|
|
33
|
+
- Convert synchronous callback failures to rejected promises.
|
|
34
|
+
- Support default/local alias exports, skip ambient declarations and duplicate overload signatures.
|
|
35
|
+
- Preserve optional multi-argument mutation fields and handle rest/destructured parameters using tuples.
|
|
36
|
+
- Include source filenames in cache prefixes and avoid unused/colliding helper imports.
|
|
37
|
+
- Honor empty artifact lists and provide per-function artifact selection.
|
|
38
|
+
- Load TypeScript/CommonJS configs and plugins with relative imports through Jiti; validate options and plugin contracts.
|
|
39
|
+
- Exclude output directories from source scans; support standard ignore globs; detect symlink and output collisions.
|
|
40
|
+
- Reconcile only owned stale files after a successful analysis, avoid unchanged writes, serialize watch passes and recover after errors.
|
|
41
|
+
- Wait for watcher readiness and reconcile startup edits before announcing that watch is active.
|
|
42
|
+
- Report generation failures with nonzero exit codes; add explicit config selection and read-only output checks.
|
|
43
|
+
|
|
44
|
+
### Maintenance
|
|
45
|
+
|
|
46
|
+
- Replace the Bun-only build with a Node/esbuild build; preserve a browser-safe runtime and NodeNext-compatible declarations.
|
|
47
|
+
- Use one npm lockfile; remove obsolete scripts, the fs placeholder dependency and Bun ambient types.
|
|
48
|
+
- Add runtime, CLI, emitted-code, type-inference and installed-package tests.
|
|
49
|
+
- Add Node 22/24 CI and pre-publish tests, consumer checks, tag/version validation and provenance.
|
|
50
|
+
- Rewrite Korean/English documentation with usage, limitations and migration steps.
|
package/README.md
CHANGED
|
@@ -1,418 +1,165 @@
|
|
|
1
1
|
<p align="center">
|
|
2
|
-
<
|
|
2
|
+
<picture>
|
|
3
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/uiwwsw/react-query-helper/main/assets/readme-hero-dark.svg" />
|
|
4
|
+
<img src="https://raw.githubusercontent.com/uiwwsw/react-query-helper/main/assets/readme-hero.svg" alt="React Query Helper logo" width="1120" />
|
|
5
|
+
</picture>
|
|
3
6
|
</p>
|
|
4
7
|
|
|
5
8
|
<h1 align="center">React Query Helper</h1>
|
|
6
9
|
|
|
7
10
|
<p align="center">
|
|
8
|
-
<
|
|
11
|
+
TypeScript API ํจ์ ํ์ผ์์ ์ฟผ๋ฆฌ ํค์ TanStack Query v5 ์ต์
ํฉํ ๋ฆฌ(<code>queryOptions</code>, <code>infiniteQueryOptions</code>, <code>mutationOptions</code> ํธ์ถ ์ฝ๋)๋ฅผ ์์ฑํ๋ CLI์ ๋ฐํ์ ํฌํผ์
๋๋ค.
|
|
9
12
|
</p>
|
|
10
13
|
|
|
11
14
|
<p align="center">
|
|
12
|
-
<a href="https://www.npmjs.com/package/@uiwwsw/react-query-helper"><img src="https://img.shields.io/npm/v/@uiwwsw/react-query-helper
|
|
13
|
-
<a href="https://
|
|
14
|
-
<a href="https://
|
|
15
|
-
<a href="https://
|
|
16
|
-
<a href="https://www.npmjs.com/package/@uiwwsw/react-query-helper"><img src="https://img.shields.io/
|
|
17
|
-
|
|
18
|
-
<p align="center">
|
|
19
|
-
<a href="https://github.com/uiwwsw/react-query-helper"><img src="https://img.shields.io/github/stars/uiwwsw/react-query-helper?style=social" alt="github stars" /></a>
|
|
15
|
+
<a href="https://www.npmjs.com/package/@uiwwsw/react-query-helper"><img src="https://img.shields.io/npm/v/@uiwwsw/react-query-helper?style=flat-square" alt="npm ๋ฒ์ " /></a>
|
|
16
|
+
<a href="https://github.com/uiwwsw/react-query-helper/blob/main/LICENSE"><img src="https://img.shields.io/npm/l/@uiwwsw/react-query-helper?style=flat-square" alt="๋ผ์ด์ ์ค" /></a>
|
|
17
|
+
<a href="https://github.com/uiwwsw/react-query-helper/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/uiwwsw/react-query-helper/ci.yml?branch=main&style=flat-square&label=CI" alt="main ๋ธ๋์น CI ์ํ" /></a>
|
|
18
|
+
<a href="https://tanstack.com/query"><img src="https://img.shields.io/npm/dependency-version/@uiwwsw/react-query-helper/peer/@tanstack/react-query?style=flat-square&label=TanStack%20Query" alt="TanStack Query peer ์์กด์ฑ ๋ฒ์" /></a>
|
|
19
|
+
<a href="https://www.npmjs.com/package/@uiwwsw/react-query-helper"><img src="https://img.shields.io/node/v/@uiwwsw/react-query-helper?style=flat-square" alt="Node.js ์๊ตฌ ๋ฒ์ " /></a>
|
|
20
|
+
<a href="https://www.npmjs.com/package/@uiwwsw/react-query-helper"><img src="https://img.shields.io/npm/types/@uiwwsw/react-query-helper?style=flat-square" alt="ํฌํจ๋ TypeScript ํ์
" /></a>
|
|
20
21
|
</p>
|
|
22
|
+
|
|
21
23
|
<p align="center">
|
|
22
|
-
<
|
|
23
|
-
<
|
|
24
|
+
<a href="https://react-query-helper.vercel.app/">๋ฐ๋ชจ</a> ยท
|
|
25
|
+
<a href="https://github.com/uiwwsw/react-query-helper/blob/main/docs/ARCHITECTURE.md">๊ตฌ์ฑ๊ณผ ์์กด์ฑ</a> ยท
|
|
26
|
+
<a href="https://www.npmjs.com/package/@uiwwsw/react-query-helper">npm</a> ยท
|
|
27
|
+
<a href="https://github.com/uiwwsw/react-query-helper/blob/main/CHANGELOG.md">๋ณ๊ฒฝ ์ด๋ ฅ</a> ยท
|
|
28
|
+
<a href="https://github.com/uiwwsw/react-query-helper/blob/main/README_EN.md">English</a>
|
|
24
29
|
</p>
|
|
25
30
|
|
|
26
|
-
>
|
|
27
|
-
|
|
28
|
-
๊ธฐ๋ณธ์ ์ผ๋ก ๊ฐ ํ์ผ์ `export`๋ ํจ์๋ง ์์ฑ ๋์์ผ๋ก ๋ถ์ํฉ๋๋ค.
|
|
29
|
-
|
|
30
|
-
---
|
|
31
|
-
|
|
32
|
-
## ๋ชฉ์ฐจ
|
|
33
|
-
|
|
34
|
-
- [์ฃผ์ ํน์ง](#์ฃผ์-ํน์ง)
|
|
35
|
-
- [๋น ๋ฅธ ์์](#๋น ๋ฅธ-์์)
|
|
36
|
-
- [์ค์น](#์ค์น)
|
|
37
|
-
- [์ด๊ธฐ ์ค์ ํ์ผ ์์ฑ](#์ด๊ธฐ-์ค์ -ํ์ผ-์์ฑ)
|
|
38
|
-
- [์ฝ๋ ์์ฑ ์คํ](#์ฝ๋-์์ฑ-์คํ)
|
|
39
|
-
- [CLI ๋ช
๋ น์ด](#cli-๋ช
๋ น์ด)
|
|
40
|
-
- [์ค์ ์ต์
](#์ค์ -์ต์
)
|
|
41
|
-
- [์์ฑ ๊ฒฐ๊ณผ ์์](#์์ฑ-๊ฒฐ๊ณผ-์์)
|
|
42
|
-
- [ํฌํผ ๊ฒฝ๋ก ์ปค์คํฐ๋ง์ด์ง](#ํฌํผ-๊ฒฝ๋ก-์ปค์คํฐ๋ง์ด์ง)
|
|
43
|
-
- [๋ฒ ์คํธ ํ๋ํฐ์ค](#๋ฒ ์คํธ-ํ๋ํฐ์ค)
|
|
44
|
-
- [์คํ ํ์คํ ๋ฆฌ](#์คํ-ํ์คํ ๋ฆฌ)
|
|
45
|
-
- [๊ธฐ์ฌ](#๊ธฐ์ฌ)
|
|
46
|
-
- [๋ผ์ด์ ์ค](#๋ผ์ด์ ์ค)
|
|
47
|
-
|
|
48
|
-
## ์ฃผ์ ํน์ง
|
|
49
|
-
|
|
50
|
-
- **์ค์ ๊ธฐ๋ฐ ์๋ํ**: `rqh.config.ts`๋ง ๊ตฌ์ฑํ๋ฉด API ๋๋ ํ ๋ฆฌ ๊ฐ์ง๋ถํฐ ์ถ๋ ฅ ๋๋ ํ ๋ฆฌ ์ง์ ๊น์ง ๋ชจ๋ ์๋ํ๋ฉ๋๋ค.
|
|
51
|
-
- **์ด๊ธฐํ ์ง์**: `react-query-helper --init`์ผ๋ก ๊ธฐ๋ณธ ์ค์ ํ์ผ์ ๋ฐ๋ก ์์ฑํ ์ ์์ต๋๋ค.
|
|
52
|
-
- **๋ฐํ์/๊ฐ๋ฐ ๋ถ๋ฆฌ**: generate/watch/config ๋ก๋ฉ์ ๊ฐ๋ฐ ์์ ์ ์ฉ์ด๊ณ , ์์ฑ๋ ๊ฒฐ๊ณผ๊ฐ ์ฐธ์กฐํ๋ ๋ฐํ์ helper ์ํธ๋ฆฌ์๋ `fs` ๊ฐ์ Node ์ ์ฉ ์ฝ๋๊ฐ ํฌํจ๋์ง ์๋๋ก ๋ถ๋ฆฌ๋์ด ์์ต๋๋ค.
|
|
53
|
-
- **Watch & Generate ๋ชจ๋**: ๊ฐ๋ฐ ์ค ์ค์๊ฐ ๊ฐ์(`--watch`), ์ด๊ธฐ ์ธํ
์ด๋ ์ฌ์์ฑ ์ ์ผ๊ด ์์ฑ(`--generate`)์ ๋ชจ๋ ์ง์ํฉ๋๋ค.
|
|
54
|
-
- **์ผ๊ด๋ ์ต์
๊ด๋ฆฌ**: `queryOption`, `mutationOption`, `infiniteOption` ์ ํธ๋ฆฌํฐ๋ก ์ ์ญ ์บ์ฑ ์ ๋ต๊ณผ ์๋ฌ ํธ๋ค๋ง์ ํต์ผํ ์ ์์ต๋๋ค.
|
|
55
|
-
- **๋ฐํ์ override ์ง์**: ์์ฑ๋ ์ต์
ํฉํ ๋ฆฌ์ `.withOptions(...)`๋ก ํค๋, queryKey, pageParam ๋งคํ, mutation ๋ณ์ ๋ณํ ๋ฑ์ ํธ์ถ๋ถ์์ ์์ ํ๊ฒ ์กฐ์ ํ ์ ์์ต๋๋ค.
|
|
56
|
-
- **Prettier ํตํฉ**: ์์ฑ๋ ํ์ผ์ ์๋์ผ๋ก ํฌ๋งทํ
๋์ด ์ฝ๋ ๋ฆฌ๋ทฐ ์ ๋ถํ์ํ ๋ณ๊ฒฝ์ ์ค์
๋๋ค.
|
|
57
|
-
- **ํฌํผ import ๊ฒฝ๋ก ์ปค์คํฐ๋ง์ด์ง**: `templateDir`๋ก ์์ฑ ์ฝ๋๊ฐ ์ฐธ์กฐํ ํฌํผ ๋ชจ๋ ๊ฒฝ๋ก๋ฅผ ๋ฐ๊ฟ ์ ์์ต๋๋ค.
|
|
58
|
-
- **์ค๋งํธ ์ํฐํฉํธ ์ถ๋ก **: ๊ธฐ๋ณธ๊ฐ์ผ๋ก ํจ์ ์ด๋ฆ์ ๋ณด๊ณ query / mutation / infinite ์์ฑ์ ๊ตฌ๋ถํด `createUserQueryOption` ๊ฐ์ ์ด์ํ ๊ฒฐ๊ณผ๋ฅผ ์ค์
๋๋ค.
|
|
59
|
-
- **๋ณด์์ ์ธ infinite ๊ธฐ๋ณธ๊ฐ**: `infiniteOption`์ ์์ ํ ๊ธฐ๋ณธ ์ต์
๋ง ์ ๊ณตํ๊ณ , ์ค์ `pageParam` ์ฒ๋ฆฌ ๊ท์น์ ํธ์ถ๋ถ์์ override ํ๋๋ก ์ค๊ณ๋์ด ์์ต๋๋ค.
|
|
60
|
-
|
|
61
|
-
## ๋น ๋ฅธ ์์
|
|
62
|
-
|
|
63
|
-
### ์ค์น
|
|
64
|
-
|
|
65
|
-
```bash
|
|
66
|
-
bun add @uiwwsw/react-query-helper
|
|
67
|
-
# ๋๋
|
|
68
|
-
npm install --save-dev @uiwwsw/react-query-helper
|
|
69
|
-
```
|
|
31
|
+
> **๋ฒ์ ์๋ด:** ์ด ๋ฌธ์๋ **2.x** ๊ธฐ์ค์
๋๋ค. ์ค์ ๊ฒ์ ๋ฒ์ ์ ์ npm ๋ฐฐ์ง์์ ํ์ธํ์ธ์. 1.x๋ฅผ ์ฌ์ฉ ์ค์ด๋ผ๋ฉด [1.3.0 ๋ฌธ์](https://github.com/uiwwsw/react-query-helper/blob/v1.3.0/README.md)์ [๋ง์ด๊ทธ๋ ์ด์
๊ฐ์ด๋](https://github.com/uiwwsw/react-query-helper/blob/main/docs/REFERENCE.md#1x์์-์ด์ )๋ฅผ ์ฐธ๊ณ ํ์ธ์. ์์ง ๊ฒ์๋์ง ์์ ๋ณ๊ฒฝ์ [์์ค์์ ์ค์น](https://github.com/uiwwsw/react-query-helper/blob/main/docs/REFERENCE.md#npm-๊ฒ์-์ -์์ค์์-์ค์นํ๊ธฐ)ํ ์ ์์ต๋๋ค.
|
|
70
32
|
|
|
71
|
-
|
|
33
|
+
TypeScript API ํจ์ ํ์ผ์ ์ฝ์ด ์ฟผ๋ฆฌ ํค์ TanStack Query v5 ์ต์
ํฉํ ๋ฆฌ(`queryOptions`, `infiniteQueryOptions`, `mutationOptions`๋ฅผ ํธ์ถํ๋ ์ฝ๋)๋ฅผ ์์ฑํ๋ CLI์ ๋ฐํ์ ํฌํผ์
๋๋ค. ์
๋ ฅ์ ์ด๋ฏธ ์๋ TypeScript ํจ์์
๋๋ค. OpenAPI ๋ช
์ธ๋ ์ฝ์ง ์์ต๋๋ค. ์ ์์๋ ํ ๋ช
์ด๊ณ , ์์ง ๋๋ฆฌ ์ฐ์ด์ง ์์ต๋๋ค.
|
|
72
34
|
|
|
73
|
-
|
|
35
|
+
## ์ง๊ธ ๋๋ ๊ฒ
|
|
74
36
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
37
|
+
- `generate`: `sourceDir`์ ์ต์์ ํจ์๋ง๋ค ํค ์์์ query, infinite query, mutation ์ต์
ํฉํ ๋ฆฌ๋ฅผ `*Options.ts`๋ก ์์ฑํฉ๋๋ค.
|
|
38
|
+
- ํค๋ ์์ค ๊ฒฝ๋ก์ ๋๋ ํ ๋ฆฌ, ํ์ผ๋ช
, ํจ์๋ช
์ผ๋ก ๋ง๋ญ๋๋ค.
|
|
39
|
+
- ํจ์ ์ด๋ฆ ์ ๋์ฌ(`get`, `list`, `create` ๋ฑ)๋ก ์์ฑ ์ข
๋ฅ๋ฅผ ๊ณ ๋ฆ
๋๋ค. ์ค์ ์ผ๋ก ๋ฐ๊ฟ ์ ์์ต๋๋ค.
|
|
40
|
+
- ์ธ์๊ฐ ๋ ์ด์์ธ ํจ์์ mutation์ ๋ณ์ ๊ฐ์ฒด ํ์
๊ณผ `mapVariablesToArgs`๋ฅผ ์์ฑํฉ๋๋ค.
|
|
41
|
+
- `withOptions`๋ก `staleTime`, `select` ๋ฑ์ ๋ฎ์ด์ฐ๊ณ , ์ธ์ยท๋ฐํยท`select` ๊ฒฐ๊ณผ ํ์
์ด ์ถ๋ก ๋ฉ๋๋ค.
|
|
42
|
+
- `generate --check`: ํ์ผ์ ์ฐ์ง ์๊ณ ๋๋ฝยท๋ณ๊ฒฝยท์ค๋๋ ๊ฒฐ๊ณผ๊ฐ ์์ผ๋ฉด ์ข
๋ฃ ์ฝ๋ 1์ ๋ฐํํฉ๋๋ค.
|
|
43
|
+
- `watch`: ์์ค, ์ค์ ํ์ผ, ์ง์ ํ ๋ก์ปฌ ํ๋ฌ๊ทธ์ธ์ด ๋ฐ๋๋ฉด ๋ค์ ์์ฑํฉ๋๋ค.
|
|
44
|
+
- ์์ฑ ํ์ผ ์ฒซ ์ค์ ์์ ํ์๋ก ๊ตฌ๋ถํด, ํ์ ์๋ ๊ธฐ์กด ํ์ผ์ ๋ฎ์ด์ฐ์ง ์๊ณ ์ค๋ฅ๋ก ์ฒ๋ฆฌํฉ๋๋ค.
|
|
45
|
+
- `customAnalyzerPath`, `customTemplatePath`๋ก ๋ถ์๊ธฐ์ ํ
ํ๋ฆฟ์ ๊ต์ฒดํ ์ ์์ต๋๋ค.
|
|
80
46
|
|
|
81
|
-
|
|
47
|
+
## ์์ง ์ ๋๋ ๊ฒ / ์งํ ์์
|
|
82
48
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
49
|
+
- OpenAPI, Swagger ๋ฑ ๋ช
์ธ ํ์ผ ์ฝ๊ธฐ.
|
|
50
|
+
- ํ
์์ฑ. `useQuery` ๋ฑ์ TanStack Query์ ๊ฒ์ ์ง์ ํธ์ถํฉ๋๋ค.
|
|
51
|
+
- HTTP ํด๋ผ์ด์ธํธ ์์ฑ. ๊ธฐ์กด API ํจ์๋ฅผ ๊ทธ๋๋ก ํธ์ถํฉ๋๋ค.
|
|
52
|
+
- React ์ธ ํด๋ผ์ด์ธํธ(Vue, Svelte, Solid ๋ฑ). TanStack Query v5 React๋ง ๋์์
๋๋ค.
|
|
53
|
+
- ๋ชฉ(mock) ์์ฑ.
|
|
54
|
+
- ํ์ด์ง๋ค์ด์
์ปค์์ `AbortSignal` ์ ๋ฌ์ ์๋ ์ถ์ธก. API๋ง๋ค ์ง์ ์ค์ ํฉ๋๋ค.
|
|
55
|
+
- re-export barrel, ํด๋์คยท๊ฐ์ฒด ๋ฉ์๋, ๊ณ ์ฐจ ํจ์๊ฐ ๋ฐํํ ํจ์ ๋ถ์.
|
|
56
|
+
- ๋ชจ๋ generic/overload ๊ด๊ณ๋ฅผ ์ต์
ํฉํ ๋ฆฌ ํ์
์ผ๋ก ๋ณด์กดํ๋ ๋ณํ.
|
|
57
|
+
- ํจ์ ์ด๋ฆ๋ง์ผ๋ก HTTP ์๋ฏธ๋ฅผ ํ๋จํ๋ ๊ฒ. ์ ๋์ฌ ๊ท์น์ ๋ง์ง ์์ผ๋ฉด `artifactsByName`์ผ๋ก ์ง์ ํฉ๋๋ค.
|
|
58
|
+
- `watch`๊ฐ ์ค์ ์ด importํ๋ ์ธ๋ถ ํ์ผ์ ๋ณ๊ฒฝ์ ๊ฐ์งํ๋ ๊ฒ. ์ฌ์์์ด ํ์ํฉ๋๋ค.
|
|
59
|
+
- ๋๋ ํ ๋ฆฌ ์ ์ฒด ๋จ์์ ํธ๋์ญ์
. ํ์ผ ๋จ์๋ก๋ง ์์์ ์ผ๋ก ์๋๋ค.
|
|
60
|
+
- ์์ฑ ํ์ผ์ Node ESM์์ ์ง์ ์คํํ๋ ๊ฒ. TS ๋ฒ๋ค๋ฌ์ฉ์
๋๋ค.
|
|
61
|
+
- ํ์ ์๋ 1.x ์์ฑ ํ์ผ์ ์๋ ์ด์ . ์๋์ผ๋ก ์ฎ๊ฒจ์ผ ํฉ๋๋ค.
|
|
88
62
|
|
|
89
|
-
|
|
63
|
+
## ํ์ฌ ์์น
|
|
90
64
|
|
|
91
|
-
|
|
92
|
-
// rqh.config.ts
|
|
93
|
-
import type { AutoQueryConfig } from "@uiwwsw/react-query-helper/config";
|
|
65
|
+
์ฃผ๊ฐ npm ๋ค์ด๋ก๋(์ต๊ทผ 1์ฃผ, api.npmjs.org ๊ธฐ์ค):
|
|
94
66
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
functionMatchMode: "all",
|
|
104
|
-
includeNames: [],
|
|
105
|
-
excludeNames: [],
|
|
106
|
-
},
|
|
107
|
-
template: {
|
|
108
|
-
enabledArtifacts: ["query", "mutation", "infinite"],
|
|
109
|
-
artifactStrategy: "smart",
|
|
110
|
-
keyStyle: "path",
|
|
111
|
-
},
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
export default config;
|
|
115
|
-
```
|
|
67
|
+
| ํจํค์ง | ๋ค์ด๋ก๋ |
|
|
68
|
+
| --------------------------------------- | ------------: |
|
|
69
|
+
| `@hey-api/openapi-ts` | 8,305,092 |
|
|
70
|
+
| `orval` | 4,328,761 |
|
|
71
|
+
| `openapi-react-query` | 956,262 |
|
|
72
|
+
| `@lukemorales/query-key-factory` | 493,363 |
|
|
73
|
+
| `@kubb/plugin-react-query` | 140,067 |
|
|
74
|
+
| `@uiwwsw/react-query-helper` (์ด ํจํค์ง) | 202 |
|
|
116
75
|
|
|
117
|
-
|
|
76
|
+
- ์ฌ์ฉ์๊ฐ ์ฌ์ค์ ์์ต๋๋ค. ๊ด๋ฆฌ์๋ ํ ๋ช
์
๋๋ค. ์ ๋๊ตฌ๋ค๊ณผ ๋น๊ตํ ๋งํ ์ฑํ ์ฌ๋ก๊ฐ ์์ต๋๋ค.
|
|
77
|
+
- ๊ท๋ชจ๊ฐ ํฐ ๋๊ตฌ๋ OpenAPI ๋ช
์ธ์์ ํ์
, ํด๋ผ์ด์ธํธ, ํ
, ์ฌ๋ฌ ํ๋ ์์ํฌ์ฉ ์ถ๋ ฅ, ๋ชฉ๊น์ง ๋ง๋ญ๋๋ค. ์ด ํจํค์ง๋ ๊ทธ์ค ์ด๋ ๊ฒ๋ ํ์ง ์์ต๋๋ค.
|
|
78
|
+
- OpenAPI ๋ช
์ธ๊ฐ ์์ผ๋ฉด ์ ๋๊ตฌ๋ฅผ ์ฐ๋ ๊ฒ์ด ๋ง์ต๋๋ค.
|
|
79
|
+
- ์ด ํจํค์ง๊ฐ ๋ง๋ ๊ฒฝ์ฐ๋ ํ๋์
๋๋ค. ๋ช
์ธ ์์ด ์์ผ๋ก ์ด TypeScript API ํจ์๊ฐ ์๊ณ , ๊ทธ ํจ์์์ ํค์ ์ต์
ํฉํ ๋ฆฌ๋ฅผ ๋ง๋ค๊ณ ์ถ์ ๋์
๋๋ค.
|
|
80
|
+
- `@lukemorales/query-key-factory`๋ ํค๋ง ๋ค๋ฃจ๊ณ , ํค ๊ตฌ์กฐ๋ฅผ ์์ผ๋ก ์ ์ธํฉ๋๋ค. ์ด ํจํค์ง๋ ํค์ ์ต์
ํฉํ ๋ฆฌ๋ฅผ ํ์ผ ๊ฒฝ๋ก์ ํจ์๋ช
์์ ์์ฑํฉ๋๋ค.
|
|
81
|
+
- ์ฟผ๋ฆฌ๊ฐ ๋ช ๊ฐ๋ฟ์ด๋ฉด `queryOptions`๋ฅผ ์ง์ ์ฐ๋ ํธ์ด ๋จ์ํฉ๋๋ค. ๋น๊ต๋ [๊ตฌ์ฑ๊ณผ ์์กด์ฑ](docs/ARCHITECTURE.md#๋น์ทํ-๋๊ตฌ)์ ์์ต๋๋ค.
|
|
118
82
|
|
|
119
|
-
|
|
83
|
+
<a id="quick-start"></a>
|
|
120
84
|
|
|
121
|
-
|
|
122
|
-
// package.json
|
|
123
|
-
{
|
|
124
|
-
"scripts": {
|
|
125
|
-
"init:rqh": "react-query-helper --init",
|
|
126
|
-
"watch": "react-query-helper --watch",
|
|
127
|
-
"generate": "react-query-helper --generate"
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
```
|
|
85
|
+
## ์ค์น์ ์ฌ์ฉ
|
|
131
86
|
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
# ๋๋
|
|
136
|
-
npm exec react-query-helper -- --generate
|
|
87
|
+
```sh
|
|
88
|
+
npm install @uiwwsw/react-query-helper@^2 @tanstack/react-query react
|
|
89
|
+
npx @uiwwsw/react-query-helper init
|
|
137
90
|
```
|
|
138
91
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
| ๋ช
๋ น์ด | ์ค๋ช
|
|
|
142
|
-
| --- | --- |
|
|
143
|
-
| `react-query-helper --init` | ๋ฃจํธ์ ๊ธฐ๋ณธ `rqh.config.ts` ํ์ผ์ ์์ฑํฉ๋๋ค. ์ด๋ฏธ ์์ผ๋ฉด ๋ฎ์ด์ฐ์ง ์์ต๋๋ค. |
|
|
144
|
-
| `react-query-helper --watch` | `sourceDir`๋ฅผ ๊ฐ์ํ์ฌ ๋ณ๊ฒฝ๋ ๋๋ง๋ค ์ฝ๋๋ฅผ ๊ฐฑ์ ํฉ๋๋ค. |
|
|
145
|
-
| `react-query-helper --generate` | `sourceDir` ๋ด ๋ชจ๋ API ํ์ผ์ ๋ถ์ํ๊ณ ํ ๋ฒ์ ์ฝ๋๋ฅผ ์์ฑํฉ๋๋ค. |
|
|
146
|
-
| `react-query-helper --help` | ์ฌ์ฉ ๊ฐ๋ฅํ ๋ชจ๋ ์ต์
์ ํ์ธํฉ๋๋ค. |
|
|
147
|
-
|
|
148
|
-
## ์ค์ ์ต์
|
|
149
|
-
|
|
150
|
-
| ์ต์
| ํ์ | ์ค๋ช
|
|
|
151
|
-
| --- | --- | --- |
|
|
152
|
-
| `sourceDir` | โ
| API ํจ์๊ฐ ํฌํจ๋ TypeScript ๋๋ ํ ๋ฆฌ (๋ฃจํธ ๊ธฐ์ค ๊ฒฝ๋ก) |
|
|
153
|
-
| `outputDir` | โ
| ์์ฑ๋ ํ
๊ณผ ์ต์
ํ์ผ์ด ์ ์ฅ๋ ๋๋ ํ ๋ฆฌ |
|
|
154
|
-
| `ignoredFiles` | โ | ์ฝ๋ ์์ฑ์์ ์ ์ธํ ํ์ผ/๊ฒฝ๋ก ํจํด ๋ฐฐ์ด (`domain.ts`, `**/*.spec.ts`, `admin/internal/**`) |
|
|
155
|
-
| `templateDir` | โ | ์์ฑ๋ ์ฝ๋์์ `queryOption` ๊ณ์ด์ import ํ ๋ชจ๋ ๊ฒฝ๋ก ๋๋ ์๋ ๋๋ ํ ๋ฆฌ |
|
|
156
|
-
| `sourceImportAlias` | โ | API ํจ์ import๋ฅผ ์๋๊ฒฝ๋ก ๋์ alias๋ก ์์ฑํ ๋ ์ฌ์ฉํ prefix (`@/apis` ๋ฑ) |
|
|
157
|
-
| `analyzer` | โ | ์ด๋ค ํจ์๋ฅผ ์ฝ์์ง ํํฐ๋งํ๋ ์ค์ (`exported-only`, `async-only`, include/exclude ๋ฑ) |
|
|
158
|
-
| `template` | โ | ์ด๋ค ์ํฐํฉํธ๋ฅผ ์์ฑํ ์ง์ ์ด๋ฆ ๊ท์น์ ์ ์ดํ๋ ์ค์ |
|
|
159
|
-
|
|
160
|
-
### ์ค๋งํธ ์์ฑ ๊ท์น
|
|
161
|
-
|
|
162
|
-
๊ธฐ๋ณธ `artifactStrategy: "smart"`๋ ํจ์ ์ด๋ฆ์ ๋ณด๊ณ ์์ฑ ๋์์ ์ถ๋ก ํฉ๋๋ค.
|
|
163
|
-
|
|
164
|
-
- `getUsers`, `fetchPost`, `listComments` โ `query` + `infinite`
|
|
165
|
-
- `createUser`, `updateProfile`, `deleteComment` โ `mutation`
|
|
166
|
-
- ๊ทธ ์ธ ์ ๋งคํ ์ด๋ฆ โ `query` + `mutation` (`infinite` ์ ์ธ)
|
|
167
|
-
|
|
168
|
-
์ํ๋ค๋ฉด `artifactStrategy: "all"`๋ก ์์ ์ฒ๋ผ ๋ชจ๋ ์ํฐํฉํธ๋ฅผ ๊ฐ์ ๋ก ์์ฑํ ์ ์์ต๋๋ค.
|
|
169
|
-
|
|
170
|
-
## Infinite Query ๊ธฐ๋ณธ๊ฐ
|
|
171
|
-
|
|
172
|
-
`infiniteOption`์ API๋ง๋ค ํ์ด์ง๋ค์ด์
๊ท์น์ด ๋ค๋ฅด๊ธฐ ๋๋ฌธ์, ๊ธฐ๋ณธ ๊ตฌํ์์๋ `pageParam`์ ์๋ ๋ณํฉํ์ง ์์ต๋๋ค.
|
|
173
|
-
|
|
174
|
-
ํ์ํ ๊ฒฝ์ฐ ์์ฑ๋ ์ต์
์ ํผ์น ๋ค `queryFn`, `getNextPageParam`, `initialPageParam`์ ์ง์ override ํด์ ์ฌ์ฉํ์ธ์.
|
|
175
|
-
|
|
176
|
-
```ts
|
|
177
|
-
const usersInfinite = {
|
|
178
|
-
...getUsersInfiniteQueryOption({ page: 1 }),
|
|
179
|
-
initialPageParam: 1,
|
|
180
|
-
queryFn: ({ pageParam }) => getUsers({ page: pageParam }),
|
|
181
|
-
getNextPageParam: (lastPage) => lastPage.nextPage,
|
|
182
|
-
};
|
|
183
|
-
```
|
|
184
|
-
|
|
185
|
-
๋ ๋ณต์กํ ์ผ์ด์ค์์๋ `.withOptions(...)`๋ฅผ ์ฐ๋ฉด ํค๋๋ `pageParam` ๋งคํ๋ ํ ๊ณณ์์ ์ฒ๋ฆฌํ ์ ์์ต๋๋ค.
|
|
186
|
-
|
|
187
|
-
```ts
|
|
188
|
-
const usersInfinite = getUsersInfiniteQueryOption.withOptions(
|
|
189
|
-
{
|
|
190
|
-
initialPageParam: 1,
|
|
191
|
-
pageParamToArgs: (pageParam, [params]) => [{
|
|
192
|
-
...params,
|
|
193
|
-
page: pageParam,
|
|
194
|
-
headers: {
|
|
195
|
-
...params.headers,
|
|
196
|
-
Authorization: `Bearer ${token}`,
|
|
197
|
-
},
|
|
198
|
-
}],
|
|
199
|
-
getNextPageParam: (lastPage) => lastPage.nextPage,
|
|
200
|
-
},
|
|
201
|
-
{ page: 1, headers: {} }
|
|
202
|
-
);
|
|
203
|
-
```
|
|
204
|
-
|
|
205
|
-
Mutation๋ ํธ์ถ ๋ฐฉ์์ ๋ฐ๋ผ ์์ฐ์ค๋ฝ๊ฒ ๋ง์ถฐ์ง๋๋ค.
|
|
206
|
-
|
|
207
|
-
- API ํจ์๊ฐ ์ธ์ 1๊ฐ๋ฉด ๊ธฐ์กด์ฒ๋ผ `mutate(body)` / `mutateAsync(body)`
|
|
208
|
-
- API ํจ์๊ฐ ์ธ์ ์ฌ๋ฌ ๊ฐ๋ฉด ์์ฑ ์ฝ๋๊ฐ object payload ํ์
์ ๋ง๋ค์ด `mutate({ body, headers })` / `mutateAsync({ body, headers })`
|
|
209
|
-
|
|
210
|
-
๊ฐ๋จํ ์ปค์คํ
๋งคํ์ด ํ์ํ๋ฉด `withOptions(...)`๋ก๋ ์ฐ๊ฒฐํ ์ ์์ต๋๋ค.
|
|
92
|
+
์์ฑ ์ฝ๋๊ฐ ์ด ํจํค์ง๋ฅผ importํ๋ฏ๋ก ์ผ๋ฐ dependency๋ก ์ค์นํฉ๋๋ค(`-D` ์ฌ์ฉ ๊ธ์ง).
|
|
211
93
|
|
|
212
94
|
```ts
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
id,
|
|
216
|
-
body,
|
|
217
|
-
{ Authorization: `Bearer ${token}` },
|
|
218
|
-
],
|
|
219
|
-
});
|
|
220
|
-
```
|
|
221
|
-
|
|
222
|
-
API ํจ์๊ฐ ์ฌ๋ฌ ์ธ์๋ฅผ ๋ฐ์ผ๋ฉด, ์์ฑ ์ฝ๋๊ฐ `mutate` / `mutateAsync`์์ ๋ฐ๋ก ์ฐ๊ธฐ ์ข์ object payload ํ์
๋ ํจ๊ป ๋ง๋ค์ด ์ค๋๋ค.
|
|
223
|
-
|
|
224
|
-
```ts
|
|
225
|
-
export type createUserMutationVariables = {
|
|
226
|
-
body: Parameters<typeof createUser>[0];
|
|
227
|
-
headers: Parameters<typeof createUser>[1];
|
|
228
|
-
};
|
|
229
|
-
|
|
230
|
-
export const createUserMutationOption = mutationOption<
|
|
231
|
-
Parameters<typeof createUser>,
|
|
232
|
-
Awaited<ReturnType<typeof createUser>>,
|
|
233
|
-
createUserMutationVariables
|
|
234
|
-
>(createUserKey, createUser, {
|
|
235
|
-
mapVariablesToArgs: (variables) => [variables.body, variables.headers],
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
mutate({
|
|
239
|
-
body: { name: "matthew" },
|
|
240
|
-
headers: { Authorization: `Bearer ${token}` },
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
await mutateAsync({
|
|
244
|
-
body: { name: "matthew" },
|
|
245
|
-
headers: { Authorization: `Bearer ${token}` },
|
|
246
|
-
});
|
|
247
|
-
```
|
|
248
|
-
|
|
249
|
-
## ๋ฐฐํฌ ๋ฐฉ์
|
|
250
|
-
|
|
251
|
-
GitHub Actions์ npm ๋ฐฐํฌ๋ ์ด์ `main` ํธ์๊ฐ ์๋๋ผ `v*` ํ๊ทธ ํธ์ ๋๋ ์๋ ์คํ์์๋ง ๋์ํฉ๋๋ค.
|
|
252
|
-
|
|
253
|
-
์์:
|
|
95
|
+
// rqh.config.ts
|
|
96
|
+
import type { AutoQueryConfig } from "@uiwwsw/react-query-helper/config";
|
|
254
97
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
98
|
+
export default {
|
|
99
|
+
sourceDir: "./libs",
|
|
100
|
+
outputDir: "./src/options",
|
|
101
|
+
template: { artifactStrategy: "smart" },
|
|
102
|
+
} satisfies AutoQueryConfig;
|
|
258
103
|
```
|
|
259
104
|
|
|
260
|
-
## ์์ฑ ๊ฒฐ๊ณผ ์์
|
|
261
|
-
|
|
262
105
|
```ts
|
|
263
106
|
// libs/users/api.ts
|
|
264
|
-
export const getUser = async (id: string) => {
|
|
265
|
-
return { id, name: `User ${id}` };
|
|
266
|
-
};
|
|
267
|
-
|
|
268
|
-
export const createUser = async (
|
|
269
|
-
body: { name: string },
|
|
270
|
-
headers?: Record<string, string>
|
|
271
|
-
) => {
|
|
272
|
-
return { id: Date.now().toString(), name: body.name, headers };
|
|
273
|
-
};
|
|
107
|
+
export const getUser = async (id: string) => ({ id, name: "Ada" });
|
|
274
108
|
```
|
|
275
109
|
|
|
110
|
+
`npx @uiwwsw/react-query-helper generate`๋ฅผ ์คํํ๋ฉด `src/options/users/apiOptions.ts`๊ฐ ์์ฑ๋ฉ๋๋ค.
|
|
111
|
+
|
|
276
112
|
```ts
|
|
277
|
-
//
|
|
278
|
-
|
|
113
|
+
// Generated by @uiwwsw/react-query-helper. DO NOT EDIT.
|
|
114
|
+
// Source root: "../../libs"
|
|
115
|
+
import { getUser } from "../../../libs/users/api";
|
|
279
116
|
import {
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
queryOption,
|
|
117
|
+
queryOption as __rqh_query,
|
|
118
|
+
infiniteOption as __rqh_infinite,
|
|
283
119
|
} from "@uiwwsw/react-query-helper";
|
|
284
120
|
|
|
285
|
-
export const getUserKey = ["users", "getUser"] as const;
|
|
286
|
-
export const getUserQueryOption =
|
|
287
|
-
export const getUserInfiniteQueryOption =
|
|
288
|
-
|
|
289
|
-
export const createUserKey = ["users", "createUser"] as const;
|
|
290
|
-
export type createUserMutationVariables = {
|
|
291
|
-
body: Parameters<typeof createUser>[0];
|
|
292
|
-
headers: Parameters<typeof createUser>[1];
|
|
293
|
-
};
|
|
294
|
-
|
|
295
|
-
export const createUserMutationOption = mutationOption<
|
|
296
|
-
Parameters<typeof createUser>,
|
|
297
|
-
Awaited<ReturnType<typeof createUser>>,
|
|
298
|
-
createUserMutationVariables
|
|
299
|
-
>(
|
|
300
|
-
createUserKey,
|
|
301
|
-
createUser,
|
|
302
|
-
{
|
|
303
|
-
mapVariablesToArgs: (variables) => [variables.body, variables.headers],
|
|
304
|
-
}
|
|
305
|
-
);
|
|
121
|
+
export const getUserKey = ["users", "api", "getUser"] as const;
|
|
122
|
+
export const getUserQueryOption = __rqh_query(getUserKey, getUser);
|
|
123
|
+
export const getUserInfiniteQueryOption = __rqh_infinite(getUserKey, getUser);
|
|
306
124
|
```
|
|
307
125
|
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
์กฐ์ง ๊ณต์ฉ ํฌํผ๋ฅผ ๋ฐ๋ก ๋๊ณ ์๋ค๋ฉด `templateDir`๋ก ์์ฑ ์ฝ๋์ import ๊ฒฝ๋ก๋ฅผ ๋ฐ๊ฟ ์ ์์ต๋๋ค.
|
|
311
|
-
|
|
312
|
-
๋ํ `template` / `analyzer` ์ค์ ์ผ๋ก ํ์ฌ ํ ๊ตฌ์กฐ์ ๋ง๊ฒ ์์ฑ ๊ท์น์ ๋ฐ๊ฟ ์ ์์ต๋๋ค.
|
|
313
|
-
|
|
314
|
-
```ts
|
|
315
|
-
const config: AutoQueryConfig = {
|
|
316
|
-
sourceDir: "./libs",
|
|
317
|
-
outputDir: "./src/options",
|
|
318
|
-
analyzer: {
|
|
319
|
-
functionMatchMode: "async-only",
|
|
320
|
-
excludeNames: ["debugHelper"],
|
|
321
|
-
},
|
|
322
|
-
template: {
|
|
323
|
-
enabledArtifacts: ["query"],
|
|
324
|
-
keyStyle: "function-only",
|
|
325
|
-
outputNames: {
|
|
326
|
-
query: "CustomQueryOption",
|
|
327
|
-
},
|
|
328
|
-
},
|
|
329
|
-
};
|
|
330
|
-
```
|
|
331
|
-
|
|
332
|
-
๋ ๊ฐํ๊ฒ ์ปค์คํฐ๋ง์ด์งํ๋ ค๋ฉด ์ธ๋ถ ๋ชจ๋๋ ์ฐ๊ฒฐํ ์ ์์ต๋๋ค.
|
|
333
|
-
|
|
334
|
-
```ts
|
|
335
|
-
const config: AutoQueryConfig = {
|
|
336
|
-
sourceDir: "./libs",
|
|
337
|
-
outputDir: "./src/options",
|
|
338
|
-
customAnalyzerPath: "./rqh.analyzer.mjs",
|
|
339
|
-
customTemplatePath: "./rqh.template.mjs",
|
|
340
|
-
};
|
|
341
|
-
```
|
|
126
|
+
์์ฑ ํ์ผ์ ์์ ํ์ง ์์ต๋๋ค. ๊ณ ์น ๋๋ ์๋ณธ API๋ฅผ ์์ ํฉ๋๋ค. ์ฌ์ฉ:
|
|
342
127
|
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
```js
|
|
349
|
-
export function analyzeFile(filePath, config) {
|
|
350
|
-
// ์ฌ๊ธฐ์ AST๋ฅผ ์ง์ ํ์ฑํ๊ฑฐ๋,
|
|
351
|
-
// ํ์ผ๋ช
๊ท์น / ํจ์๋ช
๊ท์น์ ์์ ๋กญ๊ฒ ์ ์ฉํ ์ ์์ต๋๋ค.
|
|
352
|
-
return [
|
|
353
|
-
{
|
|
354
|
-
name: "getUser",
|
|
355
|
-
parameters: ["params"],
|
|
356
|
-
isAsync: true,
|
|
357
|
-
isExported: true,
|
|
358
|
-
},
|
|
359
|
-
];
|
|
360
|
-
}
|
|
361
|
-
```
|
|
128
|
+
```tsx
|
|
129
|
+
// src/UserName.tsx
|
|
130
|
+
import { useQuery } from "@tanstack/react-query";
|
|
131
|
+
import { getUserQueryOption } from "./options/users/apiOptions";
|
|
362
132
|
|
|
363
|
-
|
|
133
|
+
export function UserName({ id }: { id: string }) {
|
|
134
|
+
const user = useQuery(
|
|
135
|
+
getUserQueryOption.withOptions(
|
|
136
|
+
{ staleTime: 60_000, select: (data) => data.name },
|
|
137
|
+
id,
|
|
138
|
+
),
|
|
139
|
+
);
|
|
364
140
|
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
return `import { ${names} } from "${importPath}";\nexport const customGenerated = true;\n`;
|
|
141
|
+
if (user.isPending) return <p>Loading...</p>;
|
|
142
|
+
if (user.isError) return <p>{user.error.message}</p>;
|
|
143
|
+
return <p>{user.data}</p>;
|
|
369
144
|
}
|
|
370
145
|
```
|
|
371
146
|
|
|
372
|
-
์ธ์ custom analyzer๋ฅผ ์ฐ๋ฉด ๋๋๋ฉด:
|
|
373
|
-
- built-in analyzer ์ค์ ๋ง์ผ๋ก ์ถฉ๋ถํ ๊ฒฝ์ฐ
|
|
374
|
-
- `exported-only`, `async-only`, ์ด๋ฆ include/exclude, ์ํฐํฉํธ on/off ์ ๋
|
|
375
|
-
- custom analyzer๊ฐ ํ์ํ ๊ฒฝ์ฐ
|
|
376
|
-
- ํจ์ ์ ์ธ์ด ๋ํ๋์ด ์๊ฑฐ๋
|
|
377
|
-
- factory/higher-order ๊ตฌ์กฐ๋ฅผ ์ฐ๊ฑฐ๋
|
|
378
|
-
- ํ ์ ์ฉ ๊ท์น์ผ๋ก ํจ์ ํ๋ณด๋ฅผ ๋ฝ์์ผ ํ๊ฑฐ๋
|
|
379
|
-
- ๊ธฐ๋ณธ AST ๊ท์น๋ณด๋ค ๋ ๋ณต์กํ generic ํจํด์ ๊ฐ์ ํ๊ณ ์ถ์ ๋
|
|
380
|
-
|
|
381
|
-
์ฆ ์ด์ ๋ ๊ธฐ๋ณธ ๊ท์น์ ์กฐ๊ธ ๋ฐ๊พธ๋ ์์ค์ด ์๋๋ผ, ํ ์ ์ฉ ์์ฑ๊ธฐ์ฒ๋ผ ํ์ฅํ ์ ์์ต๋๋ค.
|
|
382
|
-
|
|
383
|
-
```ts
|
|
384
|
-
const config: AutoQueryConfig = {
|
|
385
|
-
sourceDir: "./libs",
|
|
386
|
-
outputDir: "./src/options",
|
|
387
|
-
templateDir: "./src/query-helpers",
|
|
388
|
-
};
|
|
389
|
-
```
|
|
390
|
-
|
|
391
|
-
์๋ฅผ ๋ค์ด ์์ฑ ํ์ผ์ ๊ธฐ๋ณธ ํจํค์ง ๋์ ์๋์ฒ๋ผ ์ง์ ํ ๊ฒฝ๋ก๋ฅผ import ํ๊ฒ ๋ฉ๋๋ค.
|
|
392
|
-
|
|
393
147
|
```ts
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
} from "./src/query-helpers";
|
|
148
|
+
// ๊ธฐ์กด QueryClient ์ธ์คํด์ค client์์
|
|
149
|
+
await client.prefetchQuery(getUserQueryOption("u1"));
|
|
150
|
+
const cached = client.getQueryData(getUserQueryOption("u1").queryKey);
|
|
151
|
+
// { id: string; name: string } | undefined
|
|
399
152
|
```
|
|
400
153
|
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
- **ํ๋์ API = ํ๋์ ํ
** ๊ตฌ์กฐ๋ฅผ ์ ์งํ๋ฉด ์บ์ ํค ๊ด๋ฆฌ๊ฐ ์ฌ์์ง๋๋ค.
|
|
404
|
-
- ์์ฑ๋ ํ์ผ์ ๋ฒ์ ๊ด๋ฆฌ ์์คํ
(Git)์ ์ปค๋ฐํ์ฌ ๋ฐฐํฌ ์ ์๋ ์์ฑ ๊ณผ์ ์ ํผํ์ธ์.
|
|
405
|
-
- `queryOption` ์ ํธ ํจ์์์ ๊ธ๋ก๋ฒ ์ต์
(`staleTime`, `retry`, `refetchOnWindowFocus`)์ ์ ์ํ๋ฉด ํ ์ ์ฒด ๊ท์น์ ์์ฝ๊ฒ ํต์ผํ ์ ์์ต๋๋ค.
|
|
406
|
-
- Watch ๋ชจ๋ ์ฌ์ฉ ์ IDE ์ ์ฅ ํฌ๋งทํฐ์ ์ถฉ๋์ด ์๋๋ก ์ ์ฅ ์์ ํฌ๋งทํ
์ ๋ง์ถฐ ์ฃผ์ธ์.
|
|
407
|
-
|
|
408
|
-
## ์คํ ํ์คํ ๋ฆฌ
|
|
409
|
-
|
|
410
|
-
[](https://star-history.com/#uiwwsw/react-query-helper&Date)
|
|
154
|
+
API ์ธ์๋ ์บ์ ํค์ ํฌํจ๋ฉ๋๋ค. ํ ํฐ์ด๋ ์ธ์ฆ ํค๋๋ฅผ ์ธ์๋ก ๋๊ธฐ์ง ๋ง์ธ์.
|
|
411
155
|
|
|
412
|
-
##
|
|
156
|
+
## ๋ฌธ์
|
|
413
157
|
|
|
414
|
-
|
|
158
|
+
- [์ค์ ๊ณผ ์ฌ์ฉ ๊ฐ์ด๋](docs/REFERENCE.md): CLI, ์ค์ , ์์ฑ ๊ท์น, ๋ฐํ์ ์ต์
, ๋ฌดํ ์ฟผ๋ฆฌ, 1.x ์ด์
|
|
159
|
+
- [README์์ ์ฎ๊ธด ์์ธ](docs/GUIDE.md): ์ ์ฒด ๊ธฐ๋ฅ ๋ชฉ๋ก, ์ค์น ๋จ๊ณ๋ณ ์ค๋ช
, ์์ ์ฐพ๊ธฐ ํ, ์ง์ ํ๊ฒฝ, ์์กด์ฑ, ๋ฐ๋ชจ
|
|
160
|
+
- [๊ตฌ์ฑ๊ณผ ์์กด์ฑ](docs/ARCHITECTURE.md): ๋ชจ๋ ๊ตฌ์กฐ, ๋น์ทํ ๋๊ตฌ์์ ๋น๊ต
|
|
161
|
+
- [์ ์ฅ์ ๊ฒํ ๊ธฐ๋ก](docs/REVIEW.md) ยท [๋ณ๊ฒฝ ์ด๋ ฅ](CHANGELOG.md) ยท [๋ฐ๋ชจ](https://react-query-helper.vercel.app/)
|
|
415
162
|
|
|
416
163
|
## ๋ผ์ด์ ์ค
|
|
417
164
|
|
|
418
|
-
|
|
165
|
+
[MIT License](LICENSE)
|