@txo/service-graphql-react 2.4.1 → 2.5.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
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## [2.5.0](https://github.com/technology-studio/service-graphql-react/compare/v2.4.1...v2.5.0) (2024-02-28)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* add fetchMore fetching ([#658](https://github.com/technology-studio/service-graphql-react/issues/658)) ([1648a6f](https://github.com/technology-studio/service-graphql-react/commit/1648a6fa1ab1e8df0192a5450ce79dec5c279950))
|
|
7
|
+
|
|
1
8
|
## [2.4.1](https://github.com/technology-studio/service-graphql-react/compare/v2.4.0...v2.4.1) (2024-02-26)
|
|
2
9
|
|
|
3
10
|
|
|
@@ -10,6 +10,7 @@ export type QueryServiceProp<ATTRIBUTES extends OperationVariables, DATA, MAPPED
|
|
|
10
10
|
query: QueryResult<DATA, ATTRIBUTES>;
|
|
11
11
|
promiselessRefetch: (variables?: Partial<ATTRIBUTES>) => void;
|
|
12
12
|
fetchMore: QueryResult<DATA, ATTRIBUTES>['fetchMore'];
|
|
13
|
+
fetchMoreFetching: boolean;
|
|
13
14
|
};
|
|
14
15
|
type QueryOptions<DATA, ATTRIBUTES extends OperationVariables, DATA_PATH extends string> = {
|
|
15
16
|
options?: QueryHookOptions<DATA, ATTRIBUTES>;
|
|
@@ -35,6 +35,7 @@ const useServiceQuery = (queryDocument, options) => {
|
|
|
35
35
|
const query = (0, client_1.useQuery)(queryDocument, queryOptions);
|
|
36
36
|
const shownExceptionListRef = (0, react_1.useRef)([]);
|
|
37
37
|
const { addServiceErrorException, removeServiceErrorException, } = (0, react_1.useContext)(service_error_handler_react_1.ErrorHandlerContext);
|
|
38
|
+
const [fetchMoreFetching, setFetchMoreFetching] = (0, react_1.useState)(false);
|
|
38
39
|
const memoizedVariables = (0, hooks_react_1.useMemoObject)(queryOptions?.variables);
|
|
39
40
|
const memoizedQuery = (0, hooks_react_1.useMemoObject)(query);
|
|
40
41
|
const context = (0, react_1.useMemo)(() => (calculateContext(queryDocument, memoizedVariables)), [queryDocument, memoizedVariables]);
|
|
@@ -66,28 +67,36 @@ const useServiceQuery = (queryDocument, options) => {
|
|
|
66
67
|
const promiselessRefetch = (0, react_1.useCallback)((...args) => {
|
|
67
68
|
(0, PromiseHelper_1.asyncToCallback)(memoizedQuery.refetch(...args));
|
|
68
69
|
}, [memoizedQuery]);
|
|
69
|
-
const fetchMore = (0, react_1.useCallback)(async (...args) =>
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
operationName,
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
70
|
+
const fetchMore = (0, react_1.useCallback)(async (...args) => {
|
|
71
|
+
setFetchMoreFetching(true);
|
|
72
|
+
return (await memoizedQuery.fetchMore(...args)
|
|
73
|
+
.catch((error) => {
|
|
74
|
+
const operationName = (0, OperationHelper_1.getName)(queryDocument);
|
|
75
|
+
const errorList = service_graphql_1.configManager.config.errorResponseTranslator(error, {
|
|
76
|
+
context,
|
|
77
|
+
operationName,
|
|
78
|
+
});
|
|
79
|
+
const exception = new service_prop_1.ServiceErrorException({
|
|
80
|
+
serviceErrorList: errorList,
|
|
81
|
+
serviceName: operationName,
|
|
82
|
+
context,
|
|
83
|
+
});
|
|
84
|
+
addServiceErrorException(exception);
|
|
85
|
+
throw error;
|
|
86
|
+
})
|
|
87
|
+
.finally(() => {
|
|
88
|
+
setFetchMoreFetching(false);
|
|
89
|
+
}));
|
|
90
|
+
}, [addServiceErrorException, context, memoizedQuery, queryDocument, setFetchMoreFetching]);
|
|
83
91
|
return (0, react_1.useMemo)(() => ({
|
|
84
92
|
query: memoizedQuery,
|
|
85
93
|
data: (0, lodash_get_1.default)(memoizedQuery.data, dataPath),
|
|
86
94
|
fetching: memoizedQuery.loading,
|
|
95
|
+
fetchMoreFetching,
|
|
87
96
|
promiselessRefetch,
|
|
88
97
|
fetchMore,
|
|
89
98
|
exception,
|
|
90
|
-
}), [memoizedQuery, dataPath, promiselessRefetch, fetchMore, exception]);
|
|
99
|
+
}), [memoizedQuery, dataPath, fetchMoreFetching, promiselessRefetch, fetchMore, exception]);
|
|
91
100
|
};
|
|
92
101
|
exports.useServiceQuery = useServiceQuery;
|
|
93
102
|
//# sourceMappingURL=UseServiceQuery.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UseServiceQuery.js","sourceRoot":"","sources":["../../src/Hooks/UseServiceQuery.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;;;;AAEH,
|
|
1
|
+
{"version":3,"file":"UseServiceQuery.js","sourceRoot":"","sources":["../../src/Hooks/UseServiceQuery.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;;;;AAEH,iCAOc;AASd,2CAEuB;AACvB,4DAA4B;AAO5B,oDAE0B;AAC1B,mEAA6D;AAC7D,kDAEyB;AACzB,2FAA+E;AAG/E,wDAAqD;AACrD,4DAAgD;AAChD,wDAAsD;AAEtD,MAAM,gBAAgB,GAAG,CAAC,KAAmB,EAAE,SAA8C,EAAU,EAAE,CAAC,CACxG,IAAA,8BAAc,EAAC,IAAA,yBAAO,EAAC,KAAK,CAAC,EAAE,SAAS,IAAI,EAAE,CAAC,CAChD,CAAA;AAgBD,MAAM,uBAAuB,GAAG,CAAC,CAAiB,EAAE,CAAiB,EAAW,EAAE;IAChF,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC;QAC1B,OAAO,KAAK,CAAA;IACd,CAAC;IACD,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,KAAK,KAAK,CAAC,GAAG,CAA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
|
|
4
4
|
"description": "Technology Studio - Service graphql react",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"@types/lodash.get": "^4.4.9",
|
|
65
65
|
"@types/lodash.set": "^4.3.9",
|
|
66
66
|
"@types/node-fetch": "^2.6.11",
|
|
67
|
-
"@types/react": "^18.2.
|
|
67
|
+
"@types/react": "^18.2.60",
|
|
68
68
|
"concurrently": "^8.2.2",
|
|
69
69
|
"eslint-config-txo-typescript-react": "^2.0.40",
|
|
70
70
|
"graphql": "^16.8.1",
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
useLayoutEffect,
|
|
11
11
|
useMemo,
|
|
12
12
|
useRef,
|
|
13
|
+
useState,
|
|
13
14
|
} from 'react'
|
|
14
15
|
import type {
|
|
15
16
|
DocumentNode,
|
|
@@ -53,6 +54,7 @@ export type QueryServiceProp<ATTRIBUTES extends OperationVariables, DATA, MAPPED
|
|
|
53
54
|
query: QueryResult<DATA, ATTRIBUTES>,
|
|
54
55
|
promiselessRefetch: (variables?: Partial<ATTRIBUTES>) => void,
|
|
55
56
|
fetchMore: QueryResult<DATA, ATTRIBUTES>['fetchMore'],
|
|
57
|
+
fetchMoreFetching: boolean,
|
|
56
58
|
}
|
|
57
59
|
|
|
58
60
|
type QueryOptions<DATA, ATTRIBUTES extends OperationVariables, DATA_PATH extends string> = {
|
|
@@ -90,6 +92,7 @@ export const useServiceQuery = <
|
|
|
90
92
|
addServiceErrorException,
|
|
91
93
|
removeServiceErrorException,
|
|
92
94
|
} = useContext(ErrorHandlerContext)
|
|
95
|
+
const [fetchMoreFetching, setFetchMoreFetching] = useState(false)
|
|
93
96
|
const memoizedVariables = useMemoObject(queryOptions?.variables)
|
|
94
97
|
const memoizedQuery = useMemoObject<Typify<QueryResult<DATA, ATTRIBUTES>>>(query)
|
|
95
98
|
const context = useMemo(() => (
|
|
@@ -127,29 +130,37 @@ export const useServiceQuery = <
|
|
|
127
130
|
asyncToCallback(memoizedQuery.refetch(...args))
|
|
128
131
|
}, [memoizedQuery])
|
|
129
132
|
|
|
130
|
-
const fetchMore: QueryResult<DATA>['fetchMore'] = useCallback(async (...args) =>
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
133
|
+
const fetchMore: QueryResult<DATA>['fetchMore'] = useCallback(async (...args) => {
|
|
134
|
+
setFetchMoreFetching(true)
|
|
135
|
+
return (
|
|
136
|
+
await memoizedQuery.fetchMore(...args)
|
|
137
|
+
.catch((error: ApolloError) => {
|
|
138
|
+
const operationName = getName(queryDocument)
|
|
139
|
+
const errorList = configManager.config.errorResponseTranslator(error, {
|
|
140
|
+
context,
|
|
141
|
+
operationName,
|
|
142
|
+
})
|
|
143
|
+
const exception = new ServiceErrorException({
|
|
144
|
+
serviceErrorList: errorList,
|
|
145
|
+
serviceName: operationName,
|
|
146
|
+
context,
|
|
147
|
+
})
|
|
148
|
+
addServiceErrorException(exception)
|
|
149
|
+
throw error
|
|
150
|
+
})
|
|
151
|
+
.finally(() => {
|
|
152
|
+
setFetchMoreFetching(false)
|
|
153
|
+
})
|
|
154
|
+
)
|
|
155
|
+
}, [addServiceErrorException, context, memoizedQuery, queryDocument, setFetchMoreFetching])
|
|
146
156
|
|
|
147
157
|
return useMemo(() => ({
|
|
148
158
|
query: memoizedQuery,
|
|
149
159
|
data: get(memoizedQuery.data, dataPath) as Get<DATA, DATA_PATH> | null,
|
|
150
160
|
fetching: memoizedQuery.loading,
|
|
161
|
+
fetchMoreFetching,
|
|
151
162
|
promiselessRefetch,
|
|
152
163
|
fetchMore,
|
|
153
164
|
exception,
|
|
154
|
-
}), [memoizedQuery, dataPath, promiselessRefetch, fetchMore, exception])
|
|
165
|
+
}), [memoizedQuery, dataPath, fetchMoreFetching, promiselessRefetch, fetchMore, exception])
|
|
155
166
|
}
|