@apollo/client 3.5.10 → 3.6.5

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 (152) hide show
  1. package/LICENSE +1 -1
  2. package/apollo-client.cjs +541 -369
  3. package/apollo-client.cjs.map +1 -1
  4. package/apollo-client.min.cjs +1 -1
  5. package/cache/cache.cjs +9 -10
  6. package/cache/cache.cjs.map +1 -1
  7. package/cache/cache.cjs.native.js +2288 -0
  8. package/cache/inmemory/readFromStore.d.ts.map +1 -1
  9. package/cache/inmemory/readFromStore.js +10 -11
  10. package/cache/inmemory/readFromStore.js.map +1 -1
  11. package/core/ApolloClient.d.ts +2 -3
  12. package/core/ApolloClient.d.ts.map +1 -1
  13. package/core/ApolloClient.js +4 -8
  14. package/core/ApolloClient.js.map +1 -1
  15. package/core/ObservableQuery.d.ts +10 -4
  16. package/core/ObservableQuery.d.ts.map +1 -1
  17. package/core/ObservableQuery.js +97 -45
  18. package/core/ObservableQuery.js.map +1 -1
  19. package/core/QueryInfo.d.ts.map +1 -1
  20. package/core/QueryInfo.js +4 -2
  21. package/core/QueryInfo.js.map +1 -1
  22. package/core/QueryManager.d.ts +5 -2
  23. package/core/QueryManager.d.ts.map +1 -1
  24. package/core/QueryManager.js +29 -23
  25. package/core/QueryManager.js.map +1 -1
  26. package/core/core.cjs +138 -85
  27. package/core/core.cjs.map +1 -1
  28. package/core/core.cjs.native.js +2141 -0
  29. package/core/index.d.ts +1 -1
  30. package/core/index.d.ts.map +1 -1
  31. package/core/index.js +1 -1
  32. package/core/index.js.map +1 -1
  33. package/core/watchQueryOptions.d.ts +9 -1
  34. package/core/watchQueryOptions.d.ts.map +1 -1
  35. package/core/watchQueryOptions.js.map +1 -1
  36. package/errors/errors.cjs.native.js +48 -0
  37. package/invariantErrorCodes.js +1 -1
  38. package/link/batch/batch.cjs +47 -37
  39. package/link/batch/batch.cjs.map +1 -1
  40. package/link/batch/batch.cjs.native.js +161 -0
  41. package/link/batch/batching.d.ts +2 -6
  42. package/link/batch/batching.d.ts.map +1 -1
  43. package/link/batch/batching.js +47 -37
  44. package/link/batch/batching.js.map +1 -1
  45. package/link/batch-http/batch-http.cjs.native.js +127 -0
  46. package/link/context/context.cjs.native.js +38 -0
  47. package/link/core/core.cjs.native.js +121 -0
  48. package/link/error/error.cjs.native.js +90 -0
  49. package/link/http/http.cjs.native.js +320 -0
  50. package/link/http/selectHttpOptionsAndBody.d.ts.map +1 -1
  51. package/link/http/selectHttpOptionsAndBody.js.map +1 -1
  52. package/link/persisted-queries/index.d.ts +2 -1
  53. package/link/persisted-queries/index.d.ts.map +1 -1
  54. package/link/persisted-queries/index.js +26 -13
  55. package/link/persisted-queries/index.js.map +1 -1
  56. package/link/persisted-queries/persisted-queries.cjs +25 -12
  57. package/link/persisted-queries/persisted-queries.cjs.map +1 -1
  58. package/link/persisted-queries/persisted-queries.cjs.native.js +174 -0
  59. package/link/retry/retry.cjs.native.js +170 -0
  60. package/link/schema/schema.cjs.native.js +56 -0
  61. package/link/subscriptions/subscriptions.cjs.native.js +45 -0
  62. package/link/utils/utils.cjs.native.js +115 -0
  63. package/link/ws/ws.cjs.native.js +28 -0
  64. package/main.cjs.native.js +16 -0
  65. package/package.json +28 -26
  66. package/react/components/components.cjs.native.js +79 -0
  67. package/react/context/ApolloConsumer.js +2 -2
  68. package/react/context/ApolloProvider.js +2 -2
  69. package/react/context/context.cjs +4 -4
  70. package/react/context/context.cjs.map +1 -1
  71. package/react/context/context.cjs.native.js +67 -0
  72. package/react/hoc/hoc.cjs.native.js +325 -0
  73. package/react/hooks/hooks.cjs +365 -253
  74. package/react/hooks/hooks.cjs.map +1 -1
  75. package/react/hooks/hooks.cjs.native.js +612 -0
  76. package/react/hooks/index.d.ts +1 -1
  77. package/react/hooks/index.d.ts.map +1 -1
  78. package/react/hooks/index.js +1 -1
  79. package/react/hooks/index.js.map +1 -1
  80. package/react/hooks/useLazyQuery.d.ts +2 -2
  81. package/react/hooks/useLazyQuery.d.ts.map +1 -1
  82. package/react/hooks/useLazyQuery.js +26 -21
  83. package/react/hooks/useLazyQuery.js.map +1 -1
  84. package/react/hooks/useMutation.d.ts.map +1 -1
  85. package/react/hooks/useMutation.js +13 -10
  86. package/react/hooks/useMutation.js.map +1 -1
  87. package/react/hooks/useQuery.d.ts +36 -2
  88. package/react/hooks/useQuery.d.ts.map +1 -1
  89. package/react/hooks/useQuery.js +245 -206
  90. package/react/hooks/useQuery.js.map +1 -1
  91. package/react/hooks/useSubscription.d.ts.map +1 -1
  92. package/react/hooks/useSubscription.js +17 -7
  93. package/react/hooks/useSubscription.js.map +1 -1
  94. package/react/hooks/useSyncExternalStore.d.ts +4 -0
  95. package/react/hooks/useSyncExternalStore.d.ts.map +1 -0
  96. package/react/hooks/useSyncExternalStore.js +48 -0
  97. package/react/hooks/useSyncExternalStore.js.map +1 -0
  98. package/react/parser/index.d.ts.map +1 -1
  99. package/react/parser/index.js +24 -10
  100. package/react/parser/index.js.map +1 -1
  101. package/react/parser/parser.cjs +24 -10
  102. package/react/parser/parser.cjs.map +1 -1
  103. package/react/parser/parser.cjs.native.js +103 -0
  104. package/react/react.cjs.native.js +22 -0
  105. package/react/ssr/RenderPromises.d.ts +3 -2
  106. package/react/ssr/RenderPromises.d.ts.map +1 -1
  107. package/react/ssr/RenderPromises.js +25 -3
  108. package/react/ssr/RenderPromises.js.map +1 -1
  109. package/react/ssr/ssr.cjs +25 -3
  110. package/react/ssr/ssr.cjs.map +1 -1
  111. package/react/ssr/ssr.cjs.native.js +150 -0
  112. package/react/types/types.d.ts +10 -11
  113. package/react/types/types.d.ts.map +1 -1
  114. package/react/types/types.js.map +1 -1
  115. package/testing/core/core.cjs.native.js +288 -0
  116. package/testing/core/mocking/mockFetch.js +1 -1
  117. package/testing/core/mocking/mockFetch.js.map +1 -1
  118. package/testing/core/mocking/mockQueryManager.js +1 -1
  119. package/testing/core/mocking/mockWatchQuery.js +1 -1
  120. package/testing/core/wrap.js +1 -1
  121. package/testing/testing.cjs.native.js +58 -0
  122. package/utilities/common/canUse.d.ts +2 -0
  123. package/utilities/common/canUse.d.ts.map +1 -1
  124. package/utilities/common/canUse.js +6 -2
  125. package/utilities/common/canUse.js.map +1 -1
  126. package/utilities/common/mergeDeep.d.ts.map +1 -1
  127. package/utilities/common/mergeDeep.js +8 -11
  128. package/utilities/common/mergeDeep.js.map +1 -1
  129. package/utilities/common/mergeOptions.d.ts +5 -0
  130. package/utilities/common/mergeOptions.d.ts.map +1 -0
  131. package/utilities/common/mergeOptions.js +8 -0
  132. package/utilities/common/mergeOptions.js.map +1 -0
  133. package/utilities/globals/global.js +1 -2
  134. package/utilities/globals/globals.cjs.native.js +56 -0
  135. package/utilities/graphql/transform.d.ts +2 -2
  136. package/utilities/graphql/transform.d.ts.map +1 -1
  137. package/utilities/graphql/transform.js +1 -1
  138. package/utilities/graphql/transform.js.map +1 -1
  139. package/utilities/index.d.ts +1 -0
  140. package/utilities/index.d.ts.map +1 -1
  141. package/utilities/index.js +1 -0
  142. package/utilities/index.js.map +1 -1
  143. package/utilities/observables/Concast.d.ts.map +1 -1
  144. package/utilities/observables/Concast.js +5 -2
  145. package/utilities/observables/Concast.js.map +1 -1
  146. package/utilities/policies/pagination.d.ts.map +1 -1
  147. package/utilities/policies/pagination.js +9 -7
  148. package/utilities/policies/pagination.js.map +1 -1
  149. package/utilities/utilities.cjs +37 -23
  150. package/utilities/utilities.cjs.map +1 -1
  151. package/utilities/utilities.cjs.native.js +1281 -0
  152. package/version.js +1 -1
@@ -0,0 +1,612 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var globals = require('../../utilities/globals');
6
+ var React = require('react');
7
+ var context = require('../context');
8
+ var tslib = require('tslib');
9
+ var utilities = require('../../utilities');
10
+ var equality = require('@wry/equality');
11
+ var core = require('../../core');
12
+ var errors = require('../../errors');
13
+ var parser = require('../parser');
14
+
15
+ function _interopNamespace(e) {
16
+ if (e && e.__esModule) return e;
17
+ var n = Object.create(null);
18
+ if (e) {
19
+ for (var k in e) {
20
+ n[k] = e[k];
21
+ }
22
+ }
23
+ n["default"] = e;
24
+ return Object.freeze(n);
25
+ }
26
+
27
+ var React__namespace = /*#__PURE__*/_interopNamespace(React);
28
+
29
+ function useApolloClient(override) {
30
+ var context$1 = React.useContext(context.getApolloContext());
31
+ var client = override || context$1.client;
32
+ __DEV__ ? globals.invariant(!!client, 'Could not find "client" in the context or passed in as an option. ' +
33
+ 'Wrap the root component in an <ApolloProvider>, or pass an ApolloClient ' +
34
+ 'instance in via options.') : globals.invariant(!!client, 29);
35
+ return client;
36
+ }
37
+
38
+ var didWarnUncachedGetSnapshot = false;
39
+ var uSESKey = "useSyncExternalStore";
40
+ var realHook = React__namespace[uSESKey];
41
+ var useSyncExternalStore = realHook || (function (subscribe, getSnapshot, getServerSnapshot) {
42
+ var value = getSnapshot();
43
+ if (__DEV__ &&
44
+ !didWarnUncachedGetSnapshot &&
45
+ value !== getSnapshot()) {
46
+ didWarnUncachedGetSnapshot = true;
47
+ __DEV__ && globals.invariant.error('The result of getSnapshot should be cached to avoid an infinite loop');
48
+ }
49
+ var _a = React__namespace.useState({ inst: { value: value, getSnapshot: getSnapshot } }), inst = _a[0].inst, forceUpdate = _a[1];
50
+ if (utilities.canUseLayoutEffect) {
51
+ React__namespace.useLayoutEffect(function () {
52
+ Object.assign(inst, { value: value, getSnapshot: getSnapshot });
53
+ if (checkIfSnapshotChanged(inst)) {
54
+ forceUpdate({ inst: inst });
55
+ }
56
+ }, [subscribe, value, getSnapshot]);
57
+ }
58
+ else {
59
+ Object.assign(inst, { value: value, getSnapshot: getSnapshot });
60
+ }
61
+ React__namespace.useEffect(function () {
62
+ if (checkIfSnapshotChanged(inst)) {
63
+ forceUpdate({ inst: inst });
64
+ }
65
+ return subscribe(function handleStoreChange() {
66
+ if (checkIfSnapshotChanged(inst)) {
67
+ forceUpdate({ inst: inst });
68
+ }
69
+ });
70
+ }, [subscribe]);
71
+ return value;
72
+ });
73
+ function checkIfSnapshotChanged(_a) {
74
+ var value = _a.value, getSnapshot = _a.getSnapshot;
75
+ try {
76
+ return value !== getSnapshot();
77
+ }
78
+ catch (_b) {
79
+ return true;
80
+ }
81
+ }
82
+
83
+ var hasOwnProperty = Object.prototype.hasOwnProperty;
84
+ function useQuery(query, options) {
85
+ if (options === void 0) { options = Object.create(null); }
86
+ return useInternalState(useApolloClient(options.client), query).useQuery(options);
87
+ }
88
+ function useInternalState(client, query) {
89
+ var stateRef = React.useRef();
90
+ if (!stateRef.current ||
91
+ client !== stateRef.current.client ||
92
+ query !== stateRef.current.query) {
93
+ stateRef.current = new InternalState(client, query, stateRef.current);
94
+ }
95
+ var state = stateRef.current;
96
+ var _a = React.useState(0); _a[0]; var setTick = _a[1];
97
+ state.forceUpdate = function () {
98
+ setTick(function (tick) { return tick + 1; });
99
+ };
100
+ return state;
101
+ }
102
+ var InternalState = (function () {
103
+ function InternalState(client, query, previous) {
104
+ this.client = client;
105
+ this.query = query;
106
+ this.asyncResolveFns = new Set();
107
+ this.optionsToIgnoreOnce = new (utilities.canUseWeakSet ? WeakSet : Set)();
108
+ this.ssrDisabledResult = utilities.maybeDeepFreeze({
109
+ loading: true,
110
+ data: void 0,
111
+ error: void 0,
112
+ networkStatus: core.NetworkStatus.loading,
113
+ });
114
+ this.skipStandbyResult = utilities.maybeDeepFreeze({
115
+ loading: false,
116
+ data: void 0,
117
+ error: void 0,
118
+ networkStatus: core.NetworkStatus.ready,
119
+ });
120
+ this.toQueryResultCache = new (utilities.canUseWeakMap ? WeakMap : Map)();
121
+ parser.verifyDocumentType(query, parser.DocumentType.Query);
122
+ var previousResult = previous && previous.result;
123
+ var previousData = previousResult && previousResult.data;
124
+ if (previousData) {
125
+ this.previousData = previousData;
126
+ }
127
+ }
128
+ InternalState.prototype.forceUpdate = function () {
129
+ __DEV__ && globals.invariant.warn("Calling default no-op implementation of InternalState#forceUpdate");
130
+ };
131
+ InternalState.prototype.asyncUpdate = function () {
132
+ var _this = this;
133
+ return new Promise(function (resolve) {
134
+ _this.asyncResolveFns.add(resolve);
135
+ _this.optionsToIgnoreOnce.add(_this.watchQueryOptions);
136
+ _this.forceUpdate();
137
+ });
138
+ };
139
+ InternalState.prototype.useQuery = function (options) {
140
+ var _this = this;
141
+ this.renderPromises = React.useContext(context.getApolloContext()).renderPromises;
142
+ this.useOptions(options);
143
+ var obsQuery = this.useObservableQuery();
144
+ var result = useSyncExternalStore(React.useCallback(function () {
145
+ if (_this.renderPromises) {
146
+ return function () { };
147
+ }
148
+ var onNext = function () {
149
+ var previousResult = _this.result;
150
+ var result = obsQuery.getCurrentResult();
151
+ if (previousResult &&
152
+ previousResult.loading === result.loading &&
153
+ previousResult.networkStatus === result.networkStatus &&
154
+ equality.equal(previousResult.data, result.data)) {
155
+ return;
156
+ }
157
+ _this.setResult(result);
158
+ };
159
+ var onError = function (error) {
160
+ var last = obsQuery["last"];
161
+ subscription.unsubscribe();
162
+ try {
163
+ obsQuery.resetLastResults();
164
+ subscription = obsQuery.subscribe(onNext, onError);
165
+ }
166
+ finally {
167
+ obsQuery["last"] = last;
168
+ }
169
+ if (!hasOwnProperty.call(error, 'graphQLErrors')) {
170
+ throw error;
171
+ }
172
+ var previousResult = _this.result;
173
+ if (!previousResult ||
174
+ (previousResult && previousResult.loading) ||
175
+ !equality.equal(error, previousResult.error)) {
176
+ _this.setResult({
177
+ data: (previousResult && previousResult.data),
178
+ error: error,
179
+ loading: false,
180
+ networkStatus: core.NetworkStatus.error,
181
+ });
182
+ }
183
+ };
184
+ var subscription = obsQuery.subscribe(onNext, onError);
185
+ return function () { return subscription.unsubscribe(); };
186
+ }, [
187
+ obsQuery,
188
+ this.renderPromises,
189
+ this.client.disableNetworkFetches,
190
+ ]), function () { return _this.getCurrentResult(); }, function () { return _this.getCurrentResult(); });
191
+ this.unsafeHandlePartialRefetch(result);
192
+ var queryResult = this.toQueryResult(result);
193
+ if (!queryResult.loading && this.asyncResolveFns.size) {
194
+ this.asyncResolveFns.forEach(function (resolve) { return resolve(queryResult); });
195
+ this.asyncResolveFns.clear();
196
+ }
197
+ return queryResult;
198
+ };
199
+ InternalState.prototype.useOptions = function (options) {
200
+ var _a;
201
+ var watchQueryOptions = this.createWatchQueryOptions(this.queryHookOptions = options);
202
+ var currentWatchQueryOptions = this.watchQueryOptions;
203
+ if (this.optionsToIgnoreOnce.has(currentWatchQueryOptions) ||
204
+ !equality.equal(watchQueryOptions, currentWatchQueryOptions)) {
205
+ this.watchQueryOptions = watchQueryOptions;
206
+ if (currentWatchQueryOptions && this.observable) {
207
+ this.optionsToIgnoreOnce.delete(currentWatchQueryOptions);
208
+ this.observable.reobserve(watchQueryOptions);
209
+ this.previousData = ((_a = this.result) === null || _a === void 0 ? void 0 : _a.data) || this.previousData;
210
+ this.result = void 0;
211
+ }
212
+ }
213
+ this.onCompleted = options.onCompleted || InternalState.prototype.onCompleted;
214
+ this.onError = options.onError || InternalState.prototype.onError;
215
+ if ((this.renderPromises || this.client.disableNetworkFetches) &&
216
+ this.queryHookOptions.ssr === false &&
217
+ !this.queryHookOptions.skip) {
218
+ this.result = this.ssrDisabledResult;
219
+ }
220
+ else if (this.queryHookOptions.skip ||
221
+ this.watchQueryOptions.fetchPolicy === 'standby') {
222
+ this.result = this.skipStandbyResult;
223
+ }
224
+ else if (this.result === this.ssrDisabledResult ||
225
+ this.result === this.skipStandbyResult) {
226
+ this.result = void 0;
227
+ }
228
+ };
229
+ InternalState.prototype.createWatchQueryOptions = function (_a) {
230
+ var _b;
231
+ if (_a === void 0) { _a = {}; }
232
+ var skip = _a.skip; _a.ssr; _a.onCompleted; _a.onError; _a.displayName; _a.defaultOptions; var otherOptions = tslib.__rest(_a, ["skip", "ssr", "onCompleted", "onError", "displayName", "defaultOptions"]);
233
+ var watchQueryOptions = Object.assign(otherOptions, { query: this.query });
234
+ if (this.renderPromises &&
235
+ (watchQueryOptions.fetchPolicy === 'network-only' ||
236
+ watchQueryOptions.fetchPolicy === 'cache-and-network')) {
237
+ watchQueryOptions.fetchPolicy = 'cache-first';
238
+ }
239
+ if (!watchQueryOptions.variables) {
240
+ watchQueryOptions.variables = {};
241
+ }
242
+ if (skip) {
243
+ var _c = watchQueryOptions.fetchPolicy, fetchPolicy = _c === void 0 ? this.getDefaultFetchPolicy() : _c, _d = watchQueryOptions.initialFetchPolicy, initialFetchPolicy = _d === void 0 ? fetchPolicy : _d;
244
+ Object.assign(watchQueryOptions, {
245
+ initialFetchPolicy: initialFetchPolicy,
246
+ fetchPolicy: 'standby',
247
+ });
248
+ }
249
+ else if (!watchQueryOptions.fetchPolicy) {
250
+ watchQueryOptions.fetchPolicy =
251
+ ((_b = this.observable) === null || _b === void 0 ? void 0 : _b.options.initialFetchPolicy) ||
252
+ this.getDefaultFetchPolicy();
253
+ }
254
+ return watchQueryOptions;
255
+ };
256
+ InternalState.prototype.getDefaultFetchPolicy = function () {
257
+ var _a, _b;
258
+ return (((_a = this.queryHookOptions.defaultOptions) === null || _a === void 0 ? void 0 : _a.fetchPolicy) ||
259
+ ((_b = this.client.defaultOptions.watchQuery) === null || _b === void 0 ? void 0 : _b.fetchPolicy) ||
260
+ "cache-first");
261
+ };
262
+ InternalState.prototype.onCompleted = function (data) { };
263
+ InternalState.prototype.onError = function (error) { };
264
+ InternalState.prototype.useObservableQuery = function () {
265
+ var obsQuery = this.observable =
266
+ this.renderPromises
267
+ && this.renderPromises.getSSRObservable(this.watchQueryOptions)
268
+ || this.observable
269
+ || this.client.watchQuery(core.mergeOptions(this.queryHookOptions.defaultOptions, this.watchQueryOptions));
270
+ this.obsQueryFields = React.useMemo(function () { return ({
271
+ refetch: obsQuery.refetch.bind(obsQuery),
272
+ reobserve: obsQuery.reobserve.bind(obsQuery),
273
+ fetchMore: obsQuery.fetchMore.bind(obsQuery),
274
+ updateQuery: obsQuery.updateQuery.bind(obsQuery),
275
+ startPolling: obsQuery.startPolling.bind(obsQuery),
276
+ stopPolling: obsQuery.stopPolling.bind(obsQuery),
277
+ subscribeToMore: obsQuery.subscribeToMore.bind(obsQuery),
278
+ }); }, [obsQuery]);
279
+ var ssrAllowed = !(this.queryHookOptions.ssr === false ||
280
+ this.queryHookOptions.skip);
281
+ if (this.renderPromises && ssrAllowed) {
282
+ this.renderPromises.registerSSRObservable(obsQuery);
283
+ if (obsQuery.getCurrentResult().loading) {
284
+ this.renderPromises.addObservableQueryPromise(obsQuery);
285
+ }
286
+ }
287
+ return obsQuery;
288
+ };
289
+ InternalState.prototype.setResult = function (nextResult) {
290
+ var previousResult = this.result;
291
+ if (previousResult && previousResult.data) {
292
+ this.previousData = previousResult.data;
293
+ }
294
+ this.result = nextResult;
295
+ this.forceUpdate();
296
+ this.handleErrorOrCompleted(nextResult);
297
+ };
298
+ InternalState.prototype.handleErrorOrCompleted = function (result) {
299
+ if (!result.loading) {
300
+ if (result.error) {
301
+ this.onError(result.error);
302
+ }
303
+ else if (result.data) {
304
+ this.onCompleted(result.data);
305
+ }
306
+ }
307
+ };
308
+ InternalState.prototype.getCurrentResult = function () {
309
+ if (!this.result) {
310
+ this.handleErrorOrCompleted(this.result = this.observable.getCurrentResult());
311
+ }
312
+ return this.result;
313
+ };
314
+ InternalState.prototype.toQueryResult = function (result) {
315
+ var queryResult = this.toQueryResultCache.get(result);
316
+ if (queryResult)
317
+ return queryResult;
318
+ var data = result.data; result.partial; var resultWithoutPartial = tslib.__rest(result, ["data", "partial"]);
319
+ this.toQueryResultCache.set(result, queryResult = tslib.__assign(tslib.__assign(tslib.__assign({ data: data }, resultWithoutPartial), this.obsQueryFields), { client: this.client, observable: this.observable, variables: this.observable.variables, called: true, previousData: this.previousData }));
320
+ if (!queryResult.error && utilities.isNonEmptyArray(result.errors)) {
321
+ queryResult.error = new errors.ApolloError({ graphQLErrors: result.errors });
322
+ }
323
+ return queryResult;
324
+ };
325
+ InternalState.prototype.unsafeHandlePartialRefetch = function (result) {
326
+ if (result.partial &&
327
+ this.queryHookOptions.partialRefetch &&
328
+ !result.loading &&
329
+ (!result.data || Object.keys(result.data).length === 0) &&
330
+ this.observable.options.fetchPolicy !== 'cache-only') {
331
+ Object.assign(result, {
332
+ loading: true,
333
+ networkStatus: core.NetworkStatus.refetch,
334
+ });
335
+ this.observable.refetch();
336
+ }
337
+ };
338
+ return InternalState;
339
+ }());
340
+
341
+ var EAGER_METHODS = [
342
+ 'refetch',
343
+ 'reobserve',
344
+ 'fetchMore',
345
+ 'updateQuery',
346
+ 'startPolling',
347
+ 'subscribeToMore',
348
+ ];
349
+ function useLazyQuery(query, options) {
350
+ var internalState = useInternalState(useApolloClient(options && options.client), query);
351
+ var execOptionsRef = React.useRef();
352
+ var merged = execOptionsRef.current
353
+ ? utilities.mergeOptions(options, execOptionsRef.current)
354
+ : options;
355
+ var useQueryResult = internalState.useQuery(tslib.__assign(tslib.__assign({}, merged), { skip: !execOptionsRef.current }));
356
+ var initialFetchPolicy = useQueryResult.observable.options.initialFetchPolicy ||
357
+ internalState.getDefaultFetchPolicy();
358
+ var result = Object.assign(useQueryResult, {
359
+ called: !!execOptionsRef.current,
360
+ });
361
+ var eagerMethods = React.useMemo(function () {
362
+ var eagerMethods = {};
363
+ var _loop_1 = function (key) {
364
+ var method = result[key];
365
+ eagerMethods[key] = function () {
366
+ if (!execOptionsRef.current) {
367
+ execOptionsRef.current = Object.create(null);
368
+ internalState.forceUpdate();
369
+ }
370
+ return method.apply(this, arguments);
371
+ };
372
+ };
373
+ for (var _i = 0, EAGER_METHODS_1 = EAGER_METHODS; _i < EAGER_METHODS_1.length; _i++) {
374
+ var key = EAGER_METHODS_1[_i];
375
+ _loop_1(key);
376
+ }
377
+ return eagerMethods;
378
+ }, []);
379
+ Object.assign(result, eagerMethods);
380
+ var execute = React.useCallback(function (executeOptions) {
381
+ execOptionsRef.current = executeOptions ? tslib.__assign(tslib.__assign({}, executeOptions), { fetchPolicy: executeOptions.fetchPolicy || initialFetchPolicy }) : {
382
+ fetchPolicy: initialFetchPolicy,
383
+ };
384
+ var promise = internalState
385
+ .asyncUpdate()
386
+ .then(function (queryResult) { return Object.assign(queryResult, eagerMethods); });
387
+ promise.catch(function () { });
388
+ return promise;
389
+ }, []);
390
+ return [execute, result];
391
+ }
392
+
393
+ function useMutation(mutation, options) {
394
+ var client = useApolloClient(options === null || options === void 0 ? void 0 : options.client);
395
+ parser.verifyDocumentType(mutation, parser.DocumentType.Mutation);
396
+ var _a = React.useState({
397
+ called: false,
398
+ loading: false,
399
+ client: client,
400
+ }), result = _a[0], setResult = _a[1];
401
+ var ref = React.useRef({
402
+ result: result,
403
+ mutationId: 0,
404
+ isMounted: true,
405
+ client: client,
406
+ mutation: mutation,
407
+ options: options,
408
+ });
409
+ {
410
+ Object.assign(ref.current, { client: client, options: options, mutation: mutation });
411
+ }
412
+ var execute = React.useCallback(function (executeOptions) {
413
+ if (executeOptions === void 0) { executeOptions = {}; }
414
+ var _a = ref.current, client = _a.client, options = _a.options, mutation = _a.mutation;
415
+ var baseOptions = tslib.__assign(tslib.__assign({}, options), { mutation: mutation });
416
+ if (!ref.current.result.loading && !baseOptions.ignoreResults) {
417
+ setResult(ref.current.result = {
418
+ loading: true,
419
+ error: void 0,
420
+ data: void 0,
421
+ called: true,
422
+ client: client,
423
+ });
424
+ }
425
+ var mutationId = ++ref.current.mutationId;
426
+ var clientOptions = core.mergeOptions(baseOptions, executeOptions);
427
+ return client.mutate(clientOptions).then(function (response) {
428
+ var _a, _b, _c;
429
+ var data = response.data, errors$1 = response.errors;
430
+ var error = errors$1 && errors$1.length > 0
431
+ ? new errors.ApolloError({ graphQLErrors: errors$1 })
432
+ : void 0;
433
+ if (mutationId === ref.current.mutationId &&
434
+ !clientOptions.ignoreResults) {
435
+ var result_1 = {
436
+ called: true,
437
+ loading: false,
438
+ data: data,
439
+ error: error,
440
+ client: client,
441
+ };
442
+ if (ref.current.isMounted && !equality.equal(ref.current.result, result_1)) {
443
+ setResult(ref.current.result = result_1);
444
+ }
445
+ }
446
+ (_b = (_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onCompleted) === null || _b === void 0 ? void 0 : _b.call(_a, response.data);
447
+ (_c = executeOptions.onCompleted) === null || _c === void 0 ? void 0 : _c.call(executeOptions, response.data);
448
+ return response;
449
+ }).catch(function (error) {
450
+ var _a, _b, _c, _d;
451
+ if (mutationId === ref.current.mutationId &&
452
+ ref.current.isMounted) {
453
+ var result_2 = {
454
+ loading: false,
455
+ error: error,
456
+ data: void 0,
457
+ called: true,
458
+ client: client,
459
+ };
460
+ if (!equality.equal(ref.current.result, result_2)) {
461
+ setResult(ref.current.result = result_2);
462
+ }
463
+ }
464
+ if (((_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onError) || clientOptions.onError) {
465
+ (_c = (_b = ref.current.options) === null || _b === void 0 ? void 0 : _b.onError) === null || _c === void 0 ? void 0 : _c.call(_b, error);
466
+ (_d = executeOptions.onError) === null || _d === void 0 ? void 0 : _d.call(executeOptions, error);
467
+ return { data: void 0, errors: error };
468
+ }
469
+ throw error;
470
+ });
471
+ }, []);
472
+ var reset = React.useCallback(function () {
473
+ setResult({ called: false, loading: false, client: client });
474
+ }, []);
475
+ React.useEffect(function () {
476
+ ref.current.isMounted = true;
477
+ return function () {
478
+ ref.current.isMounted = false;
479
+ };
480
+ }, []);
481
+ return [execute, tslib.__assign({ reset: reset }, result)];
482
+ }
483
+
484
+ function useSubscription(subscription, options) {
485
+ var client = useApolloClient(options === null || options === void 0 ? void 0 : options.client);
486
+ parser.verifyDocumentType(subscription, parser.DocumentType.Subscription);
487
+ var _a = React.useState({
488
+ loading: !(options === null || options === void 0 ? void 0 : options.skip),
489
+ error: void 0,
490
+ data: void 0,
491
+ variables: options === null || options === void 0 ? void 0 : options.variables,
492
+ }), result = _a[0], setResult = _a[1];
493
+ var _b = React.useState(function () {
494
+ if (options === null || options === void 0 ? void 0 : options.skip) {
495
+ return null;
496
+ }
497
+ return client.subscribe({
498
+ query: subscription,
499
+ variables: options === null || options === void 0 ? void 0 : options.variables,
500
+ fetchPolicy: options === null || options === void 0 ? void 0 : options.fetchPolicy,
501
+ context: options === null || options === void 0 ? void 0 : options.context,
502
+ });
503
+ }), observable = _b[0], setObservable = _b[1];
504
+ var canResetObservableRef = React.useRef(false);
505
+ React.useEffect(function () {
506
+ return function () {
507
+ canResetObservableRef.current = true;
508
+ };
509
+ }, []);
510
+ var ref = React.useRef({ client: client, subscription: subscription, options: options });
511
+ React.useEffect(function () {
512
+ var _a, _b, _c, _d;
513
+ var shouldResubscribe = options === null || options === void 0 ? void 0 : options.shouldResubscribe;
514
+ if (typeof shouldResubscribe === 'function') {
515
+ shouldResubscribe = !!shouldResubscribe(options);
516
+ }
517
+ if (options === null || options === void 0 ? void 0 : options.skip) {
518
+ if (!(options === null || options === void 0 ? void 0 : options.skip) !== !((_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.skip) || canResetObservableRef.current) {
519
+ setResult({
520
+ loading: false,
521
+ data: void 0,
522
+ error: void 0,
523
+ variables: options === null || options === void 0 ? void 0 : options.variables,
524
+ });
525
+ setObservable(null);
526
+ canResetObservableRef.current = false;
527
+ }
528
+ }
529
+ else if ((shouldResubscribe !== false &&
530
+ (client !== ref.current.client ||
531
+ subscription !== ref.current.subscription ||
532
+ (options === null || options === void 0 ? void 0 : options.fetchPolicy) !== ((_b = ref.current.options) === null || _b === void 0 ? void 0 : _b.fetchPolicy) ||
533
+ !(options === null || options === void 0 ? void 0 : options.skip) !== !((_c = ref.current.options) === null || _c === void 0 ? void 0 : _c.skip) ||
534
+ !equality.equal(options === null || options === void 0 ? void 0 : options.variables, (_d = ref.current.options) === null || _d === void 0 ? void 0 : _d.variables))) ||
535
+ canResetObservableRef.current) {
536
+ setResult({
537
+ loading: true,
538
+ data: void 0,
539
+ error: void 0,
540
+ variables: options === null || options === void 0 ? void 0 : options.variables,
541
+ });
542
+ setObservable(client.subscribe({
543
+ query: subscription,
544
+ variables: options === null || options === void 0 ? void 0 : options.variables,
545
+ fetchPolicy: options === null || options === void 0 ? void 0 : options.fetchPolicy,
546
+ context: options === null || options === void 0 ? void 0 : options.context,
547
+ }));
548
+ canResetObservableRef.current = false;
549
+ }
550
+ Object.assign(ref.current, { client: client, subscription: subscription, options: options });
551
+ }, [client, subscription, options, canResetObservableRef.current]);
552
+ React.useEffect(function () {
553
+ if (!observable) {
554
+ return;
555
+ }
556
+ var subscription = observable.subscribe({
557
+ next: function (fetchResult) {
558
+ var _a, _b;
559
+ var result = {
560
+ loading: false,
561
+ data: fetchResult.data,
562
+ error: void 0,
563
+ variables: options === null || options === void 0 ? void 0 : options.variables,
564
+ };
565
+ setResult(result);
566
+ (_b = (_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onSubscriptionData) === null || _b === void 0 ? void 0 : _b.call(_a, {
567
+ client: client,
568
+ subscriptionData: result
569
+ });
570
+ },
571
+ error: function (error) {
572
+ setResult({
573
+ loading: false,
574
+ data: void 0,
575
+ error: error,
576
+ variables: options === null || options === void 0 ? void 0 : options.variables,
577
+ });
578
+ },
579
+ complete: function () {
580
+ var _a, _b;
581
+ (_b = (_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onSubscriptionComplete) === null || _b === void 0 ? void 0 : _b.call(_a);
582
+ },
583
+ });
584
+ return function () {
585
+ subscription.unsubscribe();
586
+ };
587
+ }, [observable]);
588
+ return result;
589
+ }
590
+
591
+ function useReactiveVar(rv) {
592
+ var value = rv();
593
+ var setValue = React.useState(value)[1];
594
+ React.useEffect(function () {
595
+ var probablySameValue = rv();
596
+ if (value !== probablySameValue) {
597
+ setValue(probablySameValue);
598
+ }
599
+ else {
600
+ return rv.onNextChange(setValue);
601
+ }
602
+ }, [value]);
603
+ return value;
604
+ }
605
+
606
+ exports.useApolloClient = useApolloClient;
607
+ exports.useLazyQuery = useLazyQuery;
608
+ exports.useMutation = useMutation;
609
+ exports.useQuery = useQuery;
610
+ exports.useReactiveVar = useReactiveVar;
611
+ exports.useSubscription = useSubscription;
612
+ //# sourceMappingURL=hooks.cjs.map
@@ -2,7 +2,7 @@ import '../../utilities/globals';
2
2
  export * from './useApolloClient';
3
3
  export * from './useLazyQuery';
4
4
  export * from './useMutation';
5
- export * from './useQuery';
5
+ export { useQuery } from './useQuery';
6
6
  export * from './useSubscription';
7
7
  export * from './useReactiveVar';
8
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAC;AAEjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAC;AAEjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC"}
@@ -2,7 +2,7 @@ import "../../utilities/globals/index.js";
2
2
  export * from "./useApolloClient.js";
3
3
  export * from "./useLazyQuery.js";
4
4
  export * from "./useMutation.js";
5
- export * from "./useQuery.js";
5
+ export { useQuery } from "./useQuery.js";
6
6
  export * from "./useSubscription.js";
7
7
  export * from "./useReactiveVar.js";
8
8
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/react/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAC;AAEjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC","sourcesContent":["import '../../utilities/globals';\n\nexport * from './useApolloClient';\nexport * from './useLazyQuery';\nexport * from './useMutation';\nexport * from './useQuery';\nexport * from './useSubscription';\nexport * from './useReactiveVar';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/react/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAC;AAEjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC","sourcesContent":["import '../../utilities/globals';\n\nexport * from './useApolloClient';\nexport * from './useLazyQuery';\nexport * from './useMutation';\nexport { useQuery } from './useQuery';\nexport * from './useSubscription';\nexport * from './useReactiveVar';\n"]}
@@ -1,6 +1,6 @@
1
1
  import { DocumentNode } from 'graphql';
2
2
  import { TypedDocumentNode } from '@graphql-typed-document-node/core';
3
- import { LazyQueryHookOptions, QueryTuple } from '../types/types';
4
3
  import { OperationVariables } from '../../core';
5
- export declare function useLazyQuery<TData = any, TVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: LazyQueryHookOptions<TData, TVariables>): QueryTuple<TData, TVariables>;
4
+ import { LazyQueryHookOptions, LazyQueryResultTuple } from '../types/types';
5
+ export declare function useLazyQuery<TData = any, TVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: LazyQueryHookOptions<TData, TVariables>): LazyQueryResultTuple<TData, TVariables>;
6
6
  //# sourceMappingURL=useLazyQuery.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useLazyQuery.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useLazyQuery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AAGtE,OAAO,EACL,oBAAoB,EAEpB,UAAU,EACX,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAYhD,wBAAgB,YAAY,CAAC,KAAK,GAAG,GAAG,EAAE,UAAU,GAAG,kBAAkB,EACvE,KAAK,EAAE,YAAY,GAAG,iBAAiB,CAAC,KAAK,EAAE,UAAU,CAAC,EAC1D,OAAO,CAAC,EAAE,oBAAoB,CAAC,KAAK,EAAE,UAAU,CAAC,GAChD,UAAU,CAAC,KAAK,EAAE,UAAU,CAAC,CAqE/B"}
1
+ {"version":3,"file":"useLazyQuery.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useLazyQuery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AAGtE,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAEhD,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EAErB,MAAM,gBAAgB,CAAC;AAexB,wBAAgB,YAAY,CAAC,KAAK,GAAG,GAAG,EAAE,UAAU,GAAG,kBAAkB,EACvE,KAAK,EAAE,YAAY,GAAG,iBAAiB,CAAC,KAAK,EAAE,UAAU,CAAC,EAC1D,OAAO,CAAC,EAAE,oBAAoB,CAAC,KAAK,EAAE,UAAU,CAAC,GAChD,oBAAoB,CAAC,KAAK,EAAE,UAAU,CAAC,CAmEzC"}