@dhis2/app-service-data 3.7.0 → 3.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/__tests__/integration.test.js +16 -10
- package/build/cjs/__tests__/mutations.test.js +8 -5
- package/build/cjs/engine/DataEngine.js +14 -12
- package/build/cjs/engine/helpers/resolveDynamicQuery.js +14 -11
- package/build/cjs/engine/helpers/resolveDynamicQuery.test.js +23 -14
- package/build/cjs/engine/helpers/validate.js +6 -4
- package/build/cjs/engine/helpers/validate.test.js +74 -15
- package/build/cjs/engine/types/FetchError.js +6 -5
- package/build/cjs/engine/types/InvalidQueryError.js +1 -1
- package/build/cjs/index.js +10 -10
- package/build/cjs/links/CustomDataLink.js +8 -6
- package/build/cjs/links/CustomDataLink.test.js +2 -2
- package/build/cjs/links/RestAPILink/fetchData.js +3 -2
- package/build/cjs/links/RestAPILink/fetchData.test.js +1 -1
- package/build/cjs/links/RestAPILink/metadataResources.js +1 -1
- package/build/cjs/links/RestAPILink/path.js +5 -1
- package/build/cjs/links/RestAPILink/queryToRequestOptions/multipartFormDataMatchers.js +29 -16
- package/build/cjs/links/RestAPILink/queryToRequestOptions/requestContentType.js +9 -6
- package/build/cjs/links/RestAPILink/queryToRequestOptions/requestContentType.test.js +2 -2
- package/build/cjs/links/RestAPILink/queryToRequestOptions/textPlainMatchers.js +51 -33
- package/build/cjs/links/RestAPILink/queryToRequestOptions/xWwwFormUrlencodedMatchers.js +6 -3
- package/build/cjs/links/RestAPILink/queryToRequestOptions.js +1 -1
- package/build/cjs/links/RestAPILink/queryToRequestOptions.test.js +56 -6
- package/build/cjs/links/RestAPILink/queryToResourcePath.js +14 -6
- package/build/cjs/links/RestAPILink/queryToResourcePath.test.js +16 -16
- package/build/cjs/links/RestAPILink/validateQuery.test.js +12 -12
- package/build/cjs/links/RestAPILink.js +4 -3
- package/build/cjs/react/components/CustomDataProvider.js +7 -6
- package/build/cjs/react/components/DataMutation.js +8 -7
- package/build/cjs/react/components/DataProvider.js +1 -1
- package/build/cjs/react/components/DataQuery.js +9 -8
- package/build/cjs/react/context/defaultContext.test.js +10 -2
- package/build/cjs/react/hooks/stableVariablesHash.js +1 -2
- package/build/cjs/react/hooks/stableVariablesHash.test.js +6 -6
- package/build/cjs/react/hooks/useDataMutation.js +7 -6
- package/build/cjs/react/hooks/useDataMutation.test.js +70 -43
- package/build/cjs/react/hooks/useDataQuery.js +13 -9
- package/build/cjs/react/hooks/useDataQuery.test.js +259 -162
- package/build/cjs/react/hooks/useQueryExecutor.js +11 -9
- package/build/cjs/react/hooks/useQueryExecutor.test.js +16 -12
- package/build/cjs/react/hooks/useStaticInput.js +7 -6
- package/build/cjs/react/hooks/useStaticInput.test.js +44 -25
- package/build/cjs/react/index.js +6 -6
- package/build/es/__tests__/integration.test.js +16 -10
- package/build/es/__tests__/mutations.test.js +8 -5
- package/build/es/engine/DataEngine.js +14 -12
- package/build/es/engine/helpers/resolveDynamicQuery.js +14 -11
- package/build/es/engine/helpers/resolveDynamicQuery.test.js +23 -14
- package/build/es/engine/helpers/validate.js +6 -4
- package/build/es/engine/helpers/validate.test.js +74 -15
- package/build/es/engine/types/FetchError.js +6 -5
- package/build/es/engine/types/InvalidQueryError.js +1 -1
- package/build/es/links/CustomDataLink.js +8 -6
- package/build/es/links/CustomDataLink.test.js +2 -2
- package/build/es/links/RestAPILink/fetchData.js +3 -2
- package/build/es/links/RestAPILink/fetchData.test.js +1 -1
- package/build/es/links/RestAPILink/path.js +5 -1
- package/build/es/links/RestAPILink/queryToRequestOptions/multipartFormDataMatchers.js +28 -15
- package/build/es/links/RestAPILink/queryToRequestOptions/requestContentType.js +8 -5
- package/build/es/links/RestAPILink/queryToRequestOptions/requestContentType.test.js +2 -2
- package/build/es/links/RestAPILink/queryToRequestOptions/textPlainMatchers.js +50 -32
- package/build/es/links/RestAPILink/queryToRequestOptions/xWwwFormUrlencodedMatchers.js +6 -3
- package/build/es/links/RestAPILink/queryToRequestOptions.js +1 -1
- package/build/es/links/RestAPILink/queryToRequestOptions.test.js +56 -6
- package/build/es/links/RestAPILink/queryToResourcePath.js +14 -6
- package/build/es/links/RestAPILink/queryToResourcePath.test.js +16 -16
- package/build/es/links/RestAPILink/validateQuery.test.js +12 -12
- package/build/es/links/RestAPILink.js +4 -3
- package/build/es/react/components/CustomDataProvider.js +7 -6
- package/build/es/react/components/DataMutation.js +8 -7
- package/build/es/react/components/DataQuery.js +9 -8
- package/build/es/react/context/defaultContext.test.js +10 -2
- package/build/es/react/hooks/stableVariablesHash.js +1 -2
- package/build/es/react/hooks/stableVariablesHash.test.js +6 -6
- package/build/es/react/hooks/useDataMutation.js +7 -6
- package/build/es/react/hooks/useDataMutation.test.js +70 -43
- package/build/es/react/hooks/useDataQuery.js +13 -9
- package/build/es/react/hooks/useDataQuery.test.js +259 -162
- package/build/es/react/hooks/useQueryExecutor.js +11 -9
- package/build/es/react/hooks/useQueryExecutor.test.js +16 -12
- package/build/es/react/hooks/useStaticInput.js +7 -6
- package/build/es/react/hooks/useStaticInput.test.js +44 -25
- package/package.json +2 -2
|
@@ -107,7 +107,7 @@ describe('validateQuery', () => {
|
|
|
107
107
|
}
|
|
108
108
|
}, 'read')).toBe(false);
|
|
109
109
|
expect(warn).toHaveBeenCalledTimes(1);
|
|
110
|
-
expect(warn.mock.calls.shift()[0]).toMatchInlineSnapshot("
|
|
110
|
+
expect(warn.mock.calls.shift()[0]).toMatchInlineSnapshot(`"Data queries should not use wildcard or dynamic field groups"`);
|
|
111
111
|
process.env.NODE_ENV = 'test';
|
|
112
112
|
});
|
|
113
113
|
it('Should detect missing fields', () => {
|
|
@@ -117,7 +117,7 @@ describe('validateQuery', () => {
|
|
|
117
117
|
resource: 'mapViews'
|
|
118
118
|
}, 'read')).toBe(false);
|
|
119
119
|
expect(warn).toHaveBeenCalledTimes(1);
|
|
120
|
-
expect(warn.mock.calls.shift()[0]).toMatchInlineSnapshot("
|
|
120
|
+
expect(warn.mock.calls.shift()[0]).toMatchInlineSnapshot(`"Data queries should always specify fields to return"`);
|
|
121
121
|
process.env.NODE_ENV = 'test';
|
|
122
122
|
});
|
|
123
123
|
it('Should detect paging false', () => {
|
|
@@ -131,7 +131,7 @@ describe('validateQuery', () => {
|
|
|
131
131
|
}
|
|
132
132
|
}, 'read')).toBe(false);
|
|
133
133
|
expect(warn).toHaveBeenCalledTimes(1);
|
|
134
|
-
expect(warn.mock.calls.shift()[0]).toMatchInlineSnapshot("
|
|
134
|
+
expect(warn.mock.calls.shift()[0]).toMatchInlineSnapshot(`"Data queries with paging=false are deprecated and should not be used!"`);
|
|
135
135
|
expect(validateResourceQuery({
|
|
136
136
|
resource: 'optionSets',
|
|
137
137
|
params: {
|
|
@@ -140,7 +140,7 @@ describe('validateQuery', () => {
|
|
|
140
140
|
}
|
|
141
141
|
}, 'read')).toBe(false);
|
|
142
142
|
expect(warn).toHaveBeenCalledTimes(1);
|
|
143
|
-
expect(warn.mock.calls.shift()[0]).toMatchInlineSnapshot("
|
|
143
|
+
expect(warn.mock.calls.shift()[0]).toMatchInlineSnapshot(`"Data queries with paging=false are deprecated and should not be used!"`);
|
|
144
144
|
process.env.NODE_ENV = 'test';
|
|
145
145
|
});
|
|
146
146
|
it('Should detect wildcard fields', () => {
|
|
@@ -153,7 +153,7 @@ describe('validateQuery', () => {
|
|
|
153
153
|
}
|
|
154
154
|
}, 'read')).toBe(false);
|
|
155
155
|
expect(warn).toHaveBeenCalledTimes(1);
|
|
156
|
-
expect(warn.mock.calls.shift()[0]).toMatchInlineSnapshot("
|
|
156
|
+
expect(warn.mock.calls.shift()[0]).toMatchInlineSnapshot(`"Data queries should not use wildcard or dynamic field groups"`);
|
|
157
157
|
expect(validateResourceQuery({
|
|
158
158
|
resource: 'organisationUnits',
|
|
159
159
|
params: {
|
|
@@ -161,7 +161,7 @@ describe('validateQuery', () => {
|
|
|
161
161
|
}
|
|
162
162
|
}, 'read')).toBe(false);
|
|
163
163
|
expect(warn).toHaveBeenCalledTimes(1);
|
|
164
|
-
expect(warn.mock.calls.shift()[0]).toMatchInlineSnapshot("
|
|
164
|
+
expect(warn.mock.calls.shift()[0]).toMatchInlineSnapshot(`"Data queries should not use wildcard or dynamic field groups"`);
|
|
165
165
|
expect(validateResourceQuery({
|
|
166
166
|
resource: 'organisationUnitGroups',
|
|
167
167
|
params: {
|
|
@@ -169,7 +169,7 @@ describe('validateQuery', () => {
|
|
|
169
169
|
}
|
|
170
170
|
}, 'read')).toBe(false);
|
|
171
171
|
expect(warn).toHaveBeenCalledTimes(1);
|
|
172
|
-
expect(warn.mock.calls.shift()[0]).toMatchInlineSnapshot("
|
|
172
|
+
expect(warn.mock.calls.shift()[0]).toMatchInlineSnapshot(`"Data queries should not use wildcard or dynamic field groups"`);
|
|
173
173
|
expect(validateResourceQuery({
|
|
174
174
|
resource: 'dashboards',
|
|
175
175
|
params: {
|
|
@@ -177,7 +177,7 @@ describe('validateQuery', () => {
|
|
|
177
177
|
}
|
|
178
178
|
}, 'read')).toBe(false);
|
|
179
179
|
expect(warn).toHaveBeenCalledTimes(1);
|
|
180
|
-
expect(warn.mock.calls.shift()[0]).toMatchInlineSnapshot("
|
|
180
|
+
expect(warn.mock.calls.shift()[0]).toMatchInlineSnapshot(`"Data queries should not use wildcard or dynamic field groups"`);
|
|
181
181
|
process.env.NODE_ENV = 'test';
|
|
182
182
|
});
|
|
183
183
|
it('Should warn for multiple errors in one query', () => {
|
|
@@ -191,8 +191,8 @@ describe('validateQuery', () => {
|
|
|
191
191
|
}
|
|
192
192
|
}, 'read')).toBe(false);
|
|
193
193
|
expect(warn).toHaveBeenCalledTimes(2);
|
|
194
|
-
expect(warn.mock.calls.shift()[0]).toMatchInlineSnapshot("
|
|
195
|
-
expect(warn.mock.calls.shift()[0]).toMatchInlineSnapshot("
|
|
194
|
+
expect(warn.mock.calls.shift()[0]).toMatchInlineSnapshot(`"Data queries with paging=false are deprecated and should not be used!"`);
|
|
195
|
+
expect(warn.mock.calls.shift()[0]).toMatchInlineSnapshot(`"Data queries should not use wildcard or dynamic field groups"`);
|
|
196
196
|
expect(validateResourceQuery({
|
|
197
197
|
resource: 'dashboardItems',
|
|
198
198
|
params: {
|
|
@@ -200,8 +200,8 @@ describe('validateQuery', () => {
|
|
|
200
200
|
}
|
|
201
201
|
}, 'read')).toBe(false);
|
|
202
202
|
expect(warn).toHaveBeenCalledTimes(2);
|
|
203
|
-
expect(warn.mock.calls.shift()[0]).toMatchInlineSnapshot("
|
|
204
|
-
expect(warn.mock.calls.shift()[0]).toMatchInlineSnapshot("
|
|
203
|
+
expect(warn.mock.calls.shift()[0]).toMatchInlineSnapshot(`"Data queries with paging=false are deprecated and should not be used!"`);
|
|
204
|
+
expect(warn.mock.calls.shift()[0]).toMatchInlineSnapshot(`"Data queries should always specify fields to return"`);
|
|
205
205
|
process.env.NODE_ENV = 'test';
|
|
206
206
|
});
|
|
207
207
|
});
|
|
@@ -21,9 +21,10 @@ export class RestAPILink {
|
|
|
21
21
|
return fetchData(joinPath(this.config.baseUrl, path), options);
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
executeResourceQuery(type, query, {
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
executeResourceQuery(type, query, _ref) {
|
|
25
|
+
let {
|
|
26
|
+
signal
|
|
27
|
+
} = _ref;
|
|
27
28
|
return this.fetch(queryToResourcePath(this, query, type), queryToRequestOptions(type, query, signal));
|
|
28
29
|
}
|
|
29
30
|
|
|
@@ -4,12 +4,13 @@ import { DataEngine } from '../../engine';
|
|
|
4
4
|
import { CustomDataLink } from '../../links';
|
|
5
5
|
import { DataContext } from '../context/DataContext';
|
|
6
6
|
import { queryClientOptions as queryClientDefaults } from './DataProvider';
|
|
7
|
-
export const CustomDataProvider = ({
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
export const CustomDataProvider = (_ref) => {
|
|
8
|
+
let {
|
|
9
|
+
children,
|
|
10
|
+
data,
|
|
11
|
+
options,
|
|
12
|
+
queryClientOptions = queryClientDefaults
|
|
13
|
+
} = _ref;
|
|
13
14
|
const link = new CustomDataLink(data, options);
|
|
14
15
|
const engine = new DataEngine(link);
|
|
15
16
|
const queryClient = new QueryClient(queryClientOptions);
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { useDataMutation } from '../hooks/useDataMutation';
|
|
2
|
-
export const DataMutation = ({
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
export const DataMutation = (_ref) => {
|
|
3
|
+
let {
|
|
4
|
+
mutation,
|
|
5
|
+
onComplete,
|
|
6
|
+
onError,
|
|
7
|
+
variables,
|
|
8
|
+
children
|
|
9
|
+
} = _ref;
|
|
9
10
|
const mutationState = useDataMutation(mutation, {
|
|
10
11
|
onComplete,
|
|
11
12
|
onError,
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { useDataQuery } from '../hooks/useDataQuery';
|
|
2
|
-
export const DataQuery = ({
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
export const DataQuery = (_ref) => {
|
|
3
|
+
let {
|
|
4
|
+
query,
|
|
5
|
+
onComplete,
|
|
6
|
+
onError,
|
|
7
|
+
variables,
|
|
8
|
+
lazy,
|
|
9
|
+
children
|
|
10
|
+
} = _ref;
|
|
10
11
|
const queryState = useDataQuery(query, {
|
|
11
12
|
onComplete,
|
|
12
13
|
onError,
|
|
@@ -15,7 +15,11 @@ describe('defaultContext', () => {
|
|
|
15
15
|
}
|
|
16
16
|
})).rejects.toBeTruthy();
|
|
17
17
|
expect(mockError).toHaveBeenCalledTimes(1);
|
|
18
|
-
expect(mockError.mock.calls.pop()).toMatchInlineSnapshot(
|
|
18
|
+
expect(mockError.mock.calls.pop()).toMatchInlineSnapshot(`
|
|
19
|
+
Array [
|
|
20
|
+
"DHIS2 data context must be initialized, please ensure that you include a <DataProvider> in your application",
|
|
21
|
+
]
|
|
22
|
+
`);
|
|
19
23
|
});
|
|
20
24
|
it('Should throw and log if mutate is called', () => {
|
|
21
25
|
const context = defaultContext;
|
|
@@ -25,6 +29,10 @@ describe('defaultContext', () => {
|
|
|
25
29
|
data: {}
|
|
26
30
|
})).rejects.toBeTruthy();
|
|
27
31
|
expect(mockError).toHaveBeenCalled();
|
|
28
|
-
expect(mockError.mock.calls.pop()).toMatchInlineSnapshot(
|
|
32
|
+
expect(mockError.mock.calls.pop()).toMatchInlineSnapshot(`
|
|
33
|
+
Array [
|
|
34
|
+
"DHIS2 data context must be initialized, please ensure that you include a <DataProvider> in your application",
|
|
35
|
+
]
|
|
36
|
+
`);
|
|
29
37
|
});
|
|
30
38
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
function hasObjectPrototype(o) {
|
|
2
2
|
return Object.prototype.toString.call(o) === '[object Object]';
|
|
3
|
-
} // eslint-disable-next-line @typescript-eslint/ban-types
|
|
3
|
+
} // eslint-disable-next-line @typescript-eslint/ban-types
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
export function isPlainObject(o) {
|
|
@@ -33,7 +33,6 @@ export function isPlainObject(o) {
|
|
|
33
33
|
/**
|
|
34
34
|
* Hashes the value into a stable hash.
|
|
35
35
|
*/
|
|
36
|
-
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
37
36
|
|
|
38
37
|
export function stableVariablesHash(value) {
|
|
39
38
|
let hash;
|
|
@@ -27,17 +27,17 @@ describe('stableVariablesHash', () => {
|
|
|
27
27
|
const three = 3;
|
|
28
28
|
const four = null;
|
|
29
29
|
const five = true;
|
|
30
|
-
expect(stableVariablesHash(one)).toMatchInlineSnapshot(
|
|
31
|
-
expect(stableVariablesHash(two)).toMatchInlineSnapshot("
|
|
32
|
-
expect(stableVariablesHash(three)).toMatchInlineSnapshot("
|
|
33
|
-
expect(stableVariablesHash(four)).toMatchInlineSnapshot("
|
|
34
|
-
expect(stableVariablesHash(five)).toMatchInlineSnapshot("
|
|
30
|
+
expect(stableVariablesHash(one)).toMatchInlineSnapshot(`undefined`);
|
|
31
|
+
expect(stableVariablesHash(two)).toMatchInlineSnapshot(`"\\"string\\""`);
|
|
32
|
+
expect(stableVariablesHash(three)).toMatchInlineSnapshot(`"3"`);
|
|
33
|
+
expect(stableVariablesHash(four)).toMatchInlineSnapshot(`"null"`);
|
|
34
|
+
expect(stableVariablesHash(five)).toMatchInlineSnapshot(`"true"`);
|
|
35
35
|
});
|
|
36
36
|
it('throws a clear error when the variables contain a circular reference', () => {
|
|
37
37
|
const unserializable = {
|
|
38
38
|
value: 'value'
|
|
39
39
|
};
|
|
40
40
|
unserializable.circular = unserializable;
|
|
41
|
-
expect(() => stableVariablesHash(unserializable)).toThrowErrorMatchingInlineSnapshot("
|
|
41
|
+
expect(() => stableVariablesHash(unserializable)).toThrowErrorMatchingInlineSnapshot(`"Could not serialize variables. Make sure that the variables do not contain circular references and can be processed by JSON.stringify."`);
|
|
42
42
|
});
|
|
43
43
|
});
|
|
@@ -3,12 +3,13 @@ import { useDataEngine } from './useDataEngine';
|
|
|
3
3
|
import { useQueryExecutor } from './useQueryExecutor';
|
|
4
4
|
import { useStaticInput } from './useStaticInput';
|
|
5
5
|
const empty = {};
|
|
6
|
-
export const useDataMutation = (mutation
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
export const useDataMutation = function (mutation) {
|
|
7
|
+
let {
|
|
8
|
+
onComplete,
|
|
9
|
+
onError,
|
|
10
|
+
variables = empty,
|
|
11
|
+
lazy = true
|
|
12
|
+
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
12
13
|
const engine = useDataEngine();
|
|
13
14
|
const [theMutation] = useStaticInput(mutation, {
|
|
14
15
|
warn: true,
|
|
@@ -16,11 +16,14 @@ describe('useDataMutation', () => {
|
|
|
16
16
|
answer: 42
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
-
const wrapper = ({
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
const wrapper = (_ref) => {
|
|
20
|
+
let {
|
|
21
|
+
children
|
|
22
|
+
} = _ref;
|
|
23
|
+
return /*#__PURE__*/React.createElement(CustomDataProvider, {
|
|
24
|
+
data: data
|
|
25
|
+
}, children);
|
|
26
|
+
};
|
|
24
27
|
|
|
25
28
|
const {
|
|
26
29
|
result,
|
|
@@ -64,11 +67,14 @@ describe('useDataMutation', () => {
|
|
|
64
67
|
answer: 42
|
|
65
68
|
};
|
|
66
69
|
|
|
67
|
-
const wrapper = ({
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
const wrapper = (_ref2) => {
|
|
71
|
+
let {
|
|
72
|
+
children
|
|
73
|
+
} = _ref2;
|
|
74
|
+
return /*#__PURE__*/React.createElement(CustomDataProvider, {
|
|
75
|
+
data: data
|
|
76
|
+
}, children);
|
|
77
|
+
};
|
|
72
78
|
|
|
73
79
|
const {
|
|
74
80
|
result,
|
|
@@ -105,11 +111,14 @@ describe('useDataMutation', () => {
|
|
|
105
111
|
answer: 42
|
|
106
112
|
};
|
|
107
113
|
|
|
108
|
-
const wrapper = ({
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
114
|
+
const wrapper = (_ref3) => {
|
|
115
|
+
let {
|
|
116
|
+
children
|
|
117
|
+
} = _ref3;
|
|
118
|
+
return /*#__PURE__*/React.createElement(CustomDataProvider, {
|
|
119
|
+
data: data
|
|
120
|
+
}, children);
|
|
121
|
+
};
|
|
113
122
|
|
|
114
123
|
const {
|
|
115
124
|
result,
|
|
@@ -151,11 +160,14 @@ describe('useDataMutation', () => {
|
|
|
151
160
|
}
|
|
152
161
|
};
|
|
153
162
|
|
|
154
|
-
const wrapper = ({
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
163
|
+
const wrapper = (_ref4) => {
|
|
164
|
+
let {
|
|
165
|
+
children
|
|
166
|
+
} = _ref4;
|
|
167
|
+
return /*#__PURE__*/React.createElement(CustomDataProvider, {
|
|
168
|
+
data: data
|
|
169
|
+
}, children);
|
|
170
|
+
};
|
|
159
171
|
|
|
160
172
|
const {
|
|
161
173
|
result,
|
|
@@ -185,9 +197,12 @@ describe('useDataMutation', () => {
|
|
|
185
197
|
const mutation = {
|
|
186
198
|
type: 'update',
|
|
187
199
|
resource: 'answer',
|
|
188
|
-
id: ({
|
|
189
|
-
|
|
190
|
-
|
|
200
|
+
id: (_ref5) => {
|
|
201
|
+
let {
|
|
202
|
+
id
|
|
203
|
+
} = _ref5;
|
|
204
|
+
return id;
|
|
205
|
+
},
|
|
191
206
|
data: {
|
|
192
207
|
answer: '?'
|
|
193
208
|
}
|
|
@@ -197,11 +212,14 @@ describe('useDataMutation', () => {
|
|
|
197
212
|
answer: answerSpy
|
|
198
213
|
};
|
|
199
214
|
|
|
200
|
-
const wrapper = ({
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
215
|
+
const wrapper = (_ref6) => {
|
|
216
|
+
let {
|
|
217
|
+
children
|
|
218
|
+
} = _ref6;
|
|
219
|
+
return /*#__PURE__*/React.createElement(CustomDataProvider, {
|
|
220
|
+
data: data
|
|
221
|
+
}, children);
|
|
222
|
+
};
|
|
205
223
|
|
|
206
224
|
const {
|
|
207
225
|
result,
|
|
@@ -240,11 +258,14 @@ describe('useDataMutation', () => {
|
|
|
240
258
|
}
|
|
241
259
|
};
|
|
242
260
|
|
|
243
|
-
const wrapper = ({
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
261
|
+
const wrapper = (_ref7) => {
|
|
262
|
+
let {
|
|
263
|
+
children
|
|
264
|
+
} = _ref7;
|
|
265
|
+
return /*#__PURE__*/React.createElement(CustomDataProvider, {
|
|
266
|
+
data: {}
|
|
267
|
+
}, children);
|
|
268
|
+
};
|
|
248
269
|
|
|
249
270
|
const engineHook = renderHook(() => useDataEngine(), {
|
|
250
271
|
wrapper
|
|
@@ -271,11 +292,14 @@ describe('useDataMutation', () => {
|
|
|
271
292
|
answer: 42
|
|
272
293
|
};
|
|
273
294
|
|
|
274
|
-
const wrapper = ({
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
295
|
+
const wrapper = (_ref8) => {
|
|
296
|
+
let {
|
|
297
|
+
children
|
|
298
|
+
} = _ref8;
|
|
299
|
+
return /*#__PURE__*/React.createElement(CustomDataProvider, {
|
|
300
|
+
data: data
|
|
301
|
+
}, children);
|
|
302
|
+
};
|
|
279
303
|
|
|
280
304
|
const {
|
|
281
305
|
result
|
|
@@ -307,11 +331,14 @@ describe('useDataMutation', () => {
|
|
|
307
331
|
answer: 42
|
|
308
332
|
};
|
|
309
333
|
|
|
310
|
-
const wrapper = ({
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
334
|
+
const wrapper = (_ref9) => {
|
|
335
|
+
let {
|
|
336
|
+
children
|
|
337
|
+
} = _ref9;
|
|
338
|
+
return /*#__PURE__*/React.createElement(CustomDataProvider, {
|
|
339
|
+
data: data
|
|
340
|
+
}, children);
|
|
341
|
+
};
|
|
315
342
|
|
|
316
343
|
const {
|
|
317
344
|
result,
|
|
@@ -17,12 +17,13 @@ setLogger({
|
|
|
17
17
|
warn: noop,
|
|
18
18
|
error: noop
|
|
19
19
|
});
|
|
20
|
-
export const useDataQuery = (query
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
20
|
+
export const useDataQuery = function (query) {
|
|
21
|
+
let {
|
|
22
|
+
onComplete: userOnSuccess,
|
|
23
|
+
onError: userOnError,
|
|
24
|
+
variables: initialVariables = {},
|
|
25
|
+
lazy: initialLazy = false
|
|
26
|
+
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
26
27
|
const [staticQuery] = useStaticInput(query, {
|
|
27
28
|
warn: true,
|
|
28
29
|
name: 'query'
|
|
@@ -114,9 +115,12 @@ export const useDataQuery = (query, {
|
|
|
114
115
|
return queryRefetch({
|
|
115
116
|
cancelRefetch: true,
|
|
116
117
|
throwOnError: false
|
|
117
|
-
}).then(({
|
|
118
|
-
|
|
119
|
-
|
|
118
|
+
}).then((_ref) => {
|
|
119
|
+
let {
|
|
120
|
+
data
|
|
121
|
+
} = _ref;
|
|
122
|
+
return data;
|
|
123
|
+
});
|
|
120
124
|
}
|
|
121
125
|
|
|
122
126
|
queryState.current.variables = mergedVariables;
|