@txo/service-graphql-react 2.6.31 → 3.0.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 +22 -0
- package/lib/Api/VoidError.d.ts +8 -0
- package/lib/Api/VoidError.js +15 -0
- package/lib/Api/VoidError.js.map +1 -0
- package/lib/Hooks/UseServiceMutation.d.ts +1 -1
- package/lib/Hooks/UseServiceMutation.js +8 -11
- package/lib/Hooks/UseServiceMutation.js.map +1 -1
- package/lib/Hooks/UseServiceQuery.d.ts +1 -1
- package/lib/Hooks/UseServiceQuery.js +25 -33
- package/lib/Hooks/UseServiceQuery.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/package.json +20 -21
- package/src/Api/VoidError.ts +11 -0
- package/src/Hooks/UseServiceMutation.ts +17 -25
- package/src/Hooks/UseServiceQuery.ts +31 -46
- package/src/index.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
+
## [3.0.0](https://github.com/technology-studio/service-graphql-react/compare/v2.6.32...v3.0.0) (2024-10-29)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### ⚠ BREAKING CHANGES
|
|
5
|
+
|
|
6
|
+
* - Renamed exception to the error on useServiceQuery
|
|
7
|
+
- Requires packages:
|
|
8
|
+
- @txo/service-prop@^3.0.0
|
|
9
|
+
- @txo-peer-dep/service-error-handler-react@^2.0.0
|
|
10
|
+
- @txo/service-error-handler-react@^2.0.0
|
|
11
|
+
|
|
12
|
+
### Bug fixes
|
|
13
|
+
|
|
14
|
+
* use `ServiceOperationError` and remove context ([#839](https://github.com/technology-studio/service-graphql-react/issues/839)) ([256a8c0](https://github.com/technology-studio/service-graphql-react/commit/256a8c04a30148906a2b785e0847c0a667a14c92))
|
|
15
|
+
|
|
16
|
+
## [2.6.32](https://github.com/technology-studio/service-graphql-react/compare/v2.6.31...v2.6.32) (2024-10-29)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### Bug fixes
|
|
20
|
+
|
|
21
|
+
* **deps:** update dependency @txo/service-prop to ^2.2.20 ([56e08d1](https://github.com/technology-studio/service-graphql-react/commit/56e08d136dbd9a68daea8894d8d75e6e43c4a701))
|
|
22
|
+
|
|
1
23
|
## [2.6.31](https://github.com/technology-studio/service-graphql-react/compare/v2.6.30...v2.6.31) (2024-09-08)
|
|
2
24
|
|
|
3
25
|
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @Author: Erik Slovak <erik.slovak@technologystudio.sk>
|
|
4
|
+
* @Date: 2024-10-25T22:32:09+02:00
|
|
5
|
+
* @Copyright: Technology Studio
|
|
6
|
+
**/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.VoidError = void 0;
|
|
9
|
+
class VoidError extends Error {
|
|
10
|
+
constructor() {
|
|
11
|
+
super('Void validation error');
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.VoidError = VoidError;
|
|
15
|
+
//# sourceMappingURL=VoidError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VoidError.js","sourceRoot":"","sources":["../../src/Api/VoidError.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH,MAAa,SAAU,SAAQ,KAAK;IAClC;QACE,KAAK,CAAC,uBAAuB,CAAC,CAAA;IAChC,CAAC;CACF;AAJD,8BAIC"}
|
|
@@ -7,7 +7,7 @@ import type { DependencyList } from 'react';
|
|
|
7
7
|
import type { CallAttributes, ServiceProp } from '@txo/service-prop';
|
|
8
8
|
import type { MutationOptions as ApolloMutationOptions, TypedDocumentNode, MutationResult, MutationFunctionOptions as MutateFunctionOptions, FetchResult } from '@apollo/client';
|
|
9
9
|
import type { ErrorMap } from '../Model/Types';
|
|
10
|
-
export type MutationServiceProp<ATTRIBUTES, DATA, CALL_ATTRIBUTES extends CallAttributes<ATTRIBUTES>> = Omit<ServiceProp<ATTRIBUTES, DATA, CALL_ATTRIBUTES, FetchResult<DATA>>, '
|
|
10
|
+
export type MutationServiceProp<ATTRIBUTES, DATA, CALL_ATTRIBUTES extends CallAttributes<ATTRIBUTES>> = Omit<ServiceProp<ATTRIBUTES, DATA, CALL_ATTRIBUTES, FetchResult<DATA>>, 'options' | 'error'> & {
|
|
11
11
|
mutation: MutationResult<DATA>;
|
|
12
12
|
};
|
|
13
13
|
export type MutateFunction<DATA, ATTRIBUTES> = (options?: MutateFunctionOptions<DATA, ATTRIBUTES>) => Promise<FetchResult<DATA>>;
|
|
@@ -9,15 +9,14 @@ exports.useServiceMutation = void 0;
|
|
|
9
9
|
const react_1 = require("react");
|
|
10
10
|
const hooks_react_1 = require("@txo/hooks-react");
|
|
11
11
|
const client_1 = require("@apollo/client");
|
|
12
|
-
const service_error_handler_react_1 = require("@txo-peer-dep/service-error-handler-react");
|
|
13
12
|
const service_graphql_1 = require("@txo/service-graphql");
|
|
14
13
|
const ContextHelper_1 = require("../Api/ContextHelper");
|
|
15
14
|
const OperationHelper_1 = require("../Api/OperationHelper");
|
|
16
15
|
const ErrorMapHelper_1 = require("../Api/ErrorMapHelper");
|
|
16
|
+
const VoidError_1 = require("../Api/VoidError");
|
|
17
17
|
const calculateContext = (mutation, variables) => ((0, ContextHelper_1.serviceContext)((0, OperationHelper_1.getName)(mutation), variables ?? {}));
|
|
18
18
|
const useServiceMutation = (mutationDocument, options) => {
|
|
19
19
|
const { onFieldErrors: defaultOnFieldErrors, onFieldErrorsDependencyList, errorMap, errorMapDependencyList, options: mutationOptions, mutateFactory, } = options ?? {};
|
|
20
|
-
const exceptionRef = (0, react_1.useRef)(null);
|
|
21
20
|
const memoizedErrorMap = (0, react_1.useMemo)(() => errorMap,
|
|
22
21
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
23
22
|
errorMapDependencyList ?? []);
|
|
@@ -25,15 +24,12 @@ const useServiceMutation = (mutationDocument, options) => {
|
|
|
25
24
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
26
25
|
onFieldErrorsDependencyList ?? []);
|
|
27
26
|
const [mutate, mutation] = (0, client_1.useMutation)(mutationDocument, mutationOptions);
|
|
28
|
-
const { addServiceErrorException, removeServiceErrorException, } = (0, react_1.useContext)(service_error_handler_react_1.ErrorHandlerContext);
|
|
29
27
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
30
28
|
const memoizedOptions = (0, hooks_react_1.useMemoObject)(mutationOptions);
|
|
31
29
|
const wrappedCall = (0, react_1.useCallback)(async (variables, callAttributes) => {
|
|
32
30
|
const attributes = { variables, mutation: mutationDocument, ...memoizedOptions };
|
|
33
31
|
const onFieldErrors = callAttributes?.onFieldErrors ?? memoizedDefaultOnFieldErrors;
|
|
34
32
|
const context = calculateContext(mutationDocument, variables);
|
|
35
|
-
(exceptionRef.current != null) && removeServiceErrorException(context);
|
|
36
|
-
exceptionRef.current = null;
|
|
37
33
|
const operationName = (0, OperationHelper_1.getName)(mutationDocument);
|
|
38
34
|
const mutateWithErrorProcessor = async (options) => (await (0, service_graphql_1.operationPromiseProcessor)(mutate(options), {
|
|
39
35
|
operationName,
|
|
@@ -44,15 +40,16 @@ const useServiceMutation = (mutationDocument, options) => {
|
|
|
44
40
|
operationName,
|
|
45
41
|
context,
|
|
46
42
|
})
|
|
47
|
-
.catch(async (
|
|
43
|
+
.catch(async (serviceOperationError) => {
|
|
48
44
|
if (memoizedErrorMap != null) {
|
|
49
|
-
|
|
45
|
+
serviceOperationError.serviceErrorList = (0, ErrorMapHelper_1.applyErrorMap)(serviceOperationError.serviceErrorList, memoizedErrorMap, onFieldErrors);
|
|
50
46
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
47
|
+
if (serviceOperationError.serviceErrorList.length === 0) {
|
|
48
|
+
throw new VoidError_1.VoidError();
|
|
49
|
+
}
|
|
50
|
+
throw serviceOperationError;
|
|
54
51
|
});
|
|
55
|
-
}, [mutationDocument, memoizedOptions, memoizedDefaultOnFieldErrors,
|
|
52
|
+
}, [mutationDocument, memoizedOptions, memoizedDefaultOnFieldErrors, mutateFactory, mutate, memoizedErrorMap]);
|
|
56
53
|
const memoizedMutation = (0, hooks_react_1.useMemoObject)(mutation);
|
|
57
54
|
return (0, react_1.useMemo)(() => ({
|
|
58
55
|
mutation: memoizedMutation,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UseServiceMutation.js","sourceRoot":"","sources":["../../src/Hooks/UseServiceMutation.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAGH,
|
|
1
|
+
{"version":3,"file":"UseServiceMutation.js","sourceRoot":"","sources":["../../src/Hooks/UseServiceMutation.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAGH,iCAGc;AAMd,kDAAgD;AAUhD,2CAEuB;AACvB,0DAAgE;AAEhE,wDAAqD;AACrD,4DAAgD;AAEhD,0DAAqD;AACrD,gDAA4C;AAE5C,MAAM,gBAAgB,GAAG,CAAC,QAAsB,EAAE,SAAmC,EAAU,EAAE,CAAC,CAChG,IAAA,8BAAc,EAAC,IAAA,yBAAO,EAAC,QAAQ,CAAC,EAAE,SAAS,IAAI,EAAE,CAAC,CACnD,CAAA;AAmBM,MAAM,kBAAkB,GAAG,CAKhC,gBAAqD,EACrD,OAA2C,EACa,EAAE;IAC1D,MAAM,EACJ,aAAa,EAAE,oBAAoB,EACnC,2BAA2B,EAC3B,QAAQ,EACR,sBAAsB,EACtB,OAAO,EAAE,eAAe,EACxB,aAAa,GACd,GAAG,OAAO,IAAI,EAAE,CAAA;IACjB,MAAM,gBAAgB,GAAG,IAAA,eAAO,EAC9B,GAAG,EAAE,CAAC,QAAQ;IACd,uDAAuD;IACvD,sBAAsB,IAAI,EAAE,CAC7B,CAAA;IACD,MAAM,4BAA4B,GAAG,IAAA,eAAO,EAC1C,GAAG,EAAE,CAAC,oBAAoB;IAC1B,uDAAuD;IACvD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AC;gBACxD,MAAM,IAAI,qBAAS,EAAE,CAAA;YACvB,CAAC;YACD,MAAM,qBAAqB,CAAA;QAC7B,CAAC,CAAC,CAAA;IACN,CAAC,EAAE,CAAC,gBAAgB,EAAE,eAAe,EAAE,4BAA4B,EAAE,aAAa,EAAE,MAAM,EAAE,gBAAgB,CAAC,CAAC,CAAA;IAE9G,MAAM,gBAAgB,GAAG,IAAA,2BAAa,EAA+B,QAAQ,CAAC,CAAA;IAE9E,OAAO,IAAA,eAAO,EAAC,GAAG,EAAE,CAAC,CAAC;QACpB,QAAQ,EAAE,gBAAgB;QAC1B,IAAI,EAAE,gBAAgB,CAAC,IAAI,IAAI,IAAI;QACnC,QAAQ,EAAE,gBAAgB,CAAC,OAAO;QAClC,IAAI,EAAE,WAAW;KAClB,CAAC,EAAE,CAAC,gBAAgB,EAAE,WAAW,CAAC,CAAC,CAAA;AACtC,CAAC,CAAA;AA1EY,QAAA,kBAAkB,sBA0E9B"}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import type { QueryHookOptions, TypedDocumentNode, QueryResult, OperationVariables } from '@apollo/client';
|
|
7
7
|
import type { Get } from 'type-fest';
|
|
8
8
|
import type { CallAttributes, ServiceProp } from '@txo/service-prop';
|
|
9
|
-
export type QueryServiceProp<ATTRIBUTES extends OperationVariables, DATA, MAPPED_DATA, CALL_ATTRIBUTES extends CallAttributes<ATTRIBUTES>> = Omit<ServiceProp<ATTRIBUTES, MAPPED_DATA, CALL_ATTRIBUTES>, 'call' | '
|
|
9
|
+
export type QueryServiceProp<ATTRIBUTES extends OperationVariables, DATA, MAPPED_DATA, CALL_ATTRIBUTES extends CallAttributes<ATTRIBUTES>> = Omit<ServiceProp<ATTRIBUTES, MAPPED_DATA, CALL_ATTRIBUTES>, 'call' | 'options'> & {
|
|
10
10
|
query: QueryResult<DATA, ATTRIBUTES>;
|
|
11
11
|
promiselessRefetch: (variables?: Partial<ATTRIBUTES>) => void;
|
|
12
12
|
fetchMore: QueryResult<DATA, ATTRIBUTES>['fetchMore'];
|
|
@@ -15,21 +15,12 @@ const lodash_get_1 = __importDefault(require("lodash.get"));
|
|
|
15
15
|
const service_prop_1 = require("@txo/service-prop");
|
|
16
16
|
const service_graphql_1 = require("@txo-peer-dep/service-graphql");
|
|
17
17
|
const hooks_react_1 = require("@txo/hooks-react");
|
|
18
|
-
const
|
|
18
|
+
const error_handler_1 = require("@txo-peer-dep/error-handler");
|
|
19
19
|
const ContextHelper_1 = require("../Api/ContextHelper");
|
|
20
20
|
const OperationHelper_1 = require("../Api/OperationHelper");
|
|
21
21
|
const PromiseHelper_1 = require("../Api/PromiseHelper");
|
|
22
22
|
const ObservableContext_1 = require("../Api/ObservableContext");
|
|
23
23
|
const calculateContext = (query, variables) => ((0, ContextHelper_1.serviceContext)((0, OperationHelper_1.getName)(query), variables ?? {}));
|
|
24
|
-
const isServiceErrorListEqual = (a, b) => {
|
|
25
|
-
if (a.length !== b.length) {
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
|
-
if (a.every((error, index) => (b[index].key === error.key) && (b[index].message === error.message))) {
|
|
29
|
-
return true;
|
|
30
|
-
}
|
|
31
|
-
return false;
|
|
32
|
-
};
|
|
33
24
|
// TODO: find a better way to parse type of dataPath (from attribute)
|
|
34
25
|
const useServiceQuery = (queryDocument, options) => {
|
|
35
26
|
const { dataPath, options: _queryOptions, } = options;
|
|
@@ -40,46 +31,48 @@ const useServiceQuery = (queryDocument, options) => {
|
|
|
40
31
|
skip: isSkipped,
|
|
41
32
|
});
|
|
42
33
|
const query = (0, client_1.useQuery)(queryDocument, queryOptions);
|
|
43
|
-
const
|
|
44
|
-
const { addServiceErrorException, removeServiceErrorException, } = (0, react_1.useContext)(service_error_handler_react_1.ErrorHandlerContext);
|
|
34
|
+
const reportedOperationErrorListRef = (0, react_1.useRef)([]);
|
|
45
35
|
const [fetchMoreFetching, setFetchMoreFetching] = (0, react_1.useState)(false);
|
|
46
36
|
const memoizedVariables = (0, hooks_react_1.useMemoObject)(queryOptions?.variables);
|
|
47
37
|
const memoizedQuery = (0, hooks_react_1.useMemoObject)(query);
|
|
38
|
+
(0, react_1.useMemo)(() => {
|
|
39
|
+
reportedOperationErrorListRef.current = [];
|
|
40
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
41
|
+
}, [memoizedQuery, queryDocument]);
|
|
48
42
|
const recentData = (0, react_1.useRef)(memoizedQuery.data);
|
|
49
43
|
if (!isSkipped) {
|
|
50
44
|
recentData.current = memoizedQuery.data;
|
|
51
45
|
}
|
|
52
46
|
const data = recentData.current ?? null;
|
|
53
47
|
const context = (0, react_1.useMemo)(() => (calculateContext(queryDocument, memoizedVariables)), [queryDocument, memoizedVariables]);
|
|
54
|
-
const
|
|
48
|
+
const error = (0, react_1.useMemo)(() => {
|
|
55
49
|
const operationName = (0, OperationHelper_1.getName)(queryDocument);
|
|
56
50
|
if (memoizedQuery.error != null) {
|
|
57
|
-
const
|
|
51
|
+
const serviceErrorList = service_graphql_1.configManager.config.errorResponseTranslator(memoizedQuery.error, {
|
|
58
52
|
context,
|
|
59
53
|
operationName,
|
|
60
54
|
});
|
|
61
|
-
const
|
|
62
|
-
serviceErrorList
|
|
63
|
-
|
|
55
|
+
const serviceOperationError = new service_prop_1.ServiceOperationError({
|
|
56
|
+
serviceErrorList,
|
|
57
|
+
operationName,
|
|
64
58
|
context,
|
|
65
59
|
});
|
|
66
|
-
return
|
|
60
|
+
return serviceOperationError;
|
|
67
61
|
}
|
|
68
62
|
return null;
|
|
69
|
-
}, [context, memoizedQuery, queryDocument]);
|
|
63
|
+
}, [context, memoizedQuery.error, queryDocument]);
|
|
70
64
|
(0, react_1.useLayoutEffect)(() => {
|
|
71
|
-
if ((
|
|
72
|
-
|
|
73
|
-
|
|
65
|
+
if ((error != null) && !reportedOperationErrorListRef.current.includes(error)) {
|
|
66
|
+
(0, error_handler_1.reportError)(error);
|
|
67
|
+
reportedOperationErrorListRef.current.push(error);
|
|
74
68
|
}
|
|
75
|
-
|
|
76
|
-
(exception != null) && removeServiceErrorException(context);
|
|
77
|
-
};
|
|
78
|
-
}, [addServiceErrorException, context, exception, memoizedVariables, queryDocument, removeServiceErrorException]);
|
|
69
|
+
}, [context, error, memoizedVariables, queryDocument]);
|
|
79
70
|
const promiselessRefetch = (0, react_1.useCallback)((...args) => {
|
|
71
|
+
reportedOperationErrorListRef.current = [];
|
|
80
72
|
(0, PromiseHelper_1.asyncToCallback)(memoizedQuery.refetch(...args));
|
|
81
73
|
}, [memoizedQuery]);
|
|
82
74
|
const fetchMore = (0, react_1.useCallback)(async (...args) => {
|
|
75
|
+
reportedOperationErrorListRef.current = [];
|
|
83
76
|
setFetchMoreFetching(true);
|
|
84
77
|
return (await memoizedQuery.fetchMore(...args)
|
|
85
78
|
.catch((error) => {
|
|
@@ -88,18 +81,17 @@ const useServiceQuery = (queryDocument, options) => {
|
|
|
88
81
|
context,
|
|
89
82
|
operationName,
|
|
90
83
|
});
|
|
91
|
-
const
|
|
84
|
+
const serviceOperationError = new service_prop_1.ServiceOperationError({
|
|
92
85
|
serviceErrorList: errorList,
|
|
93
|
-
|
|
86
|
+
operationName,
|
|
94
87
|
context,
|
|
95
88
|
});
|
|
96
|
-
|
|
97
|
-
throw error;
|
|
89
|
+
throw serviceOperationError;
|
|
98
90
|
})
|
|
99
91
|
.finally(() => {
|
|
100
92
|
setFetchMoreFetching(false);
|
|
101
93
|
}));
|
|
102
|
-
}, [
|
|
94
|
+
}, [context, memoizedQuery, queryDocument]);
|
|
103
95
|
return (0, react_1.useMemo)(() => ({
|
|
104
96
|
query: memoizedQuery,
|
|
105
97
|
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
|
|
@@ -108,8 +100,8 @@ const useServiceQuery = (queryDocument, options) => {
|
|
|
108
100
|
fetchMoreFetching,
|
|
109
101
|
promiselessRefetch,
|
|
110
102
|
fetchMore,
|
|
111
|
-
|
|
112
|
-
}), [memoizedQuery, data, dataPath, fetchMoreFetching, promiselessRefetch, fetchMore,
|
|
103
|
+
error,
|
|
104
|
+
}), [memoizedQuery, data, dataPath, fetchMoreFetching, promiselessRefetch, fetchMore, error]);
|
|
113
105
|
};
|
|
114
106
|
exports.useServiceQuery = useServiceQuery;
|
|
115
107
|
//# sourceMappingURL=UseServiceQuery.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UseServiceQuery.js","sourceRoot":"","sources":["../../src/Hooks/UseServiceQuery.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;;;;AAEH,iCAOc;AASd,2CAEuB;AACvB,4DAA4B;
|
|
1
|
+
{"version":3,"file":"UseServiceQuery.js","sourceRoot":"","sources":["../../src/Hooks/UseServiceQuery.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;;;;AAEH,iCAOc;AASd,2CAEuB;AACvB,4DAA4B;AAM5B,oDAE0B;AAC1B,mEAA6D;AAC7D,kDAEyB;AACzB,+DAAyD;AAGzD,wDAAqD;AACrD,4DAAgD;AAChD,wDAAsD;AACtD,gEAA4D;AAE5D,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,qEAAqE;AAC9D,MAAM,eAAe,GAAG,CAM7B,aAAkD,EAClD,OAAkD,EACyB,EAAE;IAC7E,MAAM,EACJ,QAAQ,EACR,OAAO,EAAE,aAAa,GACvB,GAAG,OAAO,CAAA;IAEX,MAAM,UAAU,GAAG,IAAA,kBAAU,EAAC,qCAAiB,CAAC,CAAA;IAChD,MAAM,SAAS,GAAG,CAAC,CAAC,aAAa,EAAE,IAAI,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,UAAU,CAAA;IACjE,MAAM,YAAY,GAAG,IAAA,2BAAa,EAAC;QACjC,GAAG,aAAa;QAChB,IAAI,EAAE,SAAS;KAChB,CAAC,CAAA;IACF,M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M,CAAC,uBAAuB,CAAC,KAAK,EAAE;gBACpE,OAAO;gBACP,aAAa;aACd,CAAC,CAAA;YACF,MAAM,qBAAqB,GAAG,IAAI,oCAAqB,CAAC;gBACtD,gBAAgB,EAAE,SAAS;gBAC3B,aAAa;gBACb,OAAO;aACR,CAAC,CAAA;YACF,MAAM,qBAAqB,CAAA;QAC7B,CAAC,CAAC;aACD,OAAO,CAAC,GAAG,EAAE;YACZ,oBAAoB,CAAC,KAAK,CAAC,CAAA;QAC7B,CAAC,CAAC,CACL,CAAA;IACH,CAAC,EAAE,CAAC,OAAO,EAAE,aAAa,EAAE,aAAa,CAAC,CAAC,CAAA;IAE3C,OAAO,IAAA,eAAO,EAAC,GAAG,EAAE,CAAC,CAAC;QACpB,KAAK,EAAE,aAAa;QACpB,2EAA2E;QAC3E,IAAI,EAAE,IAAA,oBAAG,EAAC,IAAI,EAAE,QAAQ,CAAgC;QACxD,QAAQ,EAAE,aAAa,CAAC,OAAO;QAC/B,iBAAiB;QACjB,kBAAkB;QAClB,SAAS;QACT,KAAK;KACN,CAAC,EAAE,CAAC,aAAa,EAAE,IAAI,EAAE,QAAQ,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC,CAAA;AAC/F,CAAC,CAAA;AAnGY,QAAA,eAAe,mBAmG3B"}
|
package/lib/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export { getName } from './Api/OperationHelper';
|
|
|
7
7
|
export * from './Api/ErrorMapHelper';
|
|
8
8
|
export * from './Api/ObservableContext';
|
|
9
9
|
export * from './Api/PromiseHelper';
|
|
10
|
+
export * from './Api/VoidError';
|
|
10
11
|
export * from './Hooks/UseServiceMutation';
|
|
11
12
|
export { useServiceQuery, type QueryServiceProp, } from './Hooks/UseServiceQuery';
|
|
12
13
|
export * from './Model/Types';
|
package/lib/index.js
CHANGED
|
@@ -25,6 +25,7 @@ Object.defineProperty(exports, "getName", { enumerable: true, get: function () {
|
|
|
25
25
|
__exportStar(require("./Api/ErrorMapHelper"), exports);
|
|
26
26
|
__exportStar(require("./Api/ObservableContext"), exports);
|
|
27
27
|
__exportStar(require("./Api/PromiseHelper"), exports);
|
|
28
|
+
__exportStar(require("./Api/VoidError"), exports);
|
|
28
29
|
__exportStar(require("./Hooks/UseServiceMutation"), exports);
|
|
29
30
|
var UseServiceQuery_1 = require("./Hooks/UseServiceQuery");
|
|
30
31
|
Object.defineProperty(exports, "useServiceQuery", { enumerable: true, get: function () { return UseServiceQuery_1.useServiceQuery; } });
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;;;;;;;;;;;;;;;AAEH,yDAA+C;AAAtC,0GAAA,OAAO,OAAA;AAChB,uDAAoC;AACpC,0DAAuC;AACvC,sDAAmC;AACnC,6DAA0C;AAC1C,2DAGgC;AAF9B,kHAAA,eAAe,OAAA;AAGjB,gDAA6B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;;;;;;;;;;;;;;;AAEH,yDAA+C;AAAtC,0GAAA,OAAO,OAAA;AAChB,uDAAoC;AACpC,0DAAuC;AACvC,sDAAmC;AACnC,kDAA+B;AAC/B,6DAA0C;AAC1C,2DAGgC;AAF9B,kHAAA,eAAe,OAAA;AAGjB,gDAA6B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@txo/service-graphql-react",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Technology Studio - Service graphql react",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
@@ -16,32 +16,31 @@
|
|
|
16
16
|
"license": "UNLICENSED",
|
|
17
17
|
"private": false,
|
|
18
18
|
"scripts": {
|
|
19
|
-
"build": "yarn build:clean && yarn build:lib",
|
|
20
19
|
"build:clean": "yarn rimraf lib",
|
|
21
20
|
"build:lib": "yarn tsc",
|
|
22
21
|
"build:watch": "yarn tsc --watch",
|
|
23
|
-
"
|
|
24
|
-
"test:watch": "concurrently \"yarn build:watch\" \"jest --watch\"",
|
|
25
|
-
"coverage": "jest --coverage && open coverage/lcov-report/index.html || xdg-open coverage/lcov-report/index.html",
|
|
22
|
+
"build": "yarn build:clean && yarn build:lib",
|
|
26
23
|
"compare-boilerplate-version": "./scripts/compare-boilerplate-version.sh",
|
|
24
|
+
"coverage": "jest --coverage && open coverage/lcov-report/index.html || xdg-open coverage/lcov-report/index.html",
|
|
25
|
+
"lint:ci": "yarn lint",
|
|
26
|
+
"lint:fix": "eslint . --fix",
|
|
27
27
|
"lint": "eslint --max-warnings 0 .",
|
|
28
|
-
"fixcode": "eslint . --fix",
|
|
29
|
-
"git-hook": "yarn -s lint-staged",
|
|
30
28
|
"prepare": "husky && yarn build",
|
|
31
29
|
"print-txo-packages": "yarn list 2> /dev/null|grep @txo|sed 's/.*\\(@txo[^@]*\\)@^*\\([^ ]*\\).*/\\1@\\2/g'|sort|uniq",
|
|
32
30
|
"sanity": "yarn lint:ci && yarn build && tsc --noEmit && yarn test --coverage && yarn compare-boilerplate-version && echo 'success'",
|
|
33
31
|
"semantic-release": "semantic-release",
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"type-check": "tsc --noEmit"
|
|
32
|
+
"test:watch": "concurrently \"yarn build:watch\" \"yarn test --watch\"",
|
|
33
|
+
"test": "jest",
|
|
34
|
+
"type-check": "tsc --noEmit",
|
|
35
|
+
"update-boilerplate-version": "./scripts/update-boilerplate-version.sh"
|
|
37
36
|
},
|
|
38
37
|
"engines": {
|
|
39
38
|
"node": ">=18.0.0"
|
|
40
39
|
},
|
|
41
40
|
"dependencies": {
|
|
42
41
|
"@txo/hooks-react": "^2.3.21",
|
|
43
|
-
"@txo/service-graphql": "^
|
|
44
|
-
"@txo/service-prop": "^
|
|
42
|
+
"@txo/service-graphql": "^5.0.0",
|
|
43
|
+
"@txo/service-prop": "^3.0.2",
|
|
45
44
|
"@txo/types": "^1.7.0",
|
|
46
45
|
"lodash.get": "^4.4.2",
|
|
47
46
|
"lodash.set": "^4.3.2",
|
|
@@ -49,28 +48,28 @@
|
|
|
49
48
|
},
|
|
50
49
|
"peerDependencies": {
|
|
51
50
|
"@apollo/client": "^3.11.8",
|
|
52
|
-
"@txo-peer-dep/
|
|
51
|
+
"@txo-peer-dep/error-handler": "^3.0.0",
|
|
53
52
|
"@txo-peer-dep/service-graphql": "^3.3.3",
|
|
54
53
|
"graphql": "^16.9.0"
|
|
55
54
|
},
|
|
56
55
|
"devDependencies": {
|
|
57
56
|
"@apollo/client": "^3.11.8",
|
|
57
|
+
"@txo-peer-dep/error-handler": "^3.0.0",
|
|
58
58
|
"@txo-peer-dep/log": "^4.0.4",
|
|
59
|
-
"@txo-peer-dep/service-error-handler-react": "^1.2.29",
|
|
60
59
|
"@txo-peer-dep/service-graphql": "^3.3.3",
|
|
61
|
-
"@txo/commitlint": "^1.0.
|
|
60
|
+
"@txo/commitlint": "^1.0.19",
|
|
62
61
|
"@txo/log-console": "^3.0.0",
|
|
63
62
|
"@txo/semantic-release": "^2.0.8",
|
|
64
63
|
"@txo/tsconfig": "^1.1.1",
|
|
65
|
-
"@types/jest": "^29.5.
|
|
64
|
+
"@types/jest": "^29.5.14",
|
|
66
65
|
"@types/lodash.get": "^4.4.9",
|
|
67
66
|
"@types/lodash.set": "^4.3.9",
|
|
68
67
|
"@types/node-fetch": "^2.6.11",
|
|
69
|
-
"@types/react": "^18.3.
|
|
70
|
-
"concurrently": "^
|
|
71
|
-
"eslint-config-txo-typescript-react": "^2.0.
|
|
68
|
+
"@types/react": "^18.3.12",
|
|
69
|
+
"concurrently": "^9.0.1",
|
|
70
|
+
"eslint-config-txo-typescript-react": "^2.0.81",
|
|
72
71
|
"graphql": "^16.9.0",
|
|
73
|
-
"husky": "^9.1.
|
|
72
|
+
"husky": "^9.1.6",
|
|
74
73
|
"jest": "^29.7.0",
|
|
75
74
|
"lint-staged": "^15.2.10",
|
|
76
75
|
"react": "^18.3.1",
|
|
@@ -78,6 +77,6 @@
|
|
|
78
77
|
"redux-saga": "^1.3.0",
|
|
79
78
|
"rimraf": "^6.0.1",
|
|
80
79
|
"ts-jest": "^29.2.5",
|
|
81
|
-
"typescript": "^5.
|
|
80
|
+
"typescript": "^5.6.3"
|
|
82
81
|
}
|
|
83
82
|
}
|
|
@@ -7,14 +7,12 @@
|
|
|
7
7
|
import type { DependencyList } from 'react'
|
|
8
8
|
import {
|
|
9
9
|
useCallback,
|
|
10
|
-
useContext,
|
|
11
10
|
useMemo,
|
|
12
|
-
useRef,
|
|
13
11
|
} from 'react'
|
|
14
12
|
import type {
|
|
15
13
|
CallAttributes,
|
|
16
14
|
ServiceProp,
|
|
17
|
-
|
|
15
|
+
ServiceOperationError,
|
|
18
16
|
} from '@txo/service-prop'
|
|
19
17
|
import { useMemoObject } from '@txo/hooks-react'
|
|
20
18
|
import type { Typify } from '@txo/types'
|
|
@@ -29,20 +27,20 @@ import type {
|
|
|
29
27
|
import {
|
|
30
28
|
useMutation,
|
|
31
29
|
} from '@apollo/client'
|
|
32
|
-
import { ErrorHandlerContext } from '@txo-peer-dep/service-error-handler-react'
|
|
33
30
|
import { operationPromiseProcessor } from '@txo/service-graphql'
|
|
34
31
|
|
|
35
32
|
import { serviceContext } from '../Api/ContextHelper'
|
|
36
33
|
import { getName } from '../Api/OperationHelper'
|
|
37
34
|
import type { ErrorMap } from '../Model/Types'
|
|
38
35
|
import { applyErrorMap } from '../Api/ErrorMapHelper'
|
|
36
|
+
import { VoidError } from '../Api/VoidError'
|
|
39
37
|
|
|
40
38
|
const calculateContext = (mutation: DocumentNode, variables?: Record<string, unknown>): string => (
|
|
41
39
|
serviceContext(getName(mutation), variables ?? {})
|
|
42
40
|
)
|
|
43
41
|
|
|
44
42
|
export type MutationServiceProp<ATTRIBUTES, DATA, CALL_ATTRIBUTES extends CallAttributes<ATTRIBUTES>> =
|
|
45
|
-
Omit<ServiceProp<ATTRIBUTES, DATA, CALL_ATTRIBUTES, FetchResult<DATA>>, '
|
|
43
|
+
Omit<ServiceProp<ATTRIBUTES, DATA, CALL_ATTRIBUTES, FetchResult<DATA>>, 'options' | 'error'>
|
|
46
44
|
& {
|
|
47
45
|
mutation: MutationResult<DATA>,
|
|
48
46
|
}
|
|
@@ -62,10 +60,10 @@ export const useServiceMutation = <
|
|
|
62
60
|
ATTRIBUTES extends Record<string, unknown>,
|
|
63
61
|
DATA,
|
|
64
62
|
CALL_ATTRIBUTES extends CallAttributes<ATTRIBUTES>,
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
63
|
+
> (
|
|
64
|
+
mutationDocument: TypedDocumentNode<DATA, ATTRIBUTES>,
|
|
65
|
+
options?: MutationOptions<DATA, ATTRIBUTES>,
|
|
66
|
+
): MutationServiceProp<ATTRIBUTES, DATA, CALL_ATTRIBUTES> => {
|
|
69
67
|
const {
|
|
70
68
|
onFieldErrors: defaultOnFieldErrors,
|
|
71
69
|
onFieldErrorsDependencyList,
|
|
@@ -74,7 +72,6 @@ export const useServiceMutation = <
|
|
|
74
72
|
options: mutationOptions,
|
|
75
73
|
mutateFactory,
|
|
76
74
|
} = options ?? {}
|
|
77
|
-
const exceptionRef = useRef<ServiceErrorException | null>(null)
|
|
78
75
|
const memoizedErrorMap = useMemo(
|
|
79
76
|
() => errorMap,
|
|
80
77
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -86,13 +83,9 @@ export const useServiceMutation = <
|
|
|
86
83
|
onFieldErrorsDependencyList ?? [],
|
|
87
84
|
)
|
|
88
85
|
const [mutate, mutation] = useMutation<
|
|
89
|
-
|
|
90
|
-
|
|
86
|
+
DATA,
|
|
87
|
+
ATTRIBUTES
|
|
91
88
|
>(mutationDocument, mutationOptions)
|
|
92
|
-
const {
|
|
93
|
-
addServiceErrorException,
|
|
94
|
-
removeServiceErrorException,
|
|
95
|
-
} = useContext(ErrorHandlerContext)
|
|
96
89
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
97
90
|
const memoizedOptions = useMemoObject(mutationOptions!)
|
|
98
91
|
const wrappedCall = useCallback(async (
|
|
@@ -102,8 +95,6 @@ export const useServiceMutation = <
|
|
|
102
95
|
const attributes = { variables, mutation: mutationDocument, ...memoizedOptions }
|
|
103
96
|
const onFieldErrors = callAttributes?.onFieldErrors ?? memoizedDefaultOnFieldErrors
|
|
104
97
|
const context = calculateContext(mutationDocument, variables)
|
|
105
|
-
;(exceptionRef.current != null) && removeServiceErrorException(context)
|
|
106
|
-
exceptionRef.current = null
|
|
107
98
|
const operationName = getName(mutationDocument)
|
|
108
99
|
const mutateWithErrorProcessor: typeof mutate = async (options) => (
|
|
109
100
|
await operationPromiseProcessor(mutate(options), {
|
|
@@ -116,19 +107,20 @@ export const useServiceMutation = <
|
|
|
116
107
|
operationName,
|
|
117
108
|
context,
|
|
118
109
|
})
|
|
119
|
-
.catch(async (
|
|
110
|
+
.catch(async (serviceOperationError: ServiceOperationError) => {
|
|
120
111
|
if (memoizedErrorMap != null) {
|
|
121
|
-
|
|
122
|
-
|
|
112
|
+
serviceOperationError.serviceErrorList = applyErrorMap(
|
|
113
|
+
serviceOperationError.serviceErrorList,
|
|
123
114
|
memoizedErrorMap,
|
|
124
115
|
onFieldErrors,
|
|
125
116
|
)
|
|
126
117
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
118
|
+
if (serviceOperationError.serviceErrorList.length === 0) {
|
|
119
|
+
throw new VoidError()
|
|
120
|
+
}
|
|
121
|
+
throw serviceOperationError
|
|
130
122
|
})
|
|
131
|
-
}, [mutationDocument, memoizedOptions, memoizedDefaultOnFieldErrors,
|
|
123
|
+
}, [mutationDocument, memoizedOptions, memoizedDefaultOnFieldErrors, mutateFactory, mutate, memoizedErrorMap])
|
|
132
124
|
|
|
133
125
|
const memoizedMutation = useMemoObject<Typify<MutationResult<DATA>>>(mutation)
|
|
134
126
|
|
|
@@ -27,17 +27,16 @@ import get from 'lodash.get'
|
|
|
27
27
|
import type { Get } from 'type-fest'
|
|
28
28
|
import type {
|
|
29
29
|
CallAttributes,
|
|
30
|
-
ServiceError,
|
|
31
30
|
ServiceProp,
|
|
32
31
|
} from '@txo/service-prop'
|
|
33
32
|
import {
|
|
34
|
-
|
|
33
|
+
ServiceOperationError,
|
|
35
34
|
} from '@txo/service-prop'
|
|
36
35
|
import { configManager } from '@txo-peer-dep/service-graphql'
|
|
37
36
|
import {
|
|
38
37
|
useMemoObject,
|
|
39
38
|
} from '@txo/hooks-react'
|
|
40
|
-
import {
|
|
39
|
+
import { reportError } from '@txo-peer-dep/error-handler'
|
|
41
40
|
import type { Typify } from '@txo/types'
|
|
42
41
|
|
|
43
42
|
import { serviceContext } from '../Api/ContextHelper'
|
|
@@ -50,7 +49,7 @@ const calculateContext = (query: DocumentNode, variables: Record<string, unknown
|
|
|
50
49
|
)
|
|
51
50
|
|
|
52
51
|
export type QueryServiceProp<ATTRIBUTES extends OperationVariables, DATA, MAPPED_DATA, CALL_ATTRIBUTES extends CallAttributes<ATTRIBUTES>> =
|
|
53
|
-
Omit<ServiceProp<ATTRIBUTES, MAPPED_DATA, CALL_ATTRIBUTES>, 'call' | '
|
|
52
|
+
Omit<ServiceProp<ATTRIBUTES, MAPPED_DATA, CALL_ATTRIBUTES>, 'call' | 'options'>
|
|
54
53
|
& {
|
|
55
54
|
query: QueryResult<DATA, ATTRIBUTES>,
|
|
56
55
|
promiselessRefetch: (variables?: Partial<ATTRIBUTES>) => void,
|
|
@@ -63,26 +62,16 @@ type QueryOptions<DATA, ATTRIBUTES extends OperationVariables, DATA_PATH extends
|
|
|
63
62
|
dataPath: DATA_PATH,
|
|
64
63
|
}
|
|
65
64
|
|
|
66
|
-
const isServiceErrorListEqual = (a: ServiceError[], b: ServiceError[]): boolean => {
|
|
67
|
-
if (a.length !== b.length) {
|
|
68
|
-
return false
|
|
69
|
-
}
|
|
70
|
-
if (a.every((error, index) => (b[index].key === error.key) && (b[index].message === error.message))) {
|
|
71
|
-
return true
|
|
72
|
-
}
|
|
73
|
-
return false
|
|
74
|
-
}
|
|
75
|
-
|
|
76
65
|
// TODO: find a better way to parse type of dataPath (from attribute)
|
|
77
66
|
export const useServiceQuery = <
|
|
78
67
|
ATTRIBUTES extends Record<string, unknown>,
|
|
79
68
|
DATA,
|
|
80
69
|
CALL_ATTRIBUTES extends CallAttributes<ATTRIBUTES>,
|
|
81
70
|
DATA_PATH extends string
|
|
82
|
-
>(
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
71
|
+
> (
|
|
72
|
+
queryDocument: TypedDocumentNode<DATA, ATTRIBUTES>,
|
|
73
|
+
options: QueryOptions<DATA, ATTRIBUTES, DATA_PATH>,
|
|
74
|
+
): QueryServiceProp<ATTRIBUTES, DATA, Get<DATA, DATA_PATH>, CALL_ATTRIBUTES> => {
|
|
86
75
|
const {
|
|
87
76
|
dataPath,
|
|
88
77
|
options: _queryOptions,
|
|
@@ -95,14 +84,14 @@ export const useServiceQuery = <
|
|
|
95
84
|
skip: isSkipped,
|
|
96
85
|
})
|
|
97
86
|
const query: QueryResult<DATA, ATTRIBUTES> = useQuery<DATA, ATTRIBUTES>(queryDocument, queryOptions)
|
|
98
|
-
const
|
|
99
|
-
const {
|
|
100
|
-
addServiceErrorException,
|
|
101
|
-
removeServiceErrorException,
|
|
102
|
-
} = useContext(ErrorHandlerContext)
|
|
87
|
+
const reportedOperationErrorListRef = useRef<(ServiceOperationError)[]>([])
|
|
103
88
|
const [fetchMoreFetching, setFetchMoreFetching] = useState(false)
|
|
104
89
|
const memoizedVariables = useMemoObject(queryOptions?.variables)
|
|
105
90
|
const memoizedQuery = useMemoObject<Typify<QueryResult<DATA, ATTRIBUTES>>>(query)
|
|
91
|
+
useMemo(() => {
|
|
92
|
+
reportedOperationErrorListRef.current = []
|
|
93
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
94
|
+
}, [memoizedQuery, queryDocument])
|
|
106
95
|
const recentData = useRef(memoizedQuery.data)
|
|
107
96
|
if (!isSkipped) {
|
|
108
97
|
recentData.current = memoizedQuery.data
|
|
@@ -111,39 +100,36 @@ export const useServiceQuery = <
|
|
|
111
100
|
const context = useMemo(() => (
|
|
112
101
|
calculateContext(queryDocument, memoizedVariables)
|
|
113
102
|
), [queryDocument, memoizedVariables])
|
|
114
|
-
const
|
|
103
|
+
const error = useMemo(() => {
|
|
115
104
|
const operationName = getName(queryDocument)
|
|
116
105
|
if (memoizedQuery.error != null) {
|
|
117
|
-
const
|
|
106
|
+
const serviceErrorList = configManager.config.errorResponseTranslator(memoizedQuery.error, {
|
|
118
107
|
context,
|
|
119
108
|
operationName,
|
|
120
109
|
})
|
|
121
|
-
const
|
|
122
|
-
serviceErrorList
|
|
123
|
-
|
|
110
|
+
const serviceOperationError = new ServiceOperationError({
|
|
111
|
+
serviceErrorList,
|
|
112
|
+
operationName,
|
|
124
113
|
context,
|
|
125
114
|
})
|
|
126
|
-
return
|
|
115
|
+
return serviceOperationError
|
|
127
116
|
}
|
|
128
117
|
return null
|
|
129
|
-
}, [context, memoizedQuery, queryDocument])
|
|
118
|
+
}, [context, memoizedQuery.error, queryDocument])
|
|
130
119
|
useLayoutEffect(() => {
|
|
131
|
-
if ((
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
addServiceErrorException(exception)
|
|
135
|
-
shownExceptionListRef.current.push(exception)
|
|
136
|
-
}
|
|
137
|
-
return () => {
|
|
138
|
-
(exception != null) && removeServiceErrorException(context)
|
|
120
|
+
if ((error != null) && !reportedOperationErrorListRef.current.includes(error)) {
|
|
121
|
+
reportError(error)
|
|
122
|
+
reportedOperationErrorListRef.current.push(error)
|
|
139
123
|
}
|
|
140
|
-
}, [
|
|
124
|
+
}, [context, error, memoizedVariables, queryDocument])
|
|
141
125
|
|
|
142
126
|
const promiselessRefetch = useCallback((...args: Parameters<typeof memoizedQuery.refetch>) => {
|
|
127
|
+
reportedOperationErrorListRef.current = []
|
|
143
128
|
asyncToCallback(memoizedQuery.refetch(...args))
|
|
144
129
|
}, [memoizedQuery])
|
|
145
130
|
|
|
146
131
|
const fetchMore: QueryResult<DATA>['fetchMore'] = useCallback(async (...args) => {
|
|
132
|
+
reportedOperationErrorListRef.current = []
|
|
147
133
|
setFetchMoreFetching(true)
|
|
148
134
|
return (
|
|
149
135
|
await memoizedQuery.fetchMore(...args)
|
|
@@ -153,19 +139,18 @@ export const useServiceQuery = <
|
|
|
153
139
|
context,
|
|
154
140
|
operationName,
|
|
155
141
|
})
|
|
156
|
-
const
|
|
142
|
+
const serviceOperationError = new ServiceOperationError({
|
|
157
143
|
serviceErrorList: errorList,
|
|
158
|
-
|
|
144
|
+
operationName,
|
|
159
145
|
context,
|
|
160
146
|
})
|
|
161
|
-
|
|
162
|
-
throw error
|
|
147
|
+
throw serviceOperationError
|
|
163
148
|
})
|
|
164
149
|
.finally(() => {
|
|
165
150
|
setFetchMoreFetching(false)
|
|
166
151
|
})
|
|
167
152
|
)
|
|
168
|
-
}, [
|
|
153
|
+
}, [context, memoizedQuery, queryDocument])
|
|
169
154
|
|
|
170
155
|
return useMemo(() => ({
|
|
171
156
|
query: memoizedQuery,
|
|
@@ -175,6 +160,6 @@ export const useServiceQuery = <
|
|
|
175
160
|
fetchMoreFetching,
|
|
176
161
|
promiselessRefetch,
|
|
177
162
|
fetchMore,
|
|
178
|
-
|
|
179
|
-
}), [memoizedQuery, data, dataPath, fetchMoreFetching, promiselessRefetch, fetchMore,
|
|
163
|
+
error,
|
|
164
|
+
}), [memoizedQuery, data, dataPath, fetchMoreFetching, promiselessRefetch, fetchMore, error])
|
|
180
165
|
}
|
package/src/index.ts
CHANGED
|
@@ -8,6 +8,7 @@ export { getName } from './Api/OperationHelper'
|
|
|
8
8
|
export * from './Api/ErrorMapHelper'
|
|
9
9
|
export * from './Api/ObservableContext'
|
|
10
10
|
export * from './Api/PromiseHelper'
|
|
11
|
+
export * from './Api/VoidError'
|
|
11
12
|
export * from './Hooks/UseServiceMutation'
|
|
12
13
|
export {
|
|
13
14
|
useServiceQuery,
|