@openapi-qraft/react 1.2.0 → 1.4.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.
- package/CHANGELOG.md +38 -0
- package/README.md +118 -38
- package/dist/QraftContext.d.ts +8 -10
- package/dist/QraftContext.d.ts.map +1 -1
- package/dist/QraftContext.js.map +1 -1
- package/dist/ServiceOperation.d.ts +152 -5
- package/dist/ServiceOperation.d.ts.map +1 -1
- package/dist/callbacks/cancelQueries.d.ts +2 -2
- package/dist/callbacks/cancelQueries.d.ts.map +1 -1
- package/dist/callbacks/cancelQueries.js.map +1 -1
- package/dist/callbacks/fetchInfiniteQuery.d.ts +7 -0
- package/dist/callbacks/fetchInfiniteQuery.d.ts.map +1 -0
- package/dist/callbacks/fetchInfiniteQuery.js +5 -0
- package/dist/callbacks/fetchInfiniteQuery.js.map +1 -0
- package/dist/callbacks/fetchQuery.d.ts +7 -0
- package/dist/callbacks/fetchQuery.d.ts.map +1 -0
- package/dist/callbacks/fetchQuery.js +5 -0
- package/dist/callbacks/fetchQuery.js.map +1 -0
- package/dist/callbacks/getInfiniteQueryData.d.ts +4 -4
- package/dist/callbacks/getInfiniteQueryData.d.ts.map +1 -1
- package/dist/callbacks/getInfiniteQueryData.js +3 -6
- package/dist/callbacks/getInfiniteQueryData.js.map +1 -1
- package/dist/callbacks/getInfiniteQueryKey.d.ts +2 -2
- package/dist/callbacks/getInfiniteQueryKey.d.ts.map +1 -1
- package/dist/callbacks/getInfiniteQueryKey.js.map +1 -1
- package/dist/callbacks/getMutationKey.d.ts +2 -2
- package/dist/callbacks/getMutationKey.d.ts.map +1 -1
- package/dist/callbacks/getMutationKey.js.map +1 -1
- package/dist/callbacks/getQueryData.d.ts +3 -3
- package/dist/callbacks/getQueryData.d.ts.map +1 -1
- package/dist/callbacks/getQueryData.js +3 -4
- package/dist/callbacks/getQueryData.js.map +1 -1
- package/dist/callbacks/getQueryKey.d.ts +2 -2
- package/dist/callbacks/getQueryKey.d.ts.map +1 -1
- package/dist/callbacks/getQueryKey.js.map +1 -1
- package/dist/callbacks/invalidateQueries.d.ts +2 -2
- package/dist/callbacks/invalidateQueries.d.ts.map +1 -1
- package/dist/callbacks/invalidateQueries.js.map +1 -1
- package/dist/callbacks/isFetching.d.ts +2 -2
- package/dist/callbacks/isFetching.d.ts.map +1 -1
- package/dist/callbacks/isFetching.js.map +1 -1
- package/dist/callbacks/isMutating.d.ts +5 -0
- package/dist/callbacks/isMutating.d.ts.map +1 -0
- package/dist/callbacks/isMutating.js +5 -0
- package/dist/callbacks/isMutating.js.map +1 -0
- package/dist/callbacks/mutationFn.d.ts +2 -2
- package/dist/callbacks/mutationFn.d.ts.map +1 -1
- package/dist/callbacks/mutationFn.js.map +1 -1
- package/dist/callbacks/prefetchInfiniteQuery.d.ts +7 -0
- package/dist/callbacks/prefetchInfiniteQuery.d.ts.map +1 -0
- package/dist/callbacks/prefetchInfiniteQuery.js +5 -0
- package/dist/callbacks/prefetchInfiniteQuery.js.map +1 -0
- package/dist/callbacks/prefetchQuery.d.ts +7 -0
- package/dist/callbacks/prefetchQuery.d.ts.map +1 -0
- package/dist/callbacks/prefetchQuery.js +5 -0
- package/dist/callbacks/prefetchQuery.js.map +1 -0
- package/dist/callbacks/queryFn.js.map +1 -1
- package/dist/callbacks/refetchQueries.d.ts +2 -2
- package/dist/callbacks/refetchQueries.d.ts.map +1 -1
- package/dist/callbacks/refetchQueries.js.map +1 -1
- package/dist/callbacks/removeQueries.d.ts +5 -0
- package/dist/callbacks/removeQueries.d.ts.map +1 -0
- package/dist/callbacks/removeQueries.js +5 -0
- package/dist/callbacks/removeQueries.js.map +1 -0
- package/dist/callbacks/resetQueries.d.ts +2 -2
- package/dist/callbacks/resetQueries.d.ts.map +1 -1
- package/dist/callbacks/resetQueries.js.map +1 -1
- package/dist/callbacks/setInfiniteQueryData.d.ts +2 -2
- package/dist/callbacks/setInfiniteQueryData.d.ts.map +1 -1
- package/dist/callbacks/setInfiniteQueryData.js +2 -6
- package/dist/callbacks/setInfiniteQueryData.js.map +1 -1
- package/dist/callbacks/setQueryData.d.ts +3 -3
- package/dist/callbacks/setQueryData.d.ts.map +1 -1
- package/dist/callbacks/setQueryData.js +3 -7
- package/dist/callbacks/setQueryData.js.map +1 -1
- package/dist/callbacks/useInfiniteQuery.d.ts +4 -4
- package/dist/callbacks/useInfiniteQuery.d.ts.map +1 -1
- package/dist/callbacks/useInfiniteQuery.js +4 -24
- package/dist/callbacks/useInfiniteQuery.js.map +1 -1
- package/dist/callbacks/useIsFetching.d.ts +2 -2
- package/dist/callbacks/useIsFetching.d.ts.map +1 -1
- package/dist/callbacks/useIsFetching.js +0 -3
- package/dist/callbacks/useIsFetching.js.map +1 -1
- package/dist/callbacks/useIsMutating.d.ts +7 -0
- package/dist/callbacks/useIsMutating.d.ts.map +1 -0
- package/dist/callbacks/useIsMutating.js +9 -0
- package/dist/callbacks/useIsMutating.js.map +1 -0
- package/dist/callbacks/useMutation.d.ts +2 -2
- package/dist/callbacks/useMutation.d.ts.map +1 -1
- package/dist/callbacks/useMutation.js +6 -4
- package/dist/callbacks/useMutation.js.map +1 -1
- package/dist/callbacks/useMutationState.d.ts +2 -2
- package/dist/callbacks/useMutationState.d.ts.map +1 -1
- package/dist/callbacks/useMutationState.js +2 -15
- package/dist/callbacks/useMutationState.js.map +1 -1
- package/dist/callbacks/useQueries.d.ts +2 -2
- package/dist/callbacks/useQueries.d.ts.map +1 -1
- package/dist/callbacks/useQueries.js +5 -3
- package/dist/callbacks/useQueries.js.map +1 -1
- package/dist/callbacks/useQuery.d.ts +3 -3
- package/dist/callbacks/useQuery.d.ts.map +1 -1
- package/dist/callbacks/useQuery.js +4 -23
- package/dist/callbacks/useQuery.js.map +1 -1
- package/dist/callbacks/useSuspenseInfiniteQuery.d.ts +4 -4
- package/dist/callbacks/useSuspenseInfiniteQuery.d.ts.map +1 -1
- package/dist/callbacks/useSuspenseInfiniteQuery.js +4 -24
- package/dist/callbacks/useSuspenseInfiniteQuery.js.map +1 -1
- package/dist/callbacks/useSuspenseQueries.d.ts +2 -2
- package/dist/callbacks/useSuspenseQueries.d.ts.map +1 -1
- package/dist/callbacks/useSuspenseQueries.js +5 -3
- package/dist/callbacks/useSuspenseQueries.js.map +1 -1
- package/dist/callbacks/useSuspenseQuery.d.ts +4 -4
- package/dist/callbacks/useSuspenseQuery.d.ts.map +1 -1
- package/dist/callbacks/useSuspenseQuery.js +4 -23
- package/dist/callbacks/useSuspenseQuery.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/callQueryClientFetchMethod.d.ts +20 -0
- package/dist/lib/callQueryClientFetchMethod.d.ts.map +1 -0
- package/dist/lib/callQueryClientFetchMethod.js +48 -0
- package/dist/lib/callQueryClientFetchMethod.js.map +1 -0
- package/dist/lib/callQueryClientMethodWithMutationFilters.d.ts +11 -0
- package/dist/lib/callQueryClientMethodWithMutationFilters.d.ts.map +1 -0
- package/dist/lib/callQueryClientMethodWithMutationFilters.js +18 -0
- package/dist/lib/callQueryClientMethodWithMutationFilters.js.map +1 -0
- package/dist/lib/callQueryClientMethodWithQueryFilters.d.ts +2 -2
- package/dist/lib/callQueryClientMethodWithQueryFilters.d.ts.map +1 -1
- package/dist/lib/callQueryClientMethodWithQueryFilters.js +5 -13
- package/dist/lib/callQueryClientMethodWithQueryFilters.js.map +1 -1
- package/dist/lib/callQueryClientMethodWithQueryKey.d.ts +11 -0
- package/dist/lib/callQueryClientMethodWithQueryKey.d.ts.map +1 -0
- package/dist/lib/callQueryClientMethodWithQueryKey.js +22 -0
- package/dist/lib/callQueryClientMethodWithQueryKey.js.map +1 -0
- package/dist/lib/composeInfiniteQueryKey.d.ts +2 -2
- package/dist/lib/composeInfiniteQueryKey.d.ts.map +1 -1
- package/dist/lib/composeMutationFilters.d.ts +11 -0
- package/dist/lib/composeMutationFilters.d.ts.map +1 -0
- package/dist/lib/composeMutationFilters.js +32 -0
- package/dist/lib/composeMutationFilters.js.map +1 -0
- package/dist/lib/composeMutationKey.d.ts +3 -3
- package/dist/lib/composeMutationKey.d.ts.map +1 -1
- package/dist/lib/composeMutationKey.js +1 -1
- package/dist/lib/composeMutationKey.js.map +1 -1
- package/dist/lib/composeQueryFilters.d.ts +3 -3
- package/dist/lib/composeQueryFilters.d.ts.map +1 -1
- package/dist/lib/composeQueryFilters.js.map +1 -1
- package/dist/lib/composeQueryKey.d.ts +2 -2
- package/dist/lib/composeQueryKey.d.ts.map +1 -1
- package/dist/lib/composeQueryKey.js.map +1 -1
- package/dist/lib/{request.d.ts → requestFn.d.ts} +28 -18
- package/dist/lib/requestFn.d.ts.map +1 -0
- package/dist/lib/{request.js → requestFn.js} +16 -21
- package/dist/lib/requestFn.js.map +1 -0
- package/dist/lib/useComposeUseQueryOptions.d.ts +16 -0
- package/dist/lib/useComposeUseQueryOptions.d.ts.map +1 -0
- package/dist/lib/useComposeUseQueryOptions.js +40 -0
- package/dist/lib/useComposeUseQueryOptions.js.map +1 -0
- package/dist/qraftAPIClient.d.ts +3 -3
- package/dist/qraftAPIClient.d.ts.map +1 -1
- package/package.json +3 -2
- package/src/QraftContext.ts +13 -16
- package/src/ServiceOperation.ts +360 -6
- package/src/callbacks/cancelQueries.ts +3 -3
- package/src/callbacks/fetchInfiniteQuery.ts +22 -0
- package/src/callbacks/fetchQuery.ts +20 -0
- package/src/callbacks/getInfiniteQueryData.ts +13 -16
- package/src/callbacks/getInfiniteQueryKey.ts +3 -3
- package/src/callbacks/getMutationKey.ts +3 -3
- package/src/callbacks/getQueryData.ts +12 -14
- package/src/callbacks/getQueryKey.ts +3 -7
- package/src/callbacks/invalidateQueries.ts +3 -3
- package/src/callbacks/isFetching.ts +3 -3
- package/src/callbacks/isMutating.ts +22 -0
- package/src/callbacks/mutationFn.ts +3 -3
- package/src/callbacks/prefetchInfiniteQuery.ts +22 -0
- package/src/callbacks/prefetchQuery.ts +22 -0
- package/src/callbacks/queryFn.ts +2 -2
- package/src/callbacks/refetchQueries.ts +3 -3
- package/src/callbacks/removeQueries.ts +22 -0
- package/src/callbacks/resetQueries.ts +3 -3
- package/src/callbacks/setInfiniteQueryData.ts +11 -18
- package/src/callbacks/setQueryData.ts +13 -18
- package/src/callbacks/useInfiniteQuery.ts +8 -48
- package/src/callbacks/useIsFetching.ts +3 -9
- package/src/callbacks/useIsMutating.ts +42 -0
- package/src/callbacks/useMutation.ts +15 -20
- package/src/callbacks/useMutationState.ts +5 -30
- package/src/callbacks/useQueries.ts +12 -17
- package/src/callbacks/useQuery.ts +7 -43
- package/src/callbacks/useSuspenseInfiniteQuery.ts +8 -44
- package/src/callbacks/useSuspenseQueries.ts +12 -13
- package/src/callbacks/useSuspenseQuery.ts +8 -45
- package/src/index.ts +6 -6
- package/src/lib/callQueryClientFetchMethod.ts +90 -0
- package/src/lib/callQueryClientMethodWithMutationFilters.ts +37 -0
- package/src/lib/callQueryClientMethodWithQueryFilters.ts +10 -23
- package/src/lib/callQueryClientMethodWithQueryKey.ts +46 -0
- package/src/lib/composeInfiniteQueryKey.ts +2 -2
- package/src/lib/composeMutationFilters.ts +44 -0
- package/src/lib/composeMutationKey.ts +5 -8
- package/src/lib/composeQueryFilters.ts +2 -2
- package/src/lib/composeQueryKey.ts +2 -5
- package/src/lib/{request.ts → requestFn.ts} +61 -59
- package/src/lib/useComposeUseQueryOptions.ts +64 -0
- package/src/qraftAPIClient.ts +4 -4
- package/dist/RequestClient.d.ts +0 -3
- package/dist/RequestClient.d.ts.map +0 -1
- package/dist/RequestClient.js +0 -2
- package/dist/RequestClient.js.map +0 -1
- package/dist/lib/request.d.ts.map +0 -1
- package/dist/lib/request.js.map +0 -1
- package/src/RequestClient.ts +0 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,43 @@
|
|
|
1
1
|
# @openapi-qraft/react
|
|
2
2
|
|
|
3
|
+
## 1.4.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 6343a8d: Added support for `QueryClient.isMutating(...)` method
|
|
8
|
+
- b297c10: Unified `composeMutationKey(...)` to return the same key structure as `composeQueryKey(...)` if no parameters are passed
|
|
9
|
+
- 42a0b11: Added support for `QueryClient.removeQueries(...)` method
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 34fd459: Fixed `fetchQuery(...)` documentation
|
|
14
|
+
|
|
15
|
+
## 1.3.2
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- cc36283: Republished
|
|
20
|
+
|
|
21
|
+
## 1.3.1
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- df98bc2: Fixed issue with `fetch(this, ...)`
|
|
26
|
+
|
|
27
|
+
## 1.3.0
|
|
28
|
+
|
|
29
|
+
### Minor Changes
|
|
30
|
+
|
|
31
|
+
- 7c81509: Add support for `QueryClient.fetchInfiniteQuery(...)` and `QueryClient.prefetchInfiniteQuery(...)` methods
|
|
32
|
+
- 8e47c05: Simplified `QueryClient.setQueryData(...)` API
|
|
33
|
+
- 48e662d: Added support for `QueryClient.fetchQuery(...)` method
|
|
34
|
+
- 315883b: Changed `requestFn(...)` API to simplify the usage
|
|
35
|
+
- d48a40e: Renamed the `request` property to `requestFn` for `QraftContext.value`
|
|
36
|
+
|
|
37
|
+
### Patch Changes
|
|
38
|
+
|
|
39
|
+
- 472ae32: Added support for `QueryClient.prefetchQuery(...)` method
|
|
40
|
+
|
|
3
41
|
## 1.2.0
|
|
4
42
|
|
|
5
43
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
`@openapi-qraft/react` is a modular TypeScript client designed to facilitate type-safe API requests in React
|
|
4
4
|
applications,
|
|
5
|
-
leveraging the power of **
|
|
5
|
+
leveraging the power of **TanStack Query v5**. It utilizes a Proxy-based architecture to dynamically generate
|
|
6
6
|
hooks with typed parameters, ensuring that your API requests are both type-safe and efficient.
|
|
7
7
|
|
|
8
8
|
## Features
|
|
@@ -11,7 +11,7 @@ hooks with typed parameters, ensuring that your API requests are both type-safe
|
|
|
11
11
|
developer experience.
|
|
12
12
|
- **Modular Design:** Customize the utility with a set of callbacks to handle API calls according to your project's
|
|
13
13
|
needs.
|
|
14
|
-
- **Integration with [
|
|
14
|
+
- **Integration with [TanStack Query v5](https://tanstack.com/query/v5):** Seamlessly integrate with _TanStack Query_
|
|
15
15
|
for handling server state, caching, and data synchronization.
|
|
16
16
|
- **Dynamic Proxy-Based Hooks:** Automatically generate React Query hooks for your API endpoints without manual
|
|
17
17
|
boilerplate.
|
|
@@ -56,7 +56,7 @@ npx openapi-typescript https://api.dev.monite.com/openapi.json?version=2023-09-0
|
|
|
56
56
|
|
|
57
57
|
#### Generating Qraft Services
|
|
58
58
|
|
|
59
|
-
Next, use `@openapi-qraft/cli` to generate the services and typed
|
|
59
|
+
Next, use `@openapi-qraft/cli` to generate the services and typed TanStack Query React Hooks. Ensure to specify the path
|
|
60
60
|
to the TypeScript definitions generated in the previous step.
|
|
61
61
|
|
|
62
62
|
```bash
|
|
@@ -92,7 +92,7 @@ Every request will be handled by `request` function, which can be customized to
|
|
|
92
92
|
```tsx
|
|
93
93
|
import { useMemo } from 'react';
|
|
94
94
|
|
|
95
|
-
import {
|
|
95
|
+
import { QraftContext, requestFn } from '@openapi-qraft/react';
|
|
96
96
|
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
97
97
|
|
|
98
98
|
// where `./api` is the '--output-dir' path to the services you generated with `@openapi-qraft/cli`
|
|
@@ -109,7 +109,7 @@ function Providers({ children }: { children: React.ReactNode }) {
|
|
|
109
109
|
<QraftContext.Provider
|
|
110
110
|
value={{
|
|
111
111
|
baseUrl: 'https://api.sandbox.monite.com/v1', // base URL for all requests
|
|
112
|
-
|
|
112
|
+
requestFn, // `requestFn(...)` will be invoked for every request
|
|
113
113
|
}}
|
|
114
114
|
>
|
|
115
115
|
{children}
|
|
@@ -274,7 +274,7 @@ useEffect(() => {
|
|
|
274
274
|
const infiniteQuery = qraft.posts.getPosts.useInfiniteQuery(
|
|
275
275
|
{ query: { limit: 10 } },
|
|
276
276
|
{
|
|
277
|
-
// * required by
|
|
277
|
+
// * required by TanStack Query
|
|
278
278
|
getNextPageParam: (lastPage, allPages, lastPageParams) => {
|
|
279
279
|
if (lastPage.length < 10) return; // if less than 10 items, there are no more pages
|
|
280
280
|
return {
|
|
@@ -283,7 +283,7 @@ const infiniteQuery = qraft.posts.getPosts.useInfiniteQuery(
|
|
|
283
283
|
},
|
|
284
284
|
};
|
|
285
285
|
},
|
|
286
|
-
// * required by
|
|
286
|
+
// * required by TanStack Query
|
|
287
287
|
initialPageParam: {
|
|
288
288
|
query: {
|
|
289
289
|
page: 1, // will be used in initial request
|
|
@@ -316,11 +316,11 @@ const infiniteQuery = qraft.dataExports.getDataExports.useInfiniteQuery(
|
|
|
316
316
|
},
|
|
317
317
|
},
|
|
318
318
|
{
|
|
319
|
-
// * required by
|
|
319
|
+
// * required by TanStack Query
|
|
320
320
|
initialPageParam: {
|
|
321
321
|
query: { pagination_token: undefined }, // will be used in initial request
|
|
322
322
|
},
|
|
323
|
-
// * required by
|
|
323
|
+
// * required by TanStack Query
|
|
324
324
|
getNextPageParam: (lastPage, allPages, lastPageParam) => ({
|
|
325
325
|
query: { pagination_token: lastPage.next_pagination_token },
|
|
326
326
|
}),
|
|
@@ -331,10 +331,10 @@ const infiniteQuery = qraft.dataExports.getDataExports.useInfiniteQuery(
|
|
|
331
331
|
}
|
|
332
332
|
);
|
|
333
333
|
|
|
334
|
-
// ⬇︎ will execute GET /data_exports?pagination_token
|
|
334
|
+
// ⬇︎ will execute GET /data_exports?pagination_token=<NEXT_PAGINATION_TOKEN>
|
|
335
335
|
infiniteQuery.fetchNextPage();
|
|
336
336
|
|
|
337
|
-
// ⬇︎ will execute GET /data_exports?pagination_token
|
|
337
|
+
// ⬇︎ will execute GET /data_exports?pagination_token=<PREV_PAGINATION_TOKEN>
|
|
338
338
|
infiniteQuery.fetchPreviousPage();
|
|
339
339
|
```
|
|
340
340
|
|
|
@@ -377,6 +377,34 @@ qraft.entities.getEntities.useQueries({
|
|
|
377
377
|
});
|
|
378
378
|
```
|
|
379
379
|
|
|
380
|
+
### [useIsFetching(...) 🔗](https://tanstack.com/query/latest/docs/framework/react/reference/useIsFetching)
|
|
381
|
+
|
|
382
|
+
```tsx
|
|
383
|
+
function FetchStatus() {
|
|
384
|
+
// Checks all queries `GET /entities`
|
|
385
|
+
const fetchingTotal = qraft.entities.getEntities.useIsFetching();
|
|
386
|
+
|
|
387
|
+
// Checks all queries `GET /entities/3e3e-3e3e-3e3e` and `x-monite-version: 2023-09-01` header
|
|
388
|
+
const specificQueryKeyTotal = qraft.entities.getEntities.useIsFetching({
|
|
389
|
+
parameters: {
|
|
390
|
+
header: {
|
|
391
|
+
'x-monite-version': '2023-09-01',
|
|
392
|
+
},
|
|
393
|
+
path: {
|
|
394
|
+
entity_id: '3e3e-3e3e-3e3e',
|
|
395
|
+
},
|
|
396
|
+
},
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
return (
|
|
400
|
+
<>
|
|
401
|
+
{!!fetchingTotal && <div>Number of queries: {fetchingTotal}...</div>}
|
|
402
|
+
{!!specificQueryKeyTotal && <div>Loading specific query...</div>}
|
|
403
|
+
</>
|
|
404
|
+
);
|
|
405
|
+
}
|
|
406
|
+
```
|
|
407
|
+
|
|
380
408
|
### [`QueryClient`](https://tanstack.com/query/latest/docs/reference/QueryClient) Methods
|
|
381
409
|
|
|
382
410
|
#### [invalidateQueries(...) 🔗](https://tanstack.com/query/latest/docs/reference/QueryClient#queryclientinvalidatequeries)
|
|
@@ -501,33 +529,85 @@ The interface is the same as `invalidateQueries(...)`, but it will refetch the q
|
|
|
501
529
|
The interface is the same as `invalidateQueries(...), but it will check if the queries are fetching, and there are no
|
|
502
530
|
options.
|
|
503
531
|
|
|
504
|
-
#### [
|
|
532
|
+
#### [fetchQuery(...) 🔗](https://tanstack.com/query/latest/docs/reference/QueryClient#queryclientfetchquery)
|
|
505
533
|
|
|
506
|
-
|
|
534
|
+
```ts
|
|
535
|
+
/**
|
|
536
|
+
* Will execute the request:
|
|
537
|
+
* ###
|
|
538
|
+
* GET /posts?limit=10
|
|
539
|
+
**/
|
|
540
|
+
import { requestFn } from '@openapi-qraft/react';
|
|
541
|
+
import { QueryClient } from '@tanstack/react-query';
|
|
507
542
|
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
parameters: {
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
543
|
+
const queryClient = new QueryClient();
|
|
544
|
+
|
|
545
|
+
const posts = qraft.posts.getPosts.fetchQuery(
|
|
546
|
+
{
|
|
547
|
+
parameters: { query: { limit: 10 } },
|
|
548
|
+
/**
|
|
549
|
+
* Request function should be provided, otherwise it will throw an error
|
|
550
|
+
* if default `queryFn` is not set previously using
|
|
551
|
+
* `QueryClient.setDefaultOptions(...)` method
|
|
552
|
+
*/
|
|
553
|
+
requestFn: requestFn,
|
|
554
|
+
baseUrl: 'https://api.sandbox.monite.com/v1', // must be provided if `requestFn` is set
|
|
555
|
+
},
|
|
556
|
+
queryClient
|
|
557
|
+
);
|
|
558
|
+
```
|
|
559
|
+
|
|
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)
|
|
565
|
+
|
|
566
|
+
```ts
|
|
567
|
+
/**
|
|
568
|
+
* Will execute the initial request:
|
|
569
|
+
* ###
|
|
570
|
+
* GET /posts?limit=10&page=1
|
|
571
|
+
* ###
|
|
572
|
+
* And then will execute the next page request:
|
|
573
|
+
* GET /posts?limit=10&page=2
|
|
574
|
+
**/
|
|
575
|
+
import { requestFn } from '@openapi-qraft/react';
|
|
576
|
+
import { QueryClient } from '@tanstack/react-query';
|
|
577
|
+
|
|
578
|
+
const queryClient = new QueryClient();
|
|
579
|
+
|
|
580
|
+
const posts = qraft.posts.getPosts.fetchInfiniteQuery(
|
|
581
|
+
{
|
|
582
|
+
parameters: { query: { limit: 10 } },
|
|
583
|
+
pages: 2, // How many pages to fetch
|
|
584
|
+
initialPageParam: {
|
|
585
|
+
query: { pagination_token: undefined }, // will be used in initial request
|
|
519
586
|
},
|
|
520
|
-
|
|
587
|
+
getNextPageParam: (lastPage, allPages, lastPageParam) => ({
|
|
588
|
+
query: { pagination_token: lastPage.next_pagination_token },
|
|
589
|
+
}),
|
|
590
|
+
/**
|
|
591
|
+
* Request function should be provided, otherwise it will throw an error
|
|
592
|
+
* if default `queryFn` is not set previously using
|
|
593
|
+
* `QueryClient.setDefaultOptions(...)` method
|
|
594
|
+
*/
|
|
595
|
+
requestFn: requestFn,
|
|
596
|
+
baseUrl: 'https://api.sandbox.monite.com/v1', // must be provided if `requestFn` is set
|
|
597
|
+
},
|
|
598
|
+
queryClient
|
|
599
|
+
);
|
|
521
600
|
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
</>
|
|
527
|
-
);
|
|
528
|
-
}
|
|
601
|
+
console.log(
|
|
602
|
+
posts.pages, // all fetched pages
|
|
603
|
+
posts.pageParams // all page parameters
|
|
604
|
+
);
|
|
529
605
|
```
|
|
530
606
|
|
|
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
|
+
|
|
531
611
|
### Suspense Queries
|
|
532
612
|
|
|
533
613
|
Supported Suspense Queries are:
|
|
@@ -542,8 +622,8 @@ Supported Suspense Queries are:
|
|
|
542
622
|
- `getQueryData(parameters)`
|
|
543
623
|
- `setQueryData(parameters, updater)`
|
|
544
624
|
- `getInfiniteQueryKey(parameters)`
|
|
545
|
-
- `
|
|
546
|
-
- `
|
|
625
|
+
- `getInfiniteQueryData(parameters)`
|
|
626
|
+
- `setInfiniteQueryData(parameters, updater)`
|
|
547
627
|
- `schema` - object with schema: `{method, url, mediaType}`
|
|
548
628
|
- `types` - object with types: `{parameters, data, error, body}`
|
|
549
629
|
|
|
@@ -555,7 +635,7 @@ In the example below, we provide a custom `request` function to the `QraftContex
|
|
|
555
635
|
using a custom `fetchToken` async function.
|
|
556
636
|
|
|
557
637
|
```tsx
|
|
558
|
-
import {
|
|
638
|
+
import { QraftContext, requestFn } from '@openapi-qraft/react';
|
|
559
639
|
|
|
560
640
|
import { fetchToken } from './auth';
|
|
561
641
|
|
|
@@ -564,11 +644,11 @@ function QraftProvider({ children }: { children: React.ReactNode }) {
|
|
|
564
644
|
<QraftContext.Provider
|
|
565
645
|
value={{
|
|
566
646
|
baseUrl: 'https://api.sandbox.monite.com/v1',
|
|
567
|
-
async
|
|
647
|
+
async requestFn(schema, requestInfo) {
|
|
568
648
|
const token = await fetchToken();
|
|
569
649
|
|
|
570
|
-
return
|
|
571
|
-
...
|
|
650
|
+
return requestFn(schema, {
|
|
651
|
+
...requestInfo,
|
|
572
652
|
/** Specify your predefined Headers **/
|
|
573
653
|
headers: {
|
|
574
654
|
Authorization: `Bearer ${token}`,
|
package/dist/QraftContext.d.ts
CHANGED
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import type { QueryClient } from '@tanstack/react-query';
|
|
3
|
-
import type {
|
|
3
|
+
import type { OperationSchema, RequestFnPayload } from './lib/requestFn.js';
|
|
4
4
|
interface QraftContextValueBase {
|
|
5
|
-
/** The QueryClient to use in Hooks */
|
|
6
|
-
queryClient?: QueryClient;
|
|
7
|
-
/**
|
|
8
|
-
* The request client to use for making requests. Will be invoked with every request.
|
|
9
|
-
*/
|
|
10
|
-
request<T>(options: {
|
|
11
|
-
baseUrl: string;
|
|
12
|
-
}, schema: OperationRequestSchema, requestInfo: OperationRequestInfo): Promise<T>;
|
|
13
5
|
/**
|
|
14
6
|
* The base URL to use for all requests.
|
|
15
7
|
* @example 'https://api.example.com'
|
|
16
8
|
*/
|
|
17
|
-
baseUrl
|
|
9
|
+
baseUrl?: string;
|
|
10
|
+
/**
|
|
11
|
+
* The `requestFn` will be invoked with every request.
|
|
12
|
+
*/
|
|
13
|
+
requestFn<T>(requestSchema: OperationSchema, requestInfo: RequestFnPayload): Promise<T>;
|
|
14
|
+
/** The QueryClient to use in Hooks */
|
|
15
|
+
queryClient?: QueryClient;
|
|
18
16
|
}
|
|
19
17
|
export type QraftContextValue = QraftContextValueBase | undefined;
|
|
20
18
|
export declare const QraftContext: import("react").Context<QraftContextValue>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QraftContext.d.ts","sourceRoot":"","sources":["../src/QraftContext.ts"],"names":[],"mappings":";AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEzD,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"QraftContext.d.ts","sourceRoot":"","sources":["../src/QraftContext.ts"],"names":[],"mappings":";AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEzD,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAE5E,UAAU,qBAAqB;IAC7B;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,SAAS,CAAC,CAAC,EACT,aAAa,EAAE,eAAe,EAC9B,WAAW,EAAE,gBAAgB,GAC5B,OAAO,CAAC,CAAC,CAAC,CAAC;IAEd,sCAAsC;IACtC,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B;AAED,MAAM,MAAM,iBAAiB,GAAG,qBAAqB,GAAG,SAAS,CAAC;AAElE,eAAO,MAAM,YAAY,4CAA8C,CAAC"}
|
package/dist/QraftContext.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QraftContext.js","sourceRoot":"","sources":["../src/QraftContext.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"QraftContext.js","sourceRoot":"","sources":["../src/QraftContext.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AA2BtC,MAAM,CAAC,MAAM,YAAY,GAAG,aAAa,CAAoB,SAAS,CAAC,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { CancelOptions, DefaultError, FetchStatus, InfiniteData, InfiniteQueryPageParamsOptions, InvalidateOptions, Mutation, MutationState, MutationStatus, NoInfer, QueriesPlaceholderDataFunction, Query, QueryClient, RefetchOptions, ResetOptions, SetDataOptions, Updater } from '@tanstack/query-core';
|
|
1
|
+
import { CancelOptions, DefaultError, FetchStatus, InfiniteData, InfiniteQueryPageParamsOptions, InvalidateOptions, Mutation, MutationState, MutationStatus, NoInfer, QueriesPlaceholderDataFunction, Query, QueryClient, FetchQueryOptions, RefetchOptions, ResetOptions, SetDataOptions, Updater, QueryFunction, InitialPageParam, GetNextPageParamFunction } from '@tanstack/query-core';
|
|
2
2
|
import type { DefinedInitialDataInfiniteOptions, DefinedInitialDataOptions, DefinedUseInfiniteQueryResult, DefinedUseQueryResult, UndefinedInitialDataInfiniteOptions, UndefinedInitialDataOptions, UseInfiniteQueryResult, UseMutationOptions, UseMutationResult, UseQueryOptions, UseQueryResult, UseSuspenseInfiniteQueryOptions, UseSuspenseInfiniteQueryResult, UseSuspenseQueryOptions, UseSuspenseQueryResult } from '@tanstack/react-query';
|
|
3
|
+
import type { RequestFn } from './lib/requestFn.js';
|
|
3
4
|
export type ServiceOperationQueryKey<S extends {
|
|
4
5
|
url: string;
|
|
5
6
|
method: string;
|
|
@@ -14,7 +15,7 @@ export type ServiceOperationMutationKey<S extends Record<'url' | 'method', strin
|
|
|
14
15
|
export interface ServiceOperationQuery<TSchema extends {
|
|
15
16
|
url: string;
|
|
16
17
|
method: string;
|
|
17
|
-
}, TData, TParams, TError = DefaultError> extends ServiceOperationUseQuery<TSchema, TData, TParams, TError>, ServiceOperationUseQueries<TSchema, TData, TParams, TError>, ServiceOperationUseSuspenseQueries<TSchema, TData, TParams, TError>, ServiceOperationUseInfiniteQuery<TSchema, TData, TParams, TError>, ServiceOperationUseSuspenseQueryQuery<TSchema, TData, TParams, TError>, ServiceOperationUseSuspenseInfiniteQuery<TSchema, TData, TParams, TError>, ServiceOperationUseIsFetchingQueries<TSchema, TData, TParams, TError>, ServiceOperationQueryFn<TSchema, TData, TParams>, ServiceOperationGetQueryData<TSchema, TData, TParams>, ServiceOperationGetInfiniteQueryData<TSchema, TData, TParams>, ServiceOperationSetQueryData<TSchema, TData, TParams>, ServiceOperationSetInfiniteQueryData<TSchema, TData, TParams>, ServiceOperationInvalidateQueries<TSchema, TData, TParams, TError>, ServiceOperationCancelQueries<TSchema, TData, TParams, TError>, ServiceOperationResetQueries<TSchema, TData, TParams, TError>, ServiceOperationRefetchQueries<TSchema, TData, TParams, TError>, ServiceOperationIsFetchingQueries<TSchema, TData, TParams, TError> {
|
|
18
|
+
}, TData, TParams, TError = DefaultError> extends ServiceOperationUseQuery<TSchema, TData, TParams, TError>, ServiceOperationUseQueries<TSchema, TData, TParams, TError>, ServiceOperationUseSuspenseQueries<TSchema, TData, TParams, TError>, ServiceOperationUseInfiniteQuery<TSchema, TData, TParams, TError>, ServiceOperationUseSuspenseQueryQuery<TSchema, TData, TParams, TError>, ServiceOperationUseSuspenseInfiniteQuery<TSchema, TData, TParams, TError>, ServiceOperationUseIsFetchingQueries<TSchema, TData, TParams, TError>, ServiceOperationQueryFn<TSchema, TData, TParams>, ServiceOperationFetchQuery<TSchema, TData, TParams, TError>, ServiceOperationFetchInfiniteQuery<TSchema, TData, TParams, TError>, ServiceOperationGetQueryData<TSchema, TData, TParams>, ServiceOperationGetInfiniteQueryData<TSchema, TData, TParams>, ServiceOperationSetQueryData<TSchema, TData, TParams>, ServiceOperationSetInfiniteQueryData<TSchema, TData, TParams>, ServiceOperationInvalidateQueries<TSchema, TData, TParams, TError>, ServiceOperationCancelQueries<TSchema, TData, TParams, TError>, ServiceOperationRemoveQueries<TSchema, TData, TParams, TError>, ServiceOperationResetQueries<TSchema, TData, TParams, TError>, ServiceOperationRefetchQueries<TSchema, TData, TParams, TError>, ServiceOperationIsFetchingQueries<TSchema, TData, TParams, TError> {
|
|
18
19
|
schema: TSchema;
|
|
19
20
|
types: {
|
|
20
21
|
parameters: TParams;
|
|
@@ -30,6 +31,101 @@ interface ServiceOperationUseQuery<TSchema extends {
|
|
|
30
31
|
useQuery(parameters: TParams | ServiceOperationQueryKey<TSchema, TParams>, options?: Omit<UndefinedInitialDataOptions<TData, TError, TData, ServiceOperationQueryKey<TSchema, TParams>>, 'queryKey'>, queryClient?: QueryClient): UseQueryResult<TData, TError | Error>;
|
|
31
32
|
useQuery(parameters: TParams | ServiceOperationQueryKey<TSchema, TParams>, options: Omit<DefinedInitialDataOptions<TData, TError, TData, ServiceOperationQueryKey<TSchema, TParams>>, 'queryKey'>, queryClient?: QueryClient): DefinedUseQueryResult<TData, TError | Error>;
|
|
32
33
|
}
|
|
34
|
+
type FetchQueryOptionsBase<TSchema extends {
|
|
35
|
+
url: string;
|
|
36
|
+
method: string;
|
|
37
|
+
}, TData, TParams = {}, TError = DefaultError> = Omit<FetchQueryOptions<TData, TError, TData, ServiceOperationQueryKey<TSchema, TParams>>, 'queryKey' | 'queryFn'>;
|
|
38
|
+
interface FetchQueryOptionsByQueryKey<TSchema extends {
|
|
39
|
+
url: string;
|
|
40
|
+
method: string;
|
|
41
|
+
}, TData, TParams = {}, TError = DefaultError> extends FetchQueryOptionsBase<TSchema, TData, TParams, TError> {
|
|
42
|
+
/**
|
|
43
|
+
* Fetch Queries by query key
|
|
44
|
+
*/
|
|
45
|
+
queryKey?: ServiceOperationQueryKey<TSchema, TParams>;
|
|
46
|
+
}
|
|
47
|
+
interface FetchQueryOptionsByParameters<TSchema extends {
|
|
48
|
+
url: string;
|
|
49
|
+
method: string;
|
|
50
|
+
}, TData, TParams = {}, TError = DefaultError> extends FetchQueryOptionsBase<TSchema, TData, TParams, TError> {
|
|
51
|
+
/**
|
|
52
|
+
* Fetch Queries by parameters
|
|
53
|
+
*/
|
|
54
|
+
parameters?: TParams;
|
|
55
|
+
queryKey?: never;
|
|
56
|
+
}
|
|
57
|
+
type FetchQueryOptionsQueryFn<TSchema extends {
|
|
58
|
+
url: string;
|
|
59
|
+
method: string;
|
|
60
|
+
}, TData, TParams = {}> = {
|
|
61
|
+
queryFn?: QueryFunction<TData, ServiceOperationQueryKey<TSchema, TParams>>;
|
|
62
|
+
} | {
|
|
63
|
+
requestFn: RequestFn<TData>;
|
|
64
|
+
/**
|
|
65
|
+
* Base URL to use for the request (used in the `queryFn`)
|
|
66
|
+
* @example 'https://api.example.com'
|
|
67
|
+
*/
|
|
68
|
+
baseUrl: string | undefined;
|
|
69
|
+
queryFn?: never;
|
|
70
|
+
};
|
|
71
|
+
interface ServiceOperationFetchQuery<TSchema extends {
|
|
72
|
+
url: string;
|
|
73
|
+
method: string;
|
|
74
|
+
}, TData, TParams = {}, TError = DefaultError> {
|
|
75
|
+
fetchQuery(options: (FetchQueryOptionsByQueryKey<TSchema, TData, TParams, TError> & FetchQueryOptionsQueryFn<TSchema, TData, TParams>) | (FetchQueryOptionsByParameters<TSchema, TData, TParams, TError> & FetchQueryOptionsQueryFn<TSchema, TData, TParams>), queryClient: QueryClient): Promise<TData>;
|
|
76
|
+
prefetchQuery(options: (FetchQueryOptionsByQueryKey<TSchema, TData, TParams, TError> & FetchQueryOptionsQueryFn<TSchema, TData, TParams>) | (FetchQueryOptionsByParameters<TSchema, TData, TParams, TError> & FetchQueryOptionsQueryFn<TSchema, TData, TParams>), queryClient: QueryClient): Promise<void>;
|
|
77
|
+
}
|
|
78
|
+
type FetchInfiniteQueryOptionsBase<TSchema extends {
|
|
79
|
+
url: string;
|
|
80
|
+
method: string;
|
|
81
|
+
}, TData, TParams = {}, TPageParam = unknown, TError = DefaultError> = Omit<FetchQueryOptions<TData, TError, InfiniteData<TData, TPageParam>, ServiceOperationQueryKey<TSchema, TParams>, TPageParam>, 'queryKey'> & InitialPageParam<PartialParameters<TPageParam>> & FetchInfiniteQueryPages<TData, TPageParam>;
|
|
82
|
+
type FetchInfiniteQueryPages<TData = unknown, TPageParam = unknown> = {
|
|
83
|
+
pages?: never;
|
|
84
|
+
} | {
|
|
85
|
+
pages: number;
|
|
86
|
+
getNextPageParam: GetNextPageParamFunction<PartialParameters<TPageParam>, TData>;
|
|
87
|
+
};
|
|
88
|
+
type FetchInfiniteQueryOptionsByQueryKey<TSchema extends {
|
|
89
|
+
url: string;
|
|
90
|
+
method: string;
|
|
91
|
+
}, TData, TParams = {}, TPageParam = {}, TError = DefaultError> = FetchInfiniteQueryOptionsBase<TSchema, TData, TParams, TPageParam, TError> & {
|
|
92
|
+
/**
|
|
93
|
+
* Fetch Queries by query key
|
|
94
|
+
*/
|
|
95
|
+
queryKey?: ServiceOperationInfiniteQueryKey<TSchema, TParams>;
|
|
96
|
+
parameters?: never;
|
|
97
|
+
};
|
|
98
|
+
type FetchInfiniteQueryOptionsByParameters<TSchema extends {
|
|
99
|
+
url: string;
|
|
100
|
+
method: string;
|
|
101
|
+
}, TData, TParams = {}, TPageParam = {}, TError = DefaultError> = FetchInfiniteQueryOptionsBase<TSchema, TData, TParams, TPageParam, TError> & {
|
|
102
|
+
/**
|
|
103
|
+
* Fetch Queries by parameters
|
|
104
|
+
*/
|
|
105
|
+
parameters?: TParams;
|
|
106
|
+
queryKey?: never;
|
|
107
|
+
};
|
|
108
|
+
type FetchInfiniteQueryOptionsQueryFn<TSchema extends {
|
|
109
|
+
url: string;
|
|
110
|
+
method: string;
|
|
111
|
+
}, TData, TParams = {}> = {
|
|
112
|
+
queryFn?: QueryFunction<TData, ServiceOperationInfiniteQueryKey<TSchema, TParams>>;
|
|
113
|
+
} | {
|
|
114
|
+
requestFn: RequestFn<TData>;
|
|
115
|
+
/**
|
|
116
|
+
* Base URL to use for the request (used in the `queryFn`)
|
|
117
|
+
* @example 'https://api.example.com'
|
|
118
|
+
*/
|
|
119
|
+
baseUrl: string | undefined;
|
|
120
|
+
queryFn?: never;
|
|
121
|
+
};
|
|
122
|
+
interface ServiceOperationFetchInfiniteQuery<TSchema extends {
|
|
123
|
+
url: string;
|
|
124
|
+
method: string;
|
|
125
|
+
}, TData, TParams = {}, TError = DefaultError> {
|
|
126
|
+
fetchInfiniteQuery<TPageParam extends TParams>(options: (FetchInfiniteQueryOptionsByQueryKey<TSchema, TData, TParams, TPageParam, TError> & FetchInfiniteQueryOptionsQueryFn<TSchema, TData, TParams>) | (FetchInfiniteQueryOptionsByParameters<TSchema, TData, TParams, TPageParam, TError> & FetchInfiniteQueryOptionsQueryFn<TSchema, TData, TParams>), queryClient: QueryClient): Promise<InfiniteData<TData, TPageParam>>;
|
|
127
|
+
prefetchInfiniteQuery<TPageParam extends TParams>(options: (FetchInfiniteQueryOptionsByQueryKey<TSchema, TData, TParams, TPageParam, TError> & FetchInfiniteQueryOptionsQueryFn<TSchema, TData, TParams>) | (FetchInfiniteQueryOptionsByParameters<TSchema, TData, TParams, TPageParam, TError> & FetchInfiniteQueryOptionsQueryFn<TSchema, TData, TParams>), queryClient: QueryClient): Promise<void>;
|
|
128
|
+
}
|
|
33
129
|
interface ServiceOperationUseQueries<TSchema extends {
|
|
34
130
|
url: string;
|
|
35
131
|
method: string;
|
|
@@ -39,6 +135,7 @@ interface ServiceOperationUseQueries<TSchema extends {
|
|
|
39
135
|
placeholderData?: TData | QueriesPlaceholderDataFunction<TData>;
|
|
40
136
|
} & ({
|
|
41
137
|
parameters: TParams;
|
|
138
|
+
queryKey?: never;
|
|
42
139
|
} | {
|
|
43
140
|
queryKey: ServiceOperationQueryKey<TSchema, TParams>;
|
|
44
141
|
})>;
|
|
@@ -129,6 +226,22 @@ export interface ServiceOperationCancelQueriesCallback<TSchema extends {
|
|
|
129
226
|
}, TData, TParams = {}, TError = DefaultError> extends ServiceOperationCancelQueries<TSchema, TData, TParams, TError> {
|
|
130
227
|
cancelQueries(filters: QueryFiltersByParameters<TSchema, TData, TParams, TError> | QueryFiltersByQueryKey<TSchema, TData, TParams, TError> | QueryClient, options?: CancelOptions | QueryClient, queryClient?: QueryClient): Promise<void>;
|
|
131
228
|
}
|
|
229
|
+
interface ServiceOperationRemoveQueries<TSchema extends {
|
|
230
|
+
url: string;
|
|
231
|
+
method: string;
|
|
232
|
+
}, TData, TParams = {}, TError = DefaultError> {
|
|
233
|
+
removeQueries(filters: QueryFiltersByParameters<TSchema, TData, TParams, TError> | QueryFiltersByQueryKey<TSchema, TData, TParams, TError>, queryClient: QueryClient): void;
|
|
234
|
+
removeQueries(queryClient: QueryClient): void;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* @internal
|
|
238
|
+
*/
|
|
239
|
+
export interface ServiceOperationRemoveQueriesCallback<TSchema extends {
|
|
240
|
+
url: string;
|
|
241
|
+
method: string;
|
|
242
|
+
}, TData, TParams = {}, TError = DefaultError> extends ServiceOperationRemoveQueries<TSchema, TData, TParams, TError> {
|
|
243
|
+
removeQueries(filters: QueryFiltersByParameters<TSchema, TData, TParams, TError> | QueryFiltersByQueryKey<TSchema, TData, TParams, TError> | QueryClient, queryClient?: QueryClient): void;
|
|
244
|
+
}
|
|
132
245
|
interface ServiceOperationResetQueries<TSchema extends {
|
|
133
246
|
url: string;
|
|
134
247
|
method: string;
|
|
@@ -192,6 +305,7 @@ interface ServiceOperationUseSuspenseQueries<TSchema extends {
|
|
|
192
305
|
useSuspenseQueries<TCombinedResult = Array<UseSuspenseQueryResult<TData, TError>>>(options: {
|
|
193
306
|
queries: ReadonlyArray<Omit<UseSuspenseQueryOptions<TData, TError, TData, ServiceOperationQueryKey<TSchema, TParams>>, 'queryKey'> & ({
|
|
194
307
|
parameters: TParams;
|
|
308
|
+
queryKey?: never;
|
|
195
309
|
} | {
|
|
196
310
|
queryKey: ServiceOperationQueryKey<TSchema, TParams>;
|
|
197
311
|
})>;
|
|
@@ -221,7 +335,7 @@ interface ServiceOperationUseSuspenseQueryQuery<TSchema extends {
|
|
|
221
335
|
export interface ServiceOperationMutation<TSchema extends {
|
|
222
336
|
url: string;
|
|
223
337
|
method: string;
|
|
224
|
-
}, TBody, TData, TParams, TError = DefaultError> extends ServiceOperationUseMutation<TSchema, TBody, TData, TParams, TError>, ServiceOperationUseMutationState<TSchema, TBody, TData, TParams, TError>, ServiceOperationMutationFn<TSchema, TBody, TData, TParams> {
|
|
338
|
+
}, TBody, TData, TParams, TError = DefaultError> extends ServiceOperationUseMutation<TSchema, TBody, TData, TParams, TError>, ServiceOperationUseIsMutating<TSchema, TBody, TData, TParams, TError>, ServiceOperationUseMutationState<TSchema, TBody, TData, TParams, TError>, ServiceOperationIsMutatingQueries<TSchema, TData, TParams, TError>, ServiceOperationMutationFn<TSchema, TBody, TData, TParams> {
|
|
225
339
|
schema: TSchema;
|
|
226
340
|
types: {
|
|
227
341
|
parameters: TParams;
|
|
@@ -234,7 +348,7 @@ interface ServiceOperationUseMutation<TSchema extends {
|
|
|
234
348
|
url: string;
|
|
235
349
|
method: string;
|
|
236
350
|
}, TBody, TData, TParams, TError = DefaultError> {
|
|
237
|
-
getMutationKey<TMutationKeyParams extends TParams>(parameters
|
|
351
|
+
getMutationKey<TMutationKeyParams extends TParams | undefined = undefined>(parameters?: TMutationKeyParams): ServiceOperationMutationKey<TSchema, TMutationKeyParams>;
|
|
238
352
|
useMutation<TVariables extends MutationVariables<TBody, TParams>, TContext = unknown>(parameters?: undefined, options?: Omit<UseMutationOptions<TData, TError, TVariables, TContext>, 'mutationKey'> & {
|
|
239
353
|
mutationKey?: ServiceOperationMutationKey<TSchema, TParams>;
|
|
240
354
|
}, queryClient?: QueryClient): UseMutationResult<TData, TError | Error, TVariables, TContext>;
|
|
@@ -281,12 +395,19 @@ interface ServiceOperationUseMutationState<TSchema extends {
|
|
|
281
395
|
select?: (mutation: Mutation<TData, TError, MutationVariables<TBody, TParams>, TContext>) => TResult;
|
|
282
396
|
}, queryClient?: QueryClient): Array<TResult>;
|
|
283
397
|
}
|
|
398
|
+
interface ServiceOperationUseIsMutating<TSchema extends {
|
|
399
|
+
url: string;
|
|
400
|
+
method: string;
|
|
401
|
+
}, TBody, TData, TParams, TError = DefaultError> {
|
|
402
|
+
useIsMutating<TContext = unknown>(filters?: UseMutationStateFiltersByParameters<TBody, TData, TParams, TError, TContext> | UseMutationStateFiltersByMutationKey<TSchema, TBody, TData, TParams, TError, TContext>, queryClient?: QueryClient): number;
|
|
403
|
+
}
|
|
284
404
|
interface QueryFnOptionsBase<TMeta extends Record<string, any>, TSignal extends AbortSignal = AbortSignal> {
|
|
285
405
|
signal?: TSignal;
|
|
286
406
|
meta?: TMeta;
|
|
287
407
|
}
|
|
288
408
|
interface QueryFnOptionsByParameters<TParams, TMeta extends Record<string, any>, TSignal extends AbortSignal = AbortSignal> extends QueryFnOptionsBase<TMeta, TSignal> {
|
|
289
409
|
parameters: TParams;
|
|
410
|
+
queryKey?: never;
|
|
290
411
|
}
|
|
291
412
|
interface QueryFnOptionsByQueryKey<TSchema extends {
|
|
292
413
|
url: string;
|
|
@@ -313,7 +434,17 @@ interface ServiceOperationSetQueryData<TSchema extends {
|
|
|
313
434
|
url: string;
|
|
314
435
|
method: string;
|
|
315
436
|
}, TData, TParams = {}> {
|
|
316
|
-
setQueryData(parameters: TParams | ServiceOperationQueryKey<TSchema, TParams>, updater: Updater<NoInfer<TData> | undefined, NoInfer<TData> | undefined>,
|
|
437
|
+
setQueryData(parameters: TParams | ServiceOperationQueryKey<TSchema, TParams>, updater: Updater<NoInfer<TData> | undefined, NoInfer<TData> | undefined>, options: SetDataOptions, queryClient: QueryClient): TData | undefined;
|
|
438
|
+
setQueryData(parameters: TParams | ServiceOperationQueryKey<TSchema, TParams>, updater: Updater<NoInfer<TData> | undefined, NoInfer<TData> | undefined>, queryClient: QueryClient): TData | undefined;
|
|
439
|
+
}
|
|
440
|
+
/**
|
|
441
|
+
* @internal
|
|
442
|
+
*/
|
|
443
|
+
export interface ServiceOperationSetQueryDataCallback<TSchema extends {
|
|
444
|
+
url: string;
|
|
445
|
+
method: string;
|
|
446
|
+
}, TData, TParams = {}> extends ServiceOperationSetQueryData<TSchema, TData, TParams> {
|
|
447
|
+
setQueryData(parameters: TParams | ServiceOperationQueryKey<TSchema, TParams>, updater: Updater<NoInfer<TData> | undefined, NoInfer<TData> | undefined>, options: SetDataOptions | QueryClient, queryClient?: QueryClient): TData | undefined;
|
|
317
448
|
}
|
|
318
449
|
interface ServiceOperationSetInfiniteQueryData<TSchema extends {
|
|
319
450
|
url: string;
|
|
@@ -352,6 +483,22 @@ export interface ServiceOperationMutationFn<TSchema extends {
|
|
|
352
483
|
body: TBody;
|
|
353
484
|
}): Promise<TData>;
|
|
354
485
|
}
|
|
486
|
+
interface ServiceOperationIsMutatingQueries<TSchema extends {
|
|
487
|
+
url: string;
|
|
488
|
+
method: string;
|
|
489
|
+
}, TData, TParams = {}, TError = DefaultError> {
|
|
490
|
+
isMutating(filters: QueryFiltersByParameters<TSchema, TData, TParams, TError> | QueryFiltersByQueryKey<TSchema, TData, TParams, TError>, queryClient: QueryClient): number;
|
|
491
|
+
isMutating(queryClient: QueryClient): number;
|
|
492
|
+
}
|
|
493
|
+
/**
|
|
494
|
+
* @internal
|
|
495
|
+
*/
|
|
496
|
+
export interface ServiceOperationIsMutatingQueriesCallback<TSchema extends {
|
|
497
|
+
url: string;
|
|
498
|
+
method: string;
|
|
499
|
+
}, TData, TParams = {}, TError = DefaultError> extends ServiceOperationIsMutatingQueries<TSchema, TData, TParams, TError> {
|
|
500
|
+
isMutating(filters: QueryFiltersByParameters<TSchema, TData, TParams, TError> | QueryFiltersByQueryKey<TSchema, TData, TParams, TError> | QueryClient, queryClient?: QueryClient): number;
|
|
501
|
+
}
|
|
355
502
|
/**
|
|
356
503
|
* Shallow partial 'parameters'.
|
|
357
504
|
* @example
|