@trackunit/react-graphql-hooks 1.7.24 → 1.7.26
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/index.cjs.js +31 -50
- package/index.esm.js +31 -31
- package/package.json +5 -5
- package/src/useLazyQuery.d.ts +4 -4
- package/src/usePaginationQuery.d.ts +4 -4
- package/src/usePaginationQuery.demo.d.ts +4 -4
- package/src/useQuery.d.ts +5 -5
package/index.cjs.js
CHANGED
|
@@ -3,29 +3,10 @@
|
|
|
3
3
|
require('react/jsx-runtime');
|
|
4
4
|
var i18nLibraryTranslation = require('@trackunit/i18n-library-translation');
|
|
5
5
|
var sharedUtils = require('@trackunit/shared-utils');
|
|
6
|
-
var
|
|
6
|
+
var client = require('@apollo/client');
|
|
7
|
+
var esToolkit = require('es-toolkit');
|
|
7
8
|
var react = require('react');
|
|
8
9
|
var reactComponents = require('@trackunit/react-components');
|
|
9
|
-
var esToolkit = require('es-toolkit');
|
|
10
|
-
|
|
11
|
-
function _interopNamespaceDefault(e) {
|
|
12
|
-
var n = Object.create(null);
|
|
13
|
-
if (e) {
|
|
14
|
-
Object.keys(e).forEach(function (k) {
|
|
15
|
-
if (k !== 'default') {
|
|
16
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
17
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
18
|
-
enumerable: true,
|
|
19
|
-
get: function () { return e[k]; }
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
n.default = e;
|
|
25
|
-
return Object.freeze(n);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
var ApolloClient__namespace = /*#__PURE__*/_interopNamespaceDefault(ApolloClient);
|
|
29
10
|
|
|
30
11
|
var defaultTranslations = {
|
|
31
12
|
|
|
@@ -117,14 +98,15 @@ const unionEdgesByNodeKey = (key, previousEdges, newEdges) => {
|
|
|
117
98
|
* @param options The lazy query options including stableData and showLoadingDuringPolling flags
|
|
118
99
|
* @returns {Array} A tuple with the execute function and query result with stable data behavior and optional polling loading state
|
|
119
100
|
*/
|
|
120
|
-
const useLazyQuery = (document, options
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
101
|
+
const useLazyQuery = (document, options) => {
|
|
102
|
+
const [executeQuery, result] = client.useLazyQuery(document, {
|
|
103
|
+
...esToolkit.omit(options ?? {}, ["notifyOnNetworkStatusChange", "stableData", "showLoadingDuringPolling"]),
|
|
104
|
+
notifyOnNetworkStatusChange: true,
|
|
105
|
+
});
|
|
106
|
+
const { stableData, showLoadingDuringPolling } = react.useMemo(() => ({
|
|
107
|
+
stableData: options?.stableData ?? true,
|
|
108
|
+
showLoadingDuringPolling: options?.showLoadingDuringPolling ?? true,
|
|
109
|
+
}), [options?.stableData, options?.showLoadingDuringPolling]);
|
|
128
110
|
const enhancedResult = react.useMemo(() => {
|
|
129
111
|
const baseResult = stableData
|
|
130
112
|
? {
|
|
@@ -134,15 +116,15 @@ const useLazyQuery = (document, options = {}) => {
|
|
|
134
116
|
: result;
|
|
135
117
|
// If showLoadingDuringPolling is enabled, check for polling network status
|
|
136
118
|
if (showLoadingDuringPolling) {
|
|
137
|
-
const isPolling = result.networkStatus ===
|
|
119
|
+
const isPolling = result.networkStatus === client.NetworkStatus.poll;
|
|
138
120
|
return {
|
|
139
121
|
...baseResult,
|
|
140
122
|
loading: baseResult.loading || isPolling,
|
|
141
123
|
};
|
|
142
124
|
}
|
|
143
125
|
return baseResult;
|
|
144
|
-
}, [result,
|
|
145
|
-
return [executeQuery, enhancedResult];
|
|
126
|
+
}, [result, showLoadingDuringPolling, stableData]);
|
|
127
|
+
return react.useMemo(() => [executeQuery, enhancedResult], [executeQuery, enhancedResult]);
|
|
146
128
|
};
|
|
147
129
|
|
|
148
130
|
/**
|
|
@@ -186,7 +168,7 @@ const useLazyQuery = (document, options = {}) => {
|
|
|
186
168
|
* @param {PaginationQueryProps<TData, TVariables>} props - The properties for configuring the query. This includes the `updateQuery` function for merging new and existing data, and options for pagination such as `pageSize`. Also includes other lazy query hook options from Apollo Client.
|
|
187
169
|
* @returns {*} {PaginationQuery}
|
|
188
170
|
*/
|
|
189
|
-
const usePaginationQuery = (document,
|
|
171
|
+
const usePaginationQuery = (document, props) => {
|
|
190
172
|
const [lastFetchedData, setLastFetchedData] = react.useState();
|
|
191
173
|
const [resetTrigger, setResetTrigger] = react.useState(0);
|
|
192
174
|
const [abortController, setAbortController] = react.useState(new AbortController());
|
|
@@ -232,7 +214,7 @@ const usePaginationQuery = (document, { ...props }) => {
|
|
|
232
214
|
pollInterval: internalProps.pollInterval,
|
|
233
215
|
notifyOnNetworkStatusChange: true, // Needed to update networkStatus
|
|
234
216
|
onCompleted: completedData => {
|
|
235
|
-
if (networkStatus ===
|
|
217
|
+
if (networkStatus === client.NetworkStatus.refetch) {
|
|
236
218
|
// trigger reset for refetchQueries for the provided document.
|
|
237
219
|
setResetTrigger(prev => prev + 1);
|
|
238
220
|
}
|
|
@@ -409,27 +391,26 @@ const usePaginationQuery = (document, { ...props }) => {
|
|
|
409
391
|
* @param options The query options including stableData and showLoadingDuringPolling flags
|
|
410
392
|
* @returns {object} The query result with stable data behavior and optional polling loading state
|
|
411
393
|
*/
|
|
412
|
-
const useQuery = (document, options
|
|
413
|
-
const
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
394
|
+
const useQuery = (document, options) => {
|
|
395
|
+
const result = client.useQuery(document, {
|
|
396
|
+
...esToolkit.omit(options ?? {}, ["notifyOnNetworkStatusChange", "stableData", "showLoadingDuringPolling"]),
|
|
397
|
+
notifyOnNetworkStatusChange: options?.notifyOnNetworkStatusChange ?? true,
|
|
398
|
+
});
|
|
399
|
+
const { stableData, showLoadingDuringPolling } = react.useMemo(() => ({
|
|
400
|
+
stableData: options?.stableData ?? true,
|
|
401
|
+
showLoadingDuringPolling: options?.showLoadingDuringPolling ?? true,
|
|
402
|
+
}), [options?.stableData, options?.showLoadingDuringPolling]);
|
|
420
403
|
return react.useMemo(() => {
|
|
421
|
-
const baseResult =
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
}
|
|
426
|
-
: result;
|
|
404
|
+
const baseResult = {
|
|
405
|
+
...result,
|
|
406
|
+
data: stableData ? (result.data ?? result.previousData) : result.data,
|
|
407
|
+
};
|
|
427
408
|
// If showLoadingDuringPolling is enabled, check for polling network status
|
|
428
409
|
if (showLoadingDuringPolling) {
|
|
429
|
-
const isPolling = result.networkStatus ===
|
|
410
|
+
const isPolling = result.networkStatus === client.NetworkStatus.poll;
|
|
430
411
|
return {
|
|
431
412
|
...baseResult,
|
|
432
|
-
loading:
|
|
413
|
+
loading: result.loading || isPolling,
|
|
433
414
|
};
|
|
434
415
|
}
|
|
435
416
|
return baseResult;
|
package/index.esm.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import 'react/jsx-runtime';
|
|
2
2
|
import { registerTranslations } from '@trackunit/i18n-library-translation';
|
|
3
3
|
import { truthy, objectKeys } from '@trackunit/shared-utils';
|
|
4
|
-
import
|
|
4
|
+
import { useLazyQuery as useLazyQuery$1, NetworkStatus, useQuery as useQuery$1 } from '@apollo/client';
|
|
5
|
+
import { omit, isEqual } from 'es-toolkit';
|
|
5
6
|
import { useMemo, useState, useRef, useEffect, useCallback } from 'react';
|
|
6
7
|
import { useRelayPagination, defaultPageSize } from '@trackunit/react-components';
|
|
7
|
-
import { isEqual } from 'es-toolkit';
|
|
8
8
|
|
|
9
9
|
var defaultTranslations = {
|
|
10
10
|
|
|
@@ -96,14 +96,15 @@ const unionEdgesByNodeKey = (key, previousEdges, newEdges) => {
|
|
|
96
96
|
* @param options The lazy query options including stableData and showLoadingDuringPolling flags
|
|
97
97
|
* @returns {Array} A tuple with the execute function and query result with stable data behavior and optional polling loading state
|
|
98
98
|
*/
|
|
99
|
-
const useLazyQuery = (document, options
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
99
|
+
const useLazyQuery = (document, options) => {
|
|
100
|
+
const [executeQuery, result] = useLazyQuery$1(document, {
|
|
101
|
+
...omit(options ?? {}, ["notifyOnNetworkStatusChange", "stableData", "showLoadingDuringPolling"]),
|
|
102
|
+
notifyOnNetworkStatusChange: true,
|
|
103
|
+
});
|
|
104
|
+
const { stableData, showLoadingDuringPolling } = useMemo(() => ({
|
|
105
|
+
stableData: options?.stableData ?? true,
|
|
106
|
+
showLoadingDuringPolling: options?.showLoadingDuringPolling ?? true,
|
|
107
|
+
}), [options?.stableData, options?.showLoadingDuringPolling]);
|
|
107
108
|
const enhancedResult = useMemo(() => {
|
|
108
109
|
const baseResult = stableData
|
|
109
110
|
? {
|
|
@@ -113,15 +114,15 @@ const useLazyQuery = (document, options = {}) => {
|
|
|
113
114
|
: result;
|
|
114
115
|
// If showLoadingDuringPolling is enabled, check for polling network status
|
|
115
116
|
if (showLoadingDuringPolling) {
|
|
116
|
-
const isPolling = result.networkStatus ===
|
|
117
|
+
const isPolling = result.networkStatus === NetworkStatus.poll;
|
|
117
118
|
return {
|
|
118
119
|
...baseResult,
|
|
119
120
|
loading: baseResult.loading || isPolling,
|
|
120
121
|
};
|
|
121
122
|
}
|
|
122
123
|
return baseResult;
|
|
123
|
-
}, [result,
|
|
124
|
-
return [executeQuery, enhancedResult];
|
|
124
|
+
}, [result, showLoadingDuringPolling, stableData]);
|
|
125
|
+
return useMemo(() => [executeQuery, enhancedResult], [executeQuery, enhancedResult]);
|
|
125
126
|
};
|
|
126
127
|
|
|
127
128
|
/**
|
|
@@ -165,7 +166,7 @@ const useLazyQuery = (document, options = {}) => {
|
|
|
165
166
|
* @param {PaginationQueryProps<TData, TVariables>} props - The properties for configuring the query. This includes the `updateQuery` function for merging new and existing data, and options for pagination such as `pageSize`. Also includes other lazy query hook options from Apollo Client.
|
|
166
167
|
* @returns {*} {PaginationQuery}
|
|
167
168
|
*/
|
|
168
|
-
const usePaginationQuery = (document,
|
|
169
|
+
const usePaginationQuery = (document, props) => {
|
|
169
170
|
const [lastFetchedData, setLastFetchedData] = useState();
|
|
170
171
|
const [resetTrigger, setResetTrigger] = useState(0);
|
|
171
172
|
const [abortController, setAbortController] = useState(new AbortController());
|
|
@@ -211,7 +212,7 @@ const usePaginationQuery = (document, { ...props }) => {
|
|
|
211
212
|
pollInterval: internalProps.pollInterval,
|
|
212
213
|
notifyOnNetworkStatusChange: true, // Needed to update networkStatus
|
|
213
214
|
onCompleted: completedData => {
|
|
214
|
-
if (networkStatus ===
|
|
215
|
+
if (networkStatus === NetworkStatus.refetch) {
|
|
215
216
|
// trigger reset for refetchQueries for the provided document.
|
|
216
217
|
setResetTrigger(prev => prev + 1);
|
|
217
218
|
}
|
|
@@ -388,27 +389,26 @@ const usePaginationQuery = (document, { ...props }) => {
|
|
|
388
389
|
* @param options The query options including stableData and showLoadingDuringPolling flags
|
|
389
390
|
* @returns {object} The query result with stable data behavior and optional polling loading state
|
|
390
391
|
*/
|
|
391
|
-
const useQuery = (document, options
|
|
392
|
-
const
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
392
|
+
const useQuery = (document, options) => {
|
|
393
|
+
const result = useQuery$1(document, {
|
|
394
|
+
...omit(options ?? {}, ["notifyOnNetworkStatusChange", "stableData", "showLoadingDuringPolling"]),
|
|
395
|
+
notifyOnNetworkStatusChange: options?.notifyOnNetworkStatusChange ?? true,
|
|
396
|
+
});
|
|
397
|
+
const { stableData, showLoadingDuringPolling } = useMemo(() => ({
|
|
398
|
+
stableData: options?.stableData ?? true,
|
|
399
|
+
showLoadingDuringPolling: options?.showLoadingDuringPolling ?? true,
|
|
400
|
+
}), [options?.stableData, options?.showLoadingDuringPolling]);
|
|
399
401
|
return useMemo(() => {
|
|
400
|
-
const baseResult =
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
}
|
|
405
|
-
: result;
|
|
402
|
+
const baseResult = {
|
|
403
|
+
...result,
|
|
404
|
+
data: stableData ? (result.data ?? result.previousData) : result.data,
|
|
405
|
+
};
|
|
406
406
|
// If showLoadingDuringPolling is enabled, check for polling network status
|
|
407
407
|
if (showLoadingDuringPolling) {
|
|
408
|
-
const isPolling = result.networkStatus ===
|
|
408
|
+
const isPolling = result.networkStatus === NetworkStatus.poll;
|
|
409
409
|
return {
|
|
410
410
|
...baseResult,
|
|
411
|
-
loading:
|
|
411
|
+
loading: result.loading || isPolling,
|
|
412
412
|
};
|
|
413
413
|
}
|
|
414
414
|
return baseResult;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/react-graphql-hooks",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.26",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"engines": {
|
|
@@ -9,11 +9,11 @@
|
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"@apollo/client": "3.13.8",
|
|
11
11
|
"react": "19.0.0",
|
|
12
|
-
"@trackunit/i18n-library-translation": "1.7.
|
|
13
|
-
"@trackunit/shared-utils": "1.9.
|
|
14
|
-
"@trackunit/react-test-setup": "1.4.
|
|
12
|
+
"@trackunit/i18n-library-translation": "1.7.20",
|
|
13
|
+
"@trackunit/shared-utils": "1.9.16",
|
|
14
|
+
"@trackunit/react-test-setup": "1.4.16",
|
|
15
15
|
"es-toolkit": "^1.39.10",
|
|
16
|
-
"@trackunit/react-components": "1.9.
|
|
16
|
+
"@trackunit/react-components": "1.9.26"
|
|
17
17
|
},
|
|
18
18
|
"module": "./index.esm.js",
|
|
19
19
|
"main": "./index.cjs.js",
|
package/src/useLazyQuery.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
type TypedDocumentNode<TData, TVariables> =
|
|
3
|
-
export interface LazyQueryProps<TData, TVariables extends
|
|
1
|
+
import { LazyQueryExecFunction as ApolloLazyQueryExecFunction, LazyQueryHookOptions as ApolloLazyQueryHookOptions, LazyQueryResult as ApolloLazyQueryResult, OperationVariables as ApolloOperationVariables, TypedDocumentNode as ApolloTypedDocumentNode } from "@apollo/client";
|
|
2
|
+
type TypedDocumentNode<TData, TVariables> = ApolloTypedDocumentNode<TData, TVariables>;
|
|
3
|
+
export interface LazyQueryProps<TData, TVariables extends ApolloOperationVariables = ApolloOperationVariables> extends ApolloLazyQueryHookOptions<TData, TVariables> {
|
|
4
4
|
/**
|
|
5
5
|
* A boolean value that specifies whether to return stable data (data || previousData).
|
|
6
6
|
* When true, the hook will return the current data if available, otherwise the previous data.
|
|
@@ -41,5 +41,5 @@ export interface LazyQueryProps<TData, TVariables extends ApolloClient.Operation
|
|
|
41
41
|
* @param options The lazy query options including stableData and showLoadingDuringPolling flags
|
|
42
42
|
* @returns {Array} A tuple with the execute function and query result with stable data behavior and optional polling loading state
|
|
43
43
|
*/
|
|
44
|
-
export declare const useLazyQuery: <TData, TVariables extends
|
|
44
|
+
export declare const useLazyQuery: <TData, TVariables extends ApolloOperationVariables = ApolloOperationVariables>(document: TypedDocumentNode<TData, TVariables>, options?: LazyQueryProps<NoInfer<TData>, NoInfer<TVariables>>) => [ApolloLazyQueryExecFunction<TData, TVariables>, ApolloLazyQueryResult<TData, TVariables>];
|
|
45
45
|
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { LazyQueryHookOptions as ApolloLazyQueryHookOptions, OperationVariables as ApolloOperationVariables, TypedDocumentNode as ApolloTypedDocumentNode } from "@apollo/client";
|
|
2
2
|
import { RelayPageInfo, RelayTableSupport } from "@trackunit/react-components";
|
|
3
3
|
/**
|
|
4
4
|
* This type is used to return the data from the query, the pagination object and the last fetched data.
|
|
@@ -11,8 +11,8 @@ export type PaginationQuery<TData> = {
|
|
|
11
11
|
previousData: TData | undefined;
|
|
12
12
|
reset: () => void;
|
|
13
13
|
};
|
|
14
|
-
type TypedDocumentNode<TData, TVariables> =
|
|
15
|
-
export interface PaginationQueryProps<TData, TVariables extends
|
|
14
|
+
type TypedDocumentNode<TData, TVariables> = ApolloTypedDocumentNode<TData, TVariables>;
|
|
15
|
+
export interface PaginationQueryProps<TData, TVariables extends ApolloOperationVariables = ApolloOperationVariables> extends ApolloLazyQueryHookOptions<TData, TVariables> {
|
|
16
16
|
/**
|
|
17
17
|
* A function that is used to update the query results with new data.
|
|
18
18
|
*
|
|
@@ -76,5 +76,5 @@ export interface PaginationQueryProps<TData, TVariables extends ApolloClient.Ope
|
|
|
76
76
|
* @param {PaginationQueryProps<TData, TVariables>} props - The properties for configuring the query. This includes the `updateQuery` function for merging new and existing data, and options for pagination such as `pageSize`. Also includes other lazy query hook options from Apollo Client.
|
|
77
77
|
* @returns {*} {PaginationQuery}
|
|
78
78
|
*/
|
|
79
|
-
export declare const usePaginationQuery: <TData, TVariables extends
|
|
79
|
+
export declare const usePaginationQuery: <TData, TVariables extends ApolloOperationVariables>(document: TypedDocumentNode<TData, TVariables>, props: PaginationQueryProps<TData, TVariables>) => PaginationQuery<TData>;
|
|
80
80
|
export {};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { OperationVariables, TypedDocumentNode } from "@apollo/client";
|
|
2
2
|
import { PaginationQueryProps } from "./usePaginationQuery";
|
|
3
|
-
export interface UsePaginationQueryDemoComponentProps<TData, TVariables extends
|
|
4
|
-
document:
|
|
3
|
+
export interface UsePaginationQueryDemoComponentProps<TData, TVariables extends OperationVariables> extends PaginationQueryProps<TData, TVariables> {
|
|
4
|
+
document: TypedDocumentNode<TData, TVariables>;
|
|
5
5
|
}
|
|
6
6
|
/**
|
|
7
7
|
* The `usePaginationQuery` Hook provides pagination when fetching data
|
|
8
8
|
*
|
|
9
9
|
* It returns an object containing methods and values related to pagination.
|
|
10
10
|
*/
|
|
11
|
-
export declare const UsePaginationQueryDemoComponent: <TData, TVariables extends
|
|
11
|
+
export declare const UsePaginationQueryDemoComponent: <TData, TVariables extends OperationVariables>({ document, variables, pageSize, updateQuery, }: UsePaginationQueryDemoComponentProps<TData, TVariables>) => import("react/jsx-runtime").JSX.Element;
|
package/src/useQuery.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
type TypedDocumentNode<TData, TVariables> =
|
|
3
|
-
export
|
|
1
|
+
import { OperationVariables as ApolloOperationVariables, QueryHookOptions as ApolloQueryHookOptions, QueryResult as ApolloQueryResult, TypedDocumentNode as ApolloTypedDocumentNode } from "@apollo/client";
|
|
2
|
+
export type TypedDocumentNode<TData, TVariables> = ApolloTypedDocumentNode<TData, TVariables>;
|
|
3
|
+
export type OperationVariables = ApolloOperationVariables;
|
|
4
|
+
export interface QueryProps<TData, TVariables extends ApolloOperationVariables = ApolloOperationVariables> extends ApolloQueryHookOptions<TData, TVariables> {
|
|
4
5
|
/**
|
|
5
6
|
* A boolean value that specifies whether to return stable data (data || previousData).
|
|
6
7
|
* When true, the hook will return the current data if available, otherwise the previous data.
|
|
@@ -43,5 +44,4 @@ export interface QueryProps<TData, TVariables extends ApolloClient.OperationVari
|
|
|
43
44
|
* @param options The query options including stableData and showLoadingDuringPolling flags
|
|
44
45
|
* @returns {object} The query result with stable data behavior and optional polling loading state
|
|
45
46
|
*/
|
|
46
|
-
export declare const useQuery: <TData, TVariables extends
|
|
47
|
-
export {};
|
|
47
|
+
export declare const useQuery: <TData, TVariables extends ApolloOperationVariables = ApolloOperationVariables>(document: TypedDocumentNode<TData, TVariables>, options?: QueryProps<NoInfer<TData>, NoInfer<TVariables>>) => ApolloQueryResult<TData, TVariables>;
|