@openapi-qraft/react 1.8.0 → 1.9.0

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.
Files changed (3) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/README.md +61 -55
  3. package/package.json +5 -5
package/CHANGELOG.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # @openapi-qraft/react
2
2
 
3
+ ## 1.9.0
4
+
3
5
  ## 1.8.0
4
6
 
5
7
  ### Minor Changes
package/README.md CHANGED
@@ -149,12 +149,53 @@ function App() {
149
149
  > The Qraft is designed to be as modular as possible, enabling you to integrate your own request client and serializers.
150
150
  > To ensure optimal tree-shaking, we do not include default serializers in the functions.
151
151
 
152
+ ## Supported Hooks
153
+
154
+ - [x] [`useQuery(...)`](https://openapi-qraft.github.io/openapi-qraft/docs/hooks/useQuery)
155
+ - [x] [`useMutation(...)`](https://openapi-qraft.github.io/openapi-qraft/docs/hooks/useMutation)
156
+ - [x] [`useInfiniteQuery(...)`](https://openapi-qraft.github.io/openapi-qraft/docs/hooks/useInfiniteQuery)
157
+ - [x] [`useQueries(...)`](https://openapi-qraft.github.io/openapi-qraft/docs/hooks/useQueries)
158
+ - [x] [`useSuspenseQuery(...)`](https://openapi-qraft.github.io/openapi-qraft/docs/hooks/useSuspenseQuery)
159
+ - [x] [`useSuspenseInfiniteQuery(...)`](https://openapi-qraft.github.io/openapi-qraft/docs/hooks/useSuspenseInfiniteQuery)
160
+ - [x] [`useSuspenseQueries(...)`](https://openapi-qraft.github.io/openapi-qraft/docs/hooks/useSuspenseQueries)
161
+ - [x] [`useIsFetching(...)`](https://openapi-qraft.github.io/openapi-qraft/docs/hooks/useIsFetching)
162
+ - [x] [`useMutationState(...)`](https://openapi-qraft.github.io/openapi-qraft/docs/hooks/useMutationState)
163
+ - [x] [`useIsMutating(...)`](https://openapi-qraft.github.io/openapi-qraft/docs/hooks/useIsMutating)
164
+
165
+ ## `QueryClient` methods
166
+
167
+ - [x] [`fetchQuery(...)`](https://openapi-qraft.github.io/openapi-qraft/docs/query-client/fetchQuery)
168
+ - [x] [`fetchInfiniteQuery(...)`](https://openapi-qraft.github.io/openapi-qraft/docs/query-client/fetchInfiniteQuery)
169
+ - [x] [`prefetchQuery(...)`](https://openapi-qraft.github.io/openapi-qraft/docs/query-client/prefetchQuery)
170
+ - [x] [`prefetchInfiniteQuery(...)`](https://openapi-qraft.github.io/openapi-qraft/docs/query-client/prefetchInfiniteQuery)
171
+ - [x] [`getQueryData(...)`](https://openapi-qraft.github.io/openapi-qraft/docs/query-client/getQueryData)
172
+ - [x] [`getQueriesData(...)`](https://openapi-qraft.github.io/openapi-qraft/docs/query-client/getQueriesData)
173
+ - [x] [`setQueryData(...)`](https://openapi-qraft.github.io/openapi-qraft/docs/query-client/setQueryData)
174
+ - [x] [`getQueryState(...)`](https://openapi-qraft.github.io/openapi-qraft/docs/query-client/getQueryState)
175
+ - [x] [`setQueriesData(...)`](https://openapi-qraft.github.io/openapi-qraft/docs/query-client/setQueriesData)
176
+ - [x] [`invalidateQueries(...)`](https://openapi-qraft.github.io/openapi-qraft/docs/query-client/invalidateQueries)
177
+ - [x] [`refetchQueries(...)`](https://openapi-qraft.github.io/openapi-qraft/docs/query-client/refetchQueries)
178
+ - [x] [`cancelQueries(...)`](https://openapi-qraft.github.io/openapi-qraft/docs/query-client/cancelQueries)
179
+ - [x] [`removeQueries(...)`](https://openapi-qraft.github.io/openapi-qraft/docs/query-client/removeQueries)
180
+ - [x] [`resetQueries(...)`](https://openapi-qraft.github.io/openapi-qraft/docs/query-client/resetQueries)
181
+ - [x] [`isFetching(...)`](https://openapi-qraft.github.io/openapi-qraft/docs/query-client/isFetching)
182
+ - [x] [`isMutating(...)`](https://openapi-qraft.github.io/openapi-qraft/docs/query-client/isMutating)
183
+
184
+ ## Qraft Utility Functions
185
+
186
+ - [x] [`getQueryKey(...)`](https://openapi-qraft.github.io/openapi-qraft/docs/query-client/getQueryKey)
187
+ - [x] [`setInfiniteQueryData(...)`](https://openapi-qraft.github.io/openapi-qraft/docs/query-client/setInfiniteQueryData)
188
+ - [x] [`getInfiniteQueryKey(...)`](https://openapi-qraft.github.io/openapi-qraft/docs/query-client/getInfiniteQueryKey)
189
+ - [x] [`getInfiniteQueryData(...)`](https://openapi-qraft.github.io/openapi-qraft/docs/query-client/getInfiniteQueryData)
190
+ - [x] [`getInfiniteQueryState(...)`](https://openapi-qraft.github.io/openapi-qraft/docs/query-client/getInfiniteQueryState)
191
+ - [x] [`getMutationKey(...)`](https://openapi-qraft.github.io/openapi-qraft/docs/query-client/getMutationKey)
192
+
152
193
  ## Usage
153
194
 
154
195
  With the client set up, you can now use the generated Hooks in your React Components to fetch data, execute mutations,
155
196
  and more.
156
197
 
157
- ### [useQuery(...) 🔗](https://tanstack.com/query/latest/docs/framework/react/reference/useQuery)
198
+ ### [useQuery(...) 🔗](https://openapi-qraft.github.io/openapi-qraft/docs/hooks/useQuery)
158
199
 
159
200
  ```ts
160
201
  /**
@@ -173,7 +214,7 @@ const { data, error, isPending } = qraft.entities.getEntities.useQuery({
173
214
  });
174
215
  ```
175
216
 
176
- ### [useMutation(...) 🔗](https://tanstack.com/query/latest/docs/framework/react/reference/useMutation)
217
+ ### [useMutation(...) 🔗](https://openapi-qraft.github.io/openapi-qraft/docs/hooks/useMutation)
177
218
 
178
219
  #### With predefined parameters
179
220
 
@@ -233,7 +274,7 @@ mutation.mutate({
233
274
  });
234
275
  ```
235
276
 
236
- ### [useMutationState(...) 🔗](https://tanstack.com/query/latest/docs/framework/react/reference/useMutationState)
277
+ ### [useMutationState(...) 🔗](https://openapi-qraft.github.io/openapi-qraft/docs/hooks/useMutationState)
237
278
 
238
279
  Mutation state is a helper hook that provides the current state of a mutation globally.
239
280
  It could be used to track the status of a mutation in any component, which is useful for showing loading spinners or
@@ -261,7 +302,7 @@ useEffect(() => {
261
302
  }, [mutate, mutationState?.status]);
262
303
  ```
263
304
 
264
- ### [useInfiniteQuery(...) 🔗](https://tanstack.com/query/latest/docs/framework/react/reference/useInfiniteQuery)
305
+ ### [useInfiniteQuery(...) 🔗](https://openapi-qraft.github.io/openapi-qraft/docs/hooks/useInfiniteQuery)
265
306
 
266
307
  #### _Offset-based_
267
308
 
@@ -338,7 +379,7 @@ infiniteQuery.fetchNextPage();
338
379
  infiniteQuery.fetchPreviousPage();
339
380
  ```
340
381
 
341
- ### [useQueries(...) 🔗](https://tanstack.com/query/latest/docs/framework/react/reference/useQueries)
382
+ ### [useQueries(...) 🔗](https://openapi-qraft.github.io/openapi-qraft/docs/hooks/useQueries)
342
383
 
343
384
  ```ts
344
385
  /**
@@ -377,7 +418,7 @@ qraft.entities.getEntities.useQueries({
377
418
  });
378
419
  ```
379
420
 
380
- ### [useIsFetching(...) 🔗](https://tanstack.com/query/latest/docs/framework/react/reference/useIsFetching)
421
+ ### [useIsFetching(...) 🔗](https://openapi-qraft.github.io/openapi-qraft/docs/hooks/useIsFetching)
381
422
 
382
423
  ```tsx
383
424
  function FetchStatus() {
@@ -405,9 +446,19 @@ function FetchStatus() {
405
446
  }
406
447
  ```
407
448
 
408
- ### [`QueryClient`](https://tanstack.com/query/latest/docs/reference/QueryClient) Methods
449
+ ## [`QueryClient`](https://tanstack.com/query/latest/docs/reference/QueryClient) Methods
450
+
451
+ #### [setQueryData(...) 🔗](https://openapi-qraft.github.io/openapi-qraft/docs/query-client/setQueryData)
452
+
453
+ ```ts
454
+ qraft.pet.getPetById.setQueryData(
455
+ { path: { petId: 123 } }, // Query Key parameters
456
+ { id: 123, name: 'Rex' }, // Data to set
457
+ queryClient
458
+ );
459
+ ```
409
460
 
410
- #### [invalidateQueries(...) 🔗](https://tanstack.com/query/latest/docs/reference/QueryClient#queryclientinvalidatequeries)
461
+ #### [invalidateQueries(...) 🔗](https://openapi-qraft.github.io/openapi-qraft/docs/query-client/invalidateQueries)
411
462
 
412
463
  [Queries Invalidation 🔗](https://tanstack.com/query/latest/docs/framework/react/guides/query-invalidation) is possible
413
464
  using `<operation>.invalidateQueries(...)` method.
@@ -511,25 +562,7 @@ qraft.entities.getEntities.invalidateQueries(
511
562
  );
512
563
  ```
513
564
 
514
- #### [cancelQueries(...) 🔗](https://tanstack.com/query/latest/docs/reference/QueryClient#queryclientcancelqueries)
515
-
516
- [Query Cancellation](https://tanstack.com/query/latest/docs/framework/react/guides/query-cancellation) has the
517
- same interface as `invalidateQueries(...)`, but it will cancel the queries instead of invalidating them.
518
-
519
- #### [resetQueries(...) 🔗](https://tanstack.com/query/latest/docs/reference/QueryClient#queryclientresetqueries)
520
-
521
- The interface is the same as `invalidateQueries(...)`, but it will reset the queries instead of invalidating them.
522
-
523
- #### [refetchQueries(...) 🔗](https://tanstack.com/query/latest/docs/reference/QueryClient#queryclientrefetchqueries)
524
-
525
- The interface is the same as `invalidateQueries(...)`, but it will refetch the queries instead of invalidating them.
526
-
527
- #### [isFetching(...) 🔗](https://tanstack.com/query/latest/docs/reference/QueryClient#queryclientisfetching)
528
-
529
- The interface is the same as `invalidateQueries(...), but it will check if the queries are fetching, and there are no
530
- options.
531
-
532
- #### [fetchQuery(...) 🔗](https://tanstack.com/query/latest/docs/reference/QueryClient#queryclientfetchquery)
565
+ #### [fetchQuery(...) 🔗](https://openapi-qraft.github.io/openapi-qraft/docs/query-client/fetchQuery)
533
566
 
534
567
  ```ts
535
568
  /**
@@ -557,11 +590,7 @@ const posts = qraft.posts.getPosts.fetchQuery(
557
590
  );
558
591
  ```
559
592
 
560
- #### [prefetchQuery(...) 🔗](https://tanstack.com/query/latest/docs/reference/QueryClient#queryclientprefetchquery)
561
-
562
- The interface is the same as `fetchQuery(...)`, but returns empty Promise.
563
-
564
- #### [fetchInfiniteQuery(...) 🔗](https://tanstack.com/query/latest/docs/reference/QueryClient#queryclientfetchinfinitequery)
593
+ #### [fetchInfiniteQuery(...) 🔗](https://openapi-qraft.github.io/openapi-qraft/docs/query-client/fetchInfiniteQuery)
565
594
 
566
595
  ```ts
567
596
  /**
@@ -604,29 +633,6 @@ console.log(
604
633
  );
605
634
  ```
606
635
 
607
- #### [prefetchInfiniteQuery(...) 🔗](https://tanstack.com/query/latest/docs/reference/QueryClient#queryclientprefetchinfinitequery)
608
-
609
- The interface is the same as `fetchInfiniteQuery(...)`, but returns empty Promise.
610
-
611
- ### Suspense Queries
612
-
613
- Supported Suspense Queries are:
614
-
615
- - [useSuspenseQuery(...) 🔗](https://tanstack.com/query/latest/docs/framework/react/reference/useSuspenseQuery)
616
- - [useSuspenseInfiniteQuery(...) 🔗](https://tanstack.com/query/latest/docs/framework/react/reference/useSuspenseInfiniteQuery)
617
- - [useSuspenseQueries(...) 🔗](https://tanstack.com/query/latest/docs/framework/react/reference/useSuspenseQueries)
618
-
619
- ### Documentation in Progress 🚧
620
-
621
- - `getQueryKey(parameters)`
622
- - `getQueryData(parameters)`
623
- - `setQueryData(parameters, updater)`
624
- - `getInfiniteQueryKey(parameters)`
625
- - `getInfiniteQueryData(parameters)`
626
- - `setInfiniteQueryData(parameters, updater)`
627
- - `schema` - object with schema: `{method, url, mediaType}`
628
- - `types` - object with types: `{parameters, data, error, body}`
629
-
630
636
  ### Authorization and Custom Requests
631
637
 
632
638
  To override any request, you can provide a custom `request` function to the `QraftContext`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openapi-qraft/react",
3
- "version": "1.8.0",
3
+ "version": "1.9.0",
4
4
  "description": "API client for React, providing type-safe requests and dynamic Tanstack Query React Hooks via a modular, Proxy-based architecture.",
5
5
  "scripts": {
6
6
  "build": "rimraf dist/ && tsc --project tsconfig.build.json",
@@ -9,15 +9,15 @@
9
9
  "test:coverage": "vitest run --coverage",
10
10
  "typecheck": "tsc --noEmit",
11
11
  "lint": "eslint",
12
- "generate-qraft": "openapi-qraft --plugin tanstack-query-react ../test-fixtures/openapi.json --clean -o src/tests/fixtures/api --openapi-types-import-path '../../openapi.js' --explicit-import-extensions --filter-services '/approval_policies/**,/entities/**,/files/**,!/internal/**' && prettier --write src/tests/fixtures/api/**/*.ts",
13
- "generate-types": "openapi-qraft-typescript ../test-fixtures/openapi.json -o src/tests/fixtures/openapi.ts"
12
+ "generate-api": "openapi-qraft --plugin tanstack-query-react --plugin openapi-typescript ../test-fixtures/openapi.json -rm -o src/tests/fixtures/api --openapi-types-file-name openapi.ts --explicit-import-extensions --filter-services '/approval_policies/**,/entities/**,/files/**,!/internal/**' && yarn _prettify-api",
13
+ "_prettify-api": "prettier --write src/tests/fixtures/api/**/*.ts"
14
14
  },
15
15
  "type": "module",
16
16
  "sideEffects": false,
17
17
  "devDependencies": {
18
- "@openapi-qraft/cli": "~1.8.0",
18
+ "@openapi-qraft/cli": "~1.9.0",
19
19
  "@openapi-qraft/eslint-config": "~1.0.0",
20
- "@openapi-qraft/openapi-typescript": "^1.0.0",
20
+ "@openapi-qraft/openapi-typescript-plugin": "^1.0.1",
21
21
  "@openapi-qraft/test-fixtures": "~1.0.0",
22
22
  "@tanstack/react-query": "^5.17.3",
23
23
  "@testing-library/jest-dom": "^5.17.0",