@dhis2/app-service-data 3.11.3 → 3.12.0-alpha.1

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.
Files changed (112) hide show
  1. package/build/cjs/__tests__/integration.test.js +6 -15
  2. package/build/cjs/__tests__/mutations.test.js +4 -11
  3. package/build/cjs/engine/DataEngine.js +4 -14
  4. package/build/cjs/engine/DataEngine.test.js +0 -2
  5. package/build/cjs/engine/helpers/getMutationFetchType.js +0 -2
  6. package/build/cjs/engine/helpers/getMutationFetchType.test.js +0 -1
  7. package/build/cjs/engine/helpers/resolveDynamicQuery.js +0 -2
  8. package/build/cjs/engine/helpers/resolveDynamicQuery.test.js +3 -4
  9. package/build/cjs/engine/helpers/validate.js +0 -21
  10. package/build/cjs/engine/helpers/validate.test.js +0 -1
  11. package/build/cjs/engine/index.js +0 -18
  12. package/build/cjs/engine/types/FetchError.js +3 -8
  13. package/build/cjs/engine/types/FetchError.test.js +0 -1
  14. package/build/cjs/engine/types/InvalidQueryError.js +3 -8
  15. package/build/cjs/index.js +0 -2
  16. package/build/cjs/links/CustomDataLink.js +3 -17
  17. package/build/cjs/links/CustomDataLink.test.js +0 -1
  18. package/build/cjs/links/ErrorLink.js +3 -7
  19. package/build/cjs/links/RestAPILink/fetchData.js +12 -22
  20. package/build/cjs/links/RestAPILink/fetchData.test.js +0 -2
  21. package/build/cjs/links/RestAPILink/metadataResources.js +9 -7
  22. package/build/cjs/links/RestAPILink/path.js +0 -3
  23. package/build/cjs/links/RestAPILink/path.test.js +0 -1
  24. package/build/cjs/links/RestAPILink/queryToRequestOptions/multipartFormDataMatchers.js +9 -14
  25. package/build/cjs/links/RestAPILink/queryToRequestOptions/multipartFormDataMatchers.test.js +0 -1
  26. package/build/cjs/links/RestAPILink/queryToRequestOptions/requestContentType.js +4 -31
  27. package/build/cjs/links/RestAPILink/queryToRequestOptions/requestContentType.test.js +0 -1
  28. package/build/cjs/links/RestAPILink/queryToRequestOptions/textPlainMatchers.js +22 -39
  29. package/build/cjs/links/RestAPILink/queryToRequestOptions/textPlainMatchers.test.js +0 -1
  30. package/build/cjs/links/RestAPILink/queryToRequestOptions/xWwwFormUrlencodedMatchers.js +0 -2
  31. package/build/cjs/links/RestAPILink/queryToRequestOptions/xWwwFormUrlencodedMatchers.test.js +0 -1
  32. package/build/cjs/links/RestAPILink/queryToRequestOptions.js +0 -9
  33. package/build/cjs/links/RestAPILink/queryToRequestOptions.test.js +0 -1
  34. package/build/cjs/links/RestAPILink/queryToResourcePath.js +3 -24
  35. package/build/cjs/links/RestAPILink/queryToResourcePath.test.js +2 -4
  36. package/build/cjs/links/RestAPILink/validateQuery.js +4 -18
  37. package/build/cjs/links/RestAPILink/validateQuery.test.js +0 -1
  38. package/build/cjs/links/RestAPILink.js +3 -14
  39. package/build/cjs/links/RestAPILink.test.js +0 -2
  40. package/build/cjs/links/index.js +0 -6
  41. package/build/cjs/react/components/CustomDataProvider.js +2 -11
  42. package/build/cjs/react/components/DataMutation.js +1 -4
  43. package/build/cjs/react/components/DataProvider.js +5 -14
  44. package/build/cjs/react/components/DataProvider.test.js +2 -9
  45. package/build/cjs/react/components/DataQuery.js +1 -4
  46. package/build/cjs/react/context/DataContext.js +2 -8
  47. package/build/cjs/react/context/defaultContext.js +2 -6
  48. package/build/cjs/react/context/defaultContext.test.js +0 -1
  49. package/build/cjs/react/hooks/mergeAndCompareVariables.js +4 -6
  50. package/build/cjs/react/hooks/mergeAndCompareVariables.test.js +2 -3
  51. package/build/cjs/react/hooks/stableVariablesHash.js +11 -16
  52. package/build/cjs/react/hooks/stableVariablesHash.test.js +0 -1
  53. package/build/cjs/react/hooks/useDataEngine.js +0 -4
  54. package/build/cjs/react/hooks/useDataMutation.js +0 -7
  55. package/build/cjs/react/hooks/useDataMutation.test.js +42 -71
  56. package/build/cjs/react/hooks/useDataQuery.js +11 -22
  57. package/build/cjs/react/hooks/useDataQuery.test.js +318 -374
  58. package/build/cjs/react/hooks/useQueryExecutor.js +6 -14
  59. package/build/cjs/react/hooks/useQueryExecutor.test.js +42 -45
  60. package/build/cjs/react/hooks/useStaticInput.js +0 -3
  61. package/build/cjs/react/hooks/useStaticInput.test.js +8 -10
  62. package/build/cjs/react/index.js +0 -11
  63. package/build/cjs/setupRTL.js +1 -2
  64. package/build/es/__tests__/integration.test.js +4 -8
  65. package/build/es/__tests__/mutations.test.js +2 -4
  66. package/build/es/engine/DataEngine.js +3 -8
  67. package/build/es/engine/DataEngine.test.js +0 -1
  68. package/build/es/engine/helpers/resolveDynamicQuery.test.js +3 -3
  69. package/build/es/engine/helpers/validate.js +0 -13
  70. package/build/es/engine/types/FetchError.js +3 -6
  71. package/build/es/engine/types/InvalidQueryError.js +3 -6
  72. package/build/es/links/CustomDataLink.js +3 -15
  73. package/build/es/links/ErrorLink.js +3 -5
  74. package/build/es/links/RestAPILink/fetchData.js +12 -16
  75. package/build/es/links/RestAPILink/metadataResources.js +8 -3
  76. package/build/es/links/RestAPILink/path.js +0 -1
  77. package/build/es/links/RestAPILink/queryToRequestOptions/multipartFormDataMatchers.js +9 -4
  78. package/build/es/links/RestAPILink/queryToRequestOptions/requestContentType.js +2 -19
  79. package/build/es/links/RestAPILink/queryToRequestOptions/textPlainMatchers.js +22 -19
  80. package/build/es/links/RestAPILink/queryToRequestOptions.js +0 -7
  81. package/build/es/links/RestAPILink/queryToResourcePath.js +3 -21
  82. package/build/es/links/RestAPILink/queryToResourcePath.test.js +2 -3
  83. package/build/es/links/RestAPILink/validateQuery.js +4 -16
  84. package/build/es/links/RestAPILink.js +3 -8
  85. package/build/es/react/components/CustomDataProvider.js +1 -1
  86. package/build/es/react/components/DataMutation.js +1 -1
  87. package/build/es/react/components/DataProvider.js +3 -1
  88. package/build/es/react/components/DataProvider.test.js +1 -1
  89. package/build/es/react/components/DataQuery.js +1 -1
  90. package/build/es/react/hooks/mergeAndCompareVariables.js +4 -3
  91. package/build/es/react/hooks/mergeAndCompareVariables.test.js +2 -1
  92. package/build/es/react/hooks/stableVariablesHash.js +11 -14
  93. package/build/es/react/hooks/useDataMutation.test.js +17 -39
  94. package/build/es/react/hooks/useDataQuery.js +11 -15
  95. package/build/es/react/hooks/useDataQuery.test.js +268 -318
  96. package/build/es/react/hooks/useQueryExecutor.js +6 -9
  97. package/build/es/react/hooks/useQueryExecutor.test.js +33 -34
  98. package/build/es/react/hooks/useStaticInput.test.js +6 -6
  99. package/build/es/setupRTL.js +1 -1
  100. package/build/types/engine/types/ExecuteOptions.d.ts +1 -1
  101. package/build/types/engine/types/FetchError.d.ts +2 -2
  102. package/build/types/engine/types/JsonValue.d.ts +1 -1
  103. package/build/types/engine/types/Mutation.d.ts +2 -2
  104. package/build/types/engine/types/PossiblyDynamic.d.ts +1 -1
  105. package/build/types/engine/types/Query.d.ts +3 -3
  106. package/build/types/engine/types/QueryParameters.d.ts +4 -4
  107. package/build/types/links/CustomDataLink.d.ts +2 -2
  108. package/build/types/links/RestAPILink/queryToRequestOptions/requestContentType.d.ts +1 -1
  109. package/build/types/links/RestAPILink/queryToRequestOptions.d.ts +1 -1
  110. package/build/types/react/hooks/mergeAndCompareVariables.d.ts +1 -1
  111. package/build/types/types.d.ts +6 -6
  112. package/package.json +4 -4
@@ -1,19 +1,12 @@
1
1
  "use strict";
2
2
 
3
- var _reactHooks = require("@testing-library/react-hooks");
4
-
3
+ var _react = require("@testing-library/react");
5
4
  var React = _interopRequireWildcard(require("react"));
6
-
7
5
  var _CustomDataProvider = require("../components/CustomDataProvider");
8
-
9
6
  var _useDataEngine = require("./useDataEngine");
10
-
11
7
  var _useDataMutation = require("./useDataMutation");
12
-
13
- function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
14
-
15
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
16
-
8
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
9
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
17
10
  describe('useDataMutation', () => {
18
11
  it('should render without failing', async () => {
19
12
  const mutation = {
@@ -26,8 +19,7 @@ describe('useDataMutation', () => {
26
19
  const data = {
27
20
  answer: 42
28
21
  };
29
-
30
- const wrapper = (_ref) => {
22
+ const wrapper = _ref => {
31
23
  let {
32
24
  children
33
25
  } = _ref;
@@ -35,11 +27,9 @@ describe('useDataMutation', () => {
35
27
  data: data
36
28
  }, children);
37
29
  };
38
-
39
30
  const {
40
- result,
41
- waitFor
42
- } = (0, _reactHooks.renderHook)(() => (0, _useDataMutation.useDataMutation)(mutation), {
31
+ result
32
+ } = (0, _react.renderHook)(() => (0, _useDataMutation.useDataMutation)(mutation), {
43
33
  wrapper
44
34
  });
45
35
  const [mutate, beforeMutation] = result.current;
@@ -47,17 +37,17 @@ describe('useDataMutation', () => {
47
37
  loading: false,
48
38
  called: false
49
39
  });
50
- (0, _reactHooks.act)(() => {
40
+ (0, _react.act)(() => {
51
41
  mutate();
52
42
  });
53
- await waitFor(() => {
43
+ await (0, _react.waitFor)(() => {
54
44
  const [, duringMutation] = result.current;
55
45
  expect(duringMutation).toMatchObject({
56
46
  loading: true,
57
47
  called: true
58
48
  });
59
49
  });
60
- await waitFor(() => {
50
+ await (0, _react.waitFor)(() => {
61
51
  const [, afterMutation] = result.current;
62
52
  expect(afterMutation).toMatchObject({
63
53
  loading: false,
@@ -77,8 +67,7 @@ describe('useDataMutation', () => {
77
67
  const data = {
78
68
  answer: 42
79
69
  };
80
-
81
- const wrapper = (_ref2) => {
70
+ const wrapper = _ref2 => {
82
71
  let {
83
72
  children
84
73
  } = _ref2;
@@ -86,11 +75,9 @@ describe('useDataMutation', () => {
86
75
  data: data
87
76
  }, children);
88
77
  };
89
-
90
78
  const {
91
- result,
92
- waitFor
93
- } = (0, _reactHooks.renderHook)(() => (0, _useDataMutation.useDataMutation)(mutation, {
79
+ result
80
+ } = (0, _react.renderHook)(() => (0, _useDataMutation.useDataMutation)(mutation, {
94
81
  lazy: false
95
82
  }), {
96
83
  wrapper
@@ -100,7 +87,7 @@ describe('useDataMutation', () => {
100
87
  loading: true,
101
88
  called: true
102
89
  });
103
- await waitFor(() => {
90
+ await (0, _react.waitFor)(() => {
104
91
  const [, afterMutation] = result.current;
105
92
  expect(afterMutation).toMatchObject({
106
93
  loading: false,
@@ -121,8 +108,7 @@ describe('useDataMutation', () => {
121
108
  const data = {
122
109
  answer: 42
123
110
  };
124
-
125
- const wrapper = (_ref3) => {
111
+ const wrapper = _ref3 => {
126
112
  let {
127
113
  children
128
114
  } = _ref3;
@@ -130,21 +116,19 @@ describe('useDataMutation', () => {
130
116
  data: data
131
117
  }, children);
132
118
  };
133
-
134
119
  const {
135
- result,
136
- waitFor
137
- } = (0, _reactHooks.renderHook)(() => (0, _useDataMutation.useDataMutation)(mutation, {
120
+ result
121
+ } = (0, _react.renderHook)(() => (0, _useDataMutation.useDataMutation)(mutation, {
138
122
  onComplete
139
123
  }), {
140
124
  wrapper
141
125
  });
142
126
  expect(onComplete).toHaveBeenCalledTimes(0);
143
127
  const [mutate] = result.current;
144
- (0, _reactHooks.act)(() => {
128
+ (0, _react.act)(() => {
145
129
  mutate();
146
130
  });
147
- await waitFor(() => {
131
+ await (0, _react.waitFor)(() => {
148
132
  const [, state] = result.current;
149
133
  expect(state).toMatchObject({
150
134
  loading: false,
@@ -170,8 +154,7 @@ describe('useDataMutation', () => {
170
154
  throw error;
171
155
  }
172
156
  };
173
-
174
- const wrapper = (_ref4) => {
157
+ const wrapper = _ref4 => {
175
158
  let {
176
159
  children
177
160
  } = _ref4;
@@ -179,21 +162,19 @@ describe('useDataMutation', () => {
179
162
  data: data
180
163
  }, children);
181
164
  };
182
-
183
165
  const {
184
- result,
185
- waitFor
186
- } = (0, _reactHooks.renderHook)(() => (0, _useDataMutation.useDataMutation)(mutation, {
166
+ result
167
+ } = (0, _react.renderHook)(() => (0, _useDataMutation.useDataMutation)(mutation, {
187
168
  onError
188
169
  }), {
189
170
  wrapper
190
171
  });
191
172
  expect(onError).toHaveBeenCalledTimes(0);
192
173
  const [mutate] = result.current;
193
- (0, _reactHooks.act)(() => {
174
+ (0, _react.act)(() => {
194
175
  mutate();
195
176
  });
196
- await waitFor(() => {
177
+ await (0, _react.waitFor)(() => {
197
178
  const [, state] = result.current;
198
179
  expect(state).toMatchObject({
199
180
  loading: false,
@@ -208,7 +189,7 @@ describe('useDataMutation', () => {
208
189
  const mutation = {
209
190
  type: 'update',
210
191
  resource: 'answer',
211
- id: (_ref5) => {
192
+ id: _ref5 => {
212
193
  let {
213
194
  id
214
195
  } = _ref5;
@@ -222,8 +203,7 @@ describe('useDataMutation', () => {
222
203
  const data = {
223
204
  answer: answerSpy
224
205
  };
225
-
226
- const wrapper = (_ref6) => {
206
+ const wrapper = _ref6 => {
227
207
  let {
228
208
  children
229
209
  } = _ref6;
@@ -231,11 +211,9 @@ describe('useDataMutation', () => {
231
211
  data: data
232
212
  }, children);
233
213
  };
234
-
235
214
  const {
236
- result,
237
- waitFor
238
- } = (0, _reactHooks.renderHook)(() => (0, _useDataMutation.useDataMutation)(mutation, {
215
+ result
216
+ } = (0, _react.renderHook)(() => (0, _useDataMutation.useDataMutation)(mutation, {
239
217
  lazy: false,
240
218
  variables: {
241
219
  id: '1'
@@ -243,18 +221,18 @@ describe('useDataMutation', () => {
243
221
  }), {
244
222
  wrapper
245
223
  });
246
- await waitFor(() => {
224
+ await (0, _react.waitFor)(() => {
247
225
  expect(answerSpy).toHaveBeenLastCalledWith(expect.any(String), expect.objectContaining({
248
226
  id: '1'
249
227
  }), expect.any(Object));
250
228
  });
251
229
  const [mutate] = result.current;
252
- (0, _reactHooks.act)(() => {
230
+ (0, _react.act)(() => {
253
231
  mutate({
254
232
  id: '2'
255
233
  });
256
234
  });
257
- await waitFor(() => {
235
+ await (0, _react.waitFor)(() => {
258
236
  expect(answerSpy).toHaveBeenLastCalledWith(expect.any(String), expect.objectContaining({
259
237
  id: '2'
260
238
  }), expect.any(Object));
@@ -268,8 +246,7 @@ describe('useDataMutation', () => {
268
246
  answer: '?'
269
247
  }
270
248
  };
271
-
272
- const wrapper = (_ref7) => {
249
+ const wrapper = _ref7 => {
273
250
  let {
274
251
  children
275
252
  } = _ref7;
@@ -277,18 +254,17 @@ describe('useDataMutation', () => {
277
254
  data: {}
278
255
  }, children);
279
256
  };
280
-
281
- const engineHook = (0, _reactHooks.renderHook)(() => (0, _useDataEngine.useDataEngine)(), {
257
+ const engineHook = (0, _react.renderHook)(() => (0, _useDataEngine.useDataEngine)(), {
282
258
  wrapper
283
259
  });
284
- const mutationHook = (0, _reactHooks.renderHook)(() => (0, _useDataMutation.useDataMutation)(mutation), {
260
+ const mutationHook = (0, _react.renderHook)(() => (0, _useDataMutation.useDataMutation)(mutation), {
285
261
  wrapper
286
262
  });
263
+
287
264
  /**
288
265
  * Ideally we'd check referential equality here with .toBe, but since
289
266
  * both hooks run in a different context that doesn't work.
290
267
  */
291
-
292
268
  expect(mutationHook.result.current[1].engine).toStrictEqual(engineHook.result.current);
293
269
  });
294
270
  it('should return a stable mutate function', async () => {
@@ -302,8 +278,7 @@ describe('useDataMutation', () => {
302
278
  const data = {
303
279
  answer: 42
304
280
  };
305
-
306
- const wrapper = (_ref8) => {
281
+ const wrapper = _ref8 => {
307
282
  let {
308
283
  children
309
284
  } = _ref8;
@@ -311,14 +286,13 @@ describe('useDataMutation', () => {
311
286
  data: data
312
287
  }, children);
313
288
  };
314
-
315
289
  const {
316
290
  result
317
- } = (0, _reactHooks.renderHook)(() => (0, _useDataMutation.useDataMutation)(mutation), {
291
+ } = (0, _react.renderHook)(() => (0, _useDataMutation.useDataMutation)(mutation), {
318
292
  wrapper
319
293
  });
320
294
  const [firstMutate] = result.current;
321
- await (0, _reactHooks.act)(async () => {
295
+ await (0, _react.act)(async () => {
322
296
  await firstMutate({
323
297
  variable: 'variable'
324
298
  });
@@ -341,8 +315,7 @@ describe('useDataMutation', () => {
341
315
  const data = {
342
316
  answer: 42
343
317
  };
344
-
345
- const wrapper = (_ref9) => {
318
+ const wrapper = _ref9 => {
346
319
  let {
347
320
  children
348
321
  } = _ref9;
@@ -350,19 +323,17 @@ describe('useDataMutation', () => {
350
323
  data: data
351
324
  }, children);
352
325
  };
353
-
354
326
  const {
355
- result,
356
- waitFor
357
- } = (0, _reactHooks.renderHook)(() => (0, _useDataMutation.useDataMutation)(mutation), {
327
+ result
328
+ } = (0, _react.renderHook)(() => (0, _useDataMutation.useDataMutation)(mutation), {
358
329
  wrapper
359
330
  });
360
331
  let mutatePromise;
361
332
  const [mutate] = result.current;
362
- (0, _reactHooks.act)(() => {
333
+ (0, _react.act)(() => {
363
334
  mutatePromise = mutate();
364
335
  });
365
- await waitFor(() => {
336
+ await (0, _react.waitFor)(() => {
366
337
  const [, state] = result.current;
367
338
  expect(state).toMatchObject({
368
339
  loading: false,
@@ -4,17 +4,11 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.useDataQuery = void 0;
7
-
8
7
  var _react = require("react");
9
-
10
8
  var _reactQuery = require("react-query");
11
-
12
9
  var _mergeAndCompareVariables = require("./mergeAndCompareVariables");
13
-
14
10
  var _useDataEngine = require("./useDataEngine");
15
-
16
11
  var _useStaticInput = require("./useStaticInput");
17
-
18
12
  const noop = () => {
19
13
  /**
20
14
  * Used to silence the default react-query logger. Eventually we
@@ -22,13 +16,11 @@ const noop = () => {
22
16
  * to setLogger here.
23
17
  */
24
18
  };
25
-
26
19
  (0, _reactQuery.setLogger)({
27
20
  log: noop,
28
21
  warn: noop,
29
22
  error: noop
30
23
  });
31
-
32
24
  const useDataQuery = function (query) {
33
25
  let {
34
26
  onComplete: userOnSuccess,
@@ -47,6 +39,7 @@ const useDataQuery = function (query) {
47
39
  enabled: !initialLazy,
48
40
  refetchCallback: undefined
49
41
  });
42
+
50
43
  /**
51
44
  * Display current query state and refetch count in React DevTools
52
45
  */
@@ -56,41 +49,36 @@ const useDataQuery = function (query) {
56
49
  enabled: queryState.current.enabled,
57
50
  variables: queryState.current.variables
58
51
  }, debugValue => JSON.stringify(debugValue));
52
+
59
53
  /**
60
54
  * User callbacks and refetch handling
61
55
  */
62
56
 
63
57
  const onSuccess = data => {
64
58
  var _queryState$current$r, _queryState$current;
65
-
66
59
  (_queryState$current$r = (_queryState$current = queryState.current).refetchCallback) === null || _queryState$current$r === void 0 ? void 0 : _queryState$current$r.call(_queryState$current, data);
67
60
  queryState.current.refetchCallback = undefined;
68
-
69
61
  if (userOnSuccess) {
70
62
  userOnSuccess(data);
71
63
  }
72
64
  };
73
-
74
65
  const onError = error => {
75
66
  // If we'd want to reject on errors we'd call the cb with the error here
76
67
  queryState.current.refetchCallback = undefined;
77
-
78
68
  if (userOnError) {
79
69
  userOnError(error);
80
70
  }
81
71
  };
72
+
82
73
  /**
83
74
  * Setting up react-query
84
75
  */
85
76
 
86
-
87
77
  const engine = (0, _useDataEngine.useDataEngine)();
88
78
  const queryKey = [staticQuery, queryState.current.variables];
89
-
90
79
  const queryFn = () => engine.query(staticQuery, {
91
80
  variables: queryState.current.variables
92
81
  });
93
-
94
82
  const {
95
83
  isIdle,
96
84
  isFetching,
@@ -103,6 +91,7 @@ const useDataQuery = function (query) {
103
91
  onSuccess,
104
92
  onError
105
93
  });
94
+
106
95
  /**
107
96
  * Refetch allows a user to update the variables or just
108
97
  * trigger a refetch of the query with the current variables.
@@ -118,41 +107,42 @@ const useDataQuery = function (query) {
118
107
  mergedVariables,
119
108
  mergedVariablesHash
120
109
  } = (0, _mergeAndCompareVariables.mergeAndCompareVariables)(queryState.current.variables, newVariables, queryState.current.variablesHash);
110
+
121
111
  /**
122
112
  * If there are no updates that will trigger an automatic refetch
123
113
  * we'll need to call react-query's refetch directly
124
114
  */
125
-
126
115
  if (queryState.current.enabled && identical) {
127
116
  return queryRefetch({
128
117
  cancelRefetch: true,
129
118
  throwOnError: false
130
- }).then((_ref) => {
119
+ }).then(_ref => {
131
120
  let {
132
121
  data
133
122
  } = _ref;
134
123
  return data;
135
124
  });
136
125
  }
137
-
138
126
  queryState.current.variables = mergedVariables;
139
127
  queryState.current.variablesHash = mergedVariablesHash;
140
- queryState.current.enabled = true; // This promise does not currently reject on errors
128
+ queryState.current.enabled = true;
141
129
 
130
+ // This promise does not currently reject on errors
142
131
  const refetchPromise = new Promise(resolve => {
143
132
  queryState.current.refetchCallback = data => {
144
133
  resolve(data);
145
134
  };
146
- }); // Trigger a react-query refetch by incrementing variablesUpdateCount state
135
+ });
147
136
 
137
+ // Trigger a react-query refetch by incrementing variablesUpdateCount state
148
138
  setVariablesUpdateCount(prevCount => prevCount + 1);
149
139
  return refetchPromise;
150
140
  }, [queryRefetch]);
141
+
151
142
  /**
152
143
  * react-query returns null or an error, but we return undefined
153
144
  * or an error, so this ensures consistency with the other types.
154
145
  */
155
-
156
146
  const ourError = error || undefined;
157
147
  return {
158
148
  engine,
@@ -165,5 +155,4 @@ const useDataQuery = function (query) {
165
155
  refetch
166
156
  };
167
157
  };
168
-
169
158
  exports.useDataQuery = useDataQuery;