@apollo/client 3.5.10 → 3.6.9

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 (156) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +5 -5
  3. package/apollo-client.cjs +563 -375
  4. package/apollo-client.cjs.map +1 -1
  5. package/apollo-client.min.cjs +1 -1
  6. package/cache/cache.cjs +10 -11
  7. package/cache/cache.cjs.map +1 -1
  8. package/cache/cache.cjs.native.js +2288 -0
  9. package/cache/inmemory/policies.js +1 -1
  10. package/cache/inmemory/policies.js.map +1 -1
  11. package/cache/inmemory/readFromStore.d.ts.map +1 -1
  12. package/cache/inmemory/readFromStore.js +10 -11
  13. package/cache/inmemory/readFromStore.js.map +1 -1
  14. package/core/ApolloClient.d.ts +2 -3
  15. package/core/ApolloClient.d.ts.map +1 -1
  16. package/core/ApolloClient.js +4 -8
  17. package/core/ApolloClient.js.map +1 -1
  18. package/core/ObservableQuery.d.ts +10 -4
  19. package/core/ObservableQuery.d.ts.map +1 -1
  20. package/core/ObservableQuery.js +101 -46
  21. package/core/ObservableQuery.js.map +1 -1
  22. package/core/QueryInfo.d.ts.map +1 -1
  23. package/core/QueryInfo.js +4 -2
  24. package/core/QueryInfo.js.map +1 -1
  25. package/core/QueryManager.d.ts +5 -2
  26. package/core/QueryManager.d.ts.map +1 -1
  27. package/core/QueryManager.js +36 -27
  28. package/core/QueryManager.js.map +1 -1
  29. package/core/core.cjs +148 -90
  30. package/core/core.cjs.map +1 -1
  31. package/core/core.cjs.native.js +2146 -0
  32. package/core/index.d.ts +1 -1
  33. package/core/index.d.ts.map +1 -1
  34. package/core/index.js +1 -1
  35. package/core/index.js.map +1 -1
  36. package/core/watchQueryOptions.d.ts +9 -1
  37. package/core/watchQueryOptions.d.ts.map +1 -1
  38. package/core/watchQueryOptions.js.map +1 -1
  39. package/errors/errors.cjs.native.js +48 -0
  40. package/invariantErrorCodes.js +1 -1
  41. package/link/batch/batch.cjs +46 -37
  42. package/link/batch/batch.cjs.map +1 -1
  43. package/link/batch/batch.cjs.native.js +160 -0
  44. package/link/batch/batching.d.ts +2 -6
  45. package/link/batch/batching.d.ts.map +1 -1
  46. package/link/batch/batching.js +46 -37
  47. package/link/batch/batching.js.map +1 -1
  48. package/link/batch-http/batch-http.cjs.native.js +127 -0
  49. package/link/context/context.cjs.native.js +38 -0
  50. package/link/core/core.cjs.native.js +121 -0
  51. package/link/error/error.cjs.native.js +90 -0
  52. package/link/http/http.cjs.native.js +320 -0
  53. package/link/http/selectHttpOptionsAndBody.d.ts.map +1 -1
  54. package/link/http/selectHttpOptionsAndBody.js.map +1 -1
  55. package/link/persisted-queries/index.d.ts +2 -1
  56. package/link/persisted-queries/index.d.ts.map +1 -1
  57. package/link/persisted-queries/index.js +26 -13
  58. package/link/persisted-queries/index.js.map +1 -1
  59. package/link/persisted-queries/persisted-queries.cjs +25 -12
  60. package/link/persisted-queries/persisted-queries.cjs.map +1 -1
  61. package/link/persisted-queries/persisted-queries.cjs.native.js +174 -0
  62. package/link/retry/retry.cjs.native.js +170 -0
  63. package/link/schema/schema.cjs.native.js +56 -0
  64. package/link/subscriptions/subscriptions.cjs.native.js +45 -0
  65. package/link/utils/utils.cjs.native.js +115 -0
  66. package/link/ws/ws.cjs.native.js +28 -0
  67. package/main.cjs.native.js +16 -0
  68. package/package.json +30 -27
  69. package/react/components/components.cjs.native.js +79 -0
  70. package/react/context/ApolloConsumer.js +2 -2
  71. package/react/context/ApolloProvider.js +2 -2
  72. package/react/context/context.cjs +4 -4
  73. package/react/context/context.cjs.map +1 -1
  74. package/react/context/context.cjs.native.js +67 -0
  75. package/react/hoc/hoc.cjs.native.js +325 -0
  76. package/react/hooks/hooks.cjs +376 -253
  77. package/react/hooks/hooks.cjs.map +1 -1
  78. package/react/hooks/hooks.cjs.native.js +623 -0
  79. package/react/hooks/index.d.ts +1 -1
  80. package/react/hooks/index.d.ts.map +1 -1
  81. package/react/hooks/index.js +1 -1
  82. package/react/hooks/index.js.map +1 -1
  83. package/react/hooks/useLazyQuery.d.ts +2 -2
  84. package/react/hooks/useLazyQuery.d.ts.map +1 -1
  85. package/react/hooks/useLazyQuery.js +26 -21
  86. package/react/hooks/useLazyQuery.js.map +1 -1
  87. package/react/hooks/useMutation.d.ts.map +1 -1
  88. package/react/hooks/useMutation.js +13 -10
  89. package/react/hooks/useMutation.js.map +1 -1
  90. package/react/hooks/useQuery.d.ts +37 -2
  91. package/react/hooks/useQuery.d.ts.map +1 -1
  92. package/react/hooks/useQuery.js +256 -206
  93. package/react/hooks/useQuery.js.map +1 -1
  94. package/react/hooks/useSubscription.d.ts.map +1 -1
  95. package/react/hooks/useSubscription.js +17 -7
  96. package/react/hooks/useSubscription.js.map +1 -1
  97. package/react/hooks/useSyncExternalStore.d.ts +4 -0
  98. package/react/hooks/useSyncExternalStore.d.ts.map +1 -0
  99. package/react/hooks/useSyncExternalStore.js +48 -0
  100. package/react/hooks/useSyncExternalStore.js.map +1 -0
  101. package/react/parser/index.d.ts.map +1 -1
  102. package/react/parser/index.js +24 -10
  103. package/react/parser/index.js.map +1 -1
  104. package/react/parser/parser.cjs +24 -10
  105. package/react/parser/parser.cjs.map +1 -1
  106. package/react/parser/parser.cjs.native.js +103 -0
  107. package/react/react.cjs.native.js +22 -0
  108. package/react/ssr/RenderPromises.d.ts +3 -2
  109. package/react/ssr/RenderPromises.d.ts.map +1 -1
  110. package/react/ssr/RenderPromises.js +25 -3
  111. package/react/ssr/RenderPromises.js.map +1 -1
  112. package/react/ssr/ssr.cjs +25 -3
  113. package/react/ssr/ssr.cjs.map +1 -1
  114. package/react/ssr/ssr.cjs.native.js +150 -0
  115. package/react/types/types.d.ts +10 -11
  116. package/react/types/types.d.ts.map +1 -1
  117. package/react/types/types.js.map +1 -1
  118. package/testing/core/core.cjs.native.js +288 -0
  119. package/testing/core/mocking/mockFetch.js +1 -1
  120. package/testing/core/mocking/mockFetch.js.map +1 -1
  121. package/testing/core/mocking/mockQueryManager.js +1 -1
  122. package/testing/core/mocking/mockWatchQuery.js +1 -1
  123. package/testing/core/wrap.js +1 -1
  124. package/testing/testing.cjs.native.js +58 -0
  125. package/utilities/common/canUse.d.ts +2 -0
  126. package/utilities/common/canUse.d.ts.map +1 -1
  127. package/utilities/common/canUse.js +6 -2
  128. package/utilities/common/canUse.js.map +1 -1
  129. package/utilities/common/mergeDeep.d.ts.map +1 -1
  130. package/utilities/common/mergeDeep.js +8 -11
  131. package/utilities/common/mergeDeep.js.map +1 -1
  132. package/utilities/common/mergeOptions.d.ts +5 -0
  133. package/utilities/common/mergeOptions.d.ts.map +1 -0
  134. package/utilities/common/mergeOptions.js +8 -0
  135. package/utilities/common/mergeOptions.js.map +1 -0
  136. package/utilities/globals/global.js +1 -2
  137. package/utilities/globals/globals.cjs.native.js +56 -0
  138. package/utilities/graphql/transform.d.ts +2 -2
  139. package/utilities/graphql/transform.d.ts.map +1 -1
  140. package/utilities/graphql/transform.js +1 -1
  141. package/utilities/graphql/transform.js.map +1 -1
  142. package/utilities/index.d.ts +1 -0
  143. package/utilities/index.d.ts.map +1 -1
  144. package/utilities/index.js +1 -0
  145. package/utilities/index.js.map +1 -1
  146. package/utilities/observables/Concast.d.ts +1 -0
  147. package/utilities/observables/Concast.d.ts.map +1 -1
  148. package/utilities/observables/Concast.js +5 -2
  149. package/utilities/observables/Concast.js.map +1 -1
  150. package/utilities/policies/pagination.d.ts.map +1 -1
  151. package/utilities/policies/pagination.js +9 -7
  152. package/utilities/policies/pagination.js.map +1 -1
  153. package/utilities/utilities.cjs +37 -23
  154. package/utilities/utilities.cjs.map +1 -1
  155. package/utilities/utilities.cjs.native.js +1281 -0
  156. package/version.js +1 -1
@@ -0,0 +1,623 @@
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(this.getObsQueryOptions());
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.getObsQueryOptions = function () {
230
+ var toMerge = [];
231
+ var globalDefaults = this.client.defaultOptions.watchQuery;
232
+ if (globalDefaults)
233
+ toMerge.push(globalDefaults);
234
+ if (this.queryHookOptions.defaultOptions) {
235
+ toMerge.push(this.queryHookOptions.defaultOptions);
236
+ }
237
+ toMerge.push(utilities.compact(this.observable && this.observable.options, this.watchQueryOptions));
238
+ return toMerge.reduce(core.mergeOptions);
239
+ };
240
+ InternalState.prototype.createWatchQueryOptions = function (_a) {
241
+ var _b;
242
+ if (_a === void 0) { _a = {}; }
243
+ 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"]);
244
+ var watchQueryOptions = Object.assign(otherOptions, { query: this.query });
245
+ if (this.renderPromises &&
246
+ (watchQueryOptions.fetchPolicy === 'network-only' ||
247
+ watchQueryOptions.fetchPolicy === 'cache-and-network')) {
248
+ watchQueryOptions.fetchPolicy = 'cache-first';
249
+ }
250
+ if (!watchQueryOptions.variables) {
251
+ watchQueryOptions.variables = {};
252
+ }
253
+ if (skip) {
254
+ var _c = watchQueryOptions.fetchPolicy, fetchPolicy = _c === void 0 ? this.getDefaultFetchPolicy() : _c, _d = watchQueryOptions.initialFetchPolicy, initialFetchPolicy = _d === void 0 ? fetchPolicy : _d;
255
+ Object.assign(watchQueryOptions, {
256
+ initialFetchPolicy: initialFetchPolicy,
257
+ fetchPolicy: 'standby',
258
+ });
259
+ }
260
+ else if (!watchQueryOptions.fetchPolicy) {
261
+ watchQueryOptions.fetchPolicy =
262
+ ((_b = this.observable) === null || _b === void 0 ? void 0 : _b.options.initialFetchPolicy) ||
263
+ this.getDefaultFetchPolicy();
264
+ }
265
+ return watchQueryOptions;
266
+ };
267
+ InternalState.prototype.getDefaultFetchPolicy = function () {
268
+ var _a, _b;
269
+ return (((_a = this.queryHookOptions.defaultOptions) === null || _a === void 0 ? void 0 : _a.fetchPolicy) ||
270
+ ((_b = this.client.defaultOptions.watchQuery) === null || _b === void 0 ? void 0 : _b.fetchPolicy) ||
271
+ "cache-first");
272
+ };
273
+ InternalState.prototype.onCompleted = function (data) { };
274
+ InternalState.prototype.onError = function (error) { };
275
+ InternalState.prototype.useObservableQuery = function () {
276
+ var obsQuery = this.observable =
277
+ this.renderPromises
278
+ && this.renderPromises.getSSRObservable(this.watchQueryOptions)
279
+ || this.observable
280
+ || this.client.watchQuery(this.getObsQueryOptions());
281
+ this.obsQueryFields = React.useMemo(function () { return ({
282
+ refetch: obsQuery.refetch.bind(obsQuery),
283
+ reobserve: obsQuery.reobserve.bind(obsQuery),
284
+ fetchMore: obsQuery.fetchMore.bind(obsQuery),
285
+ updateQuery: obsQuery.updateQuery.bind(obsQuery),
286
+ startPolling: obsQuery.startPolling.bind(obsQuery),
287
+ stopPolling: obsQuery.stopPolling.bind(obsQuery),
288
+ subscribeToMore: obsQuery.subscribeToMore.bind(obsQuery),
289
+ }); }, [obsQuery]);
290
+ var ssrAllowed = !(this.queryHookOptions.ssr === false ||
291
+ this.queryHookOptions.skip);
292
+ if (this.renderPromises && ssrAllowed) {
293
+ this.renderPromises.registerSSRObservable(obsQuery);
294
+ if (obsQuery.getCurrentResult().loading) {
295
+ this.renderPromises.addObservableQueryPromise(obsQuery);
296
+ }
297
+ }
298
+ return obsQuery;
299
+ };
300
+ InternalState.prototype.setResult = function (nextResult) {
301
+ var previousResult = this.result;
302
+ if (previousResult && previousResult.data) {
303
+ this.previousData = previousResult.data;
304
+ }
305
+ this.result = nextResult;
306
+ this.forceUpdate();
307
+ this.handleErrorOrCompleted(nextResult);
308
+ };
309
+ InternalState.prototype.handleErrorOrCompleted = function (result) {
310
+ if (!result.loading) {
311
+ if (result.error) {
312
+ this.onError(result.error);
313
+ }
314
+ else if (result.data) {
315
+ this.onCompleted(result.data);
316
+ }
317
+ }
318
+ };
319
+ InternalState.prototype.getCurrentResult = function () {
320
+ if (!this.result) {
321
+ this.handleErrorOrCompleted(this.result = this.observable.getCurrentResult());
322
+ }
323
+ return this.result;
324
+ };
325
+ InternalState.prototype.toQueryResult = function (result) {
326
+ var queryResult = this.toQueryResultCache.get(result);
327
+ if (queryResult)
328
+ return queryResult;
329
+ var data = result.data; result.partial; var resultWithoutPartial = tslib.__rest(result, ["data", "partial"]);
330
+ 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: !this.queryHookOptions.skip, previousData: this.previousData }));
331
+ if (!queryResult.error && utilities.isNonEmptyArray(result.errors)) {
332
+ queryResult.error = new errors.ApolloError({ graphQLErrors: result.errors });
333
+ }
334
+ return queryResult;
335
+ };
336
+ InternalState.prototype.unsafeHandlePartialRefetch = function (result) {
337
+ if (result.partial &&
338
+ this.queryHookOptions.partialRefetch &&
339
+ !result.loading &&
340
+ (!result.data || Object.keys(result.data).length === 0) &&
341
+ this.observable.options.fetchPolicy !== 'cache-only') {
342
+ Object.assign(result, {
343
+ loading: true,
344
+ networkStatus: core.NetworkStatus.refetch,
345
+ });
346
+ this.observable.refetch();
347
+ }
348
+ };
349
+ return InternalState;
350
+ }());
351
+
352
+ var EAGER_METHODS = [
353
+ 'refetch',
354
+ 'reobserve',
355
+ 'fetchMore',
356
+ 'updateQuery',
357
+ 'startPolling',
358
+ 'subscribeToMore',
359
+ ];
360
+ function useLazyQuery(query, options) {
361
+ var internalState = useInternalState(useApolloClient(options && options.client), query);
362
+ var execOptionsRef = React.useRef();
363
+ var merged = execOptionsRef.current
364
+ ? utilities.mergeOptions(options, execOptionsRef.current)
365
+ : options;
366
+ var useQueryResult = internalState.useQuery(tslib.__assign(tslib.__assign({}, merged), { skip: !execOptionsRef.current }));
367
+ var initialFetchPolicy = useQueryResult.observable.options.initialFetchPolicy ||
368
+ internalState.getDefaultFetchPolicy();
369
+ var result = Object.assign(useQueryResult, {
370
+ called: !!execOptionsRef.current,
371
+ });
372
+ var eagerMethods = React.useMemo(function () {
373
+ var eagerMethods = {};
374
+ var _loop_1 = function (key) {
375
+ var method = result[key];
376
+ eagerMethods[key] = function () {
377
+ if (!execOptionsRef.current) {
378
+ execOptionsRef.current = Object.create(null);
379
+ internalState.forceUpdate();
380
+ }
381
+ return method.apply(this, arguments);
382
+ };
383
+ };
384
+ for (var _i = 0, EAGER_METHODS_1 = EAGER_METHODS; _i < EAGER_METHODS_1.length; _i++) {
385
+ var key = EAGER_METHODS_1[_i];
386
+ _loop_1(key);
387
+ }
388
+ return eagerMethods;
389
+ }, []);
390
+ Object.assign(result, eagerMethods);
391
+ var execute = React.useCallback(function (executeOptions) {
392
+ execOptionsRef.current = executeOptions ? tslib.__assign(tslib.__assign({}, executeOptions), { fetchPolicy: executeOptions.fetchPolicy || initialFetchPolicy }) : {
393
+ fetchPolicy: initialFetchPolicy,
394
+ };
395
+ var promise = internalState
396
+ .asyncUpdate()
397
+ .then(function (queryResult) { return Object.assign(queryResult, eagerMethods); });
398
+ promise.catch(function () { });
399
+ return promise;
400
+ }, []);
401
+ return [execute, result];
402
+ }
403
+
404
+ function useMutation(mutation, options) {
405
+ var client = useApolloClient(options === null || options === void 0 ? void 0 : options.client);
406
+ parser.verifyDocumentType(mutation, parser.DocumentType.Mutation);
407
+ var _a = React.useState({
408
+ called: false,
409
+ loading: false,
410
+ client: client,
411
+ }), result = _a[0], setResult = _a[1];
412
+ var ref = React.useRef({
413
+ result: result,
414
+ mutationId: 0,
415
+ isMounted: true,
416
+ client: client,
417
+ mutation: mutation,
418
+ options: options,
419
+ });
420
+ {
421
+ Object.assign(ref.current, { client: client, options: options, mutation: mutation });
422
+ }
423
+ var execute = React.useCallback(function (executeOptions) {
424
+ if (executeOptions === void 0) { executeOptions = {}; }
425
+ var _a = ref.current, client = _a.client, options = _a.options, mutation = _a.mutation;
426
+ var baseOptions = tslib.__assign(tslib.__assign({}, options), { mutation: mutation });
427
+ if (!ref.current.result.loading && !baseOptions.ignoreResults) {
428
+ setResult(ref.current.result = {
429
+ loading: true,
430
+ error: void 0,
431
+ data: void 0,
432
+ called: true,
433
+ client: client,
434
+ });
435
+ }
436
+ var mutationId = ++ref.current.mutationId;
437
+ var clientOptions = core.mergeOptions(baseOptions, executeOptions);
438
+ return client.mutate(clientOptions).then(function (response) {
439
+ var _a, _b, _c;
440
+ var data = response.data, errors$1 = response.errors;
441
+ var error = errors$1 && errors$1.length > 0
442
+ ? new errors.ApolloError({ graphQLErrors: errors$1 })
443
+ : void 0;
444
+ if (mutationId === ref.current.mutationId &&
445
+ !clientOptions.ignoreResults) {
446
+ var result_1 = {
447
+ called: true,
448
+ loading: false,
449
+ data: data,
450
+ error: error,
451
+ client: client,
452
+ };
453
+ if (ref.current.isMounted && !equality.equal(ref.current.result, result_1)) {
454
+ setResult(ref.current.result = result_1);
455
+ }
456
+ }
457
+ (_b = (_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onCompleted) === null || _b === void 0 ? void 0 : _b.call(_a, response.data);
458
+ (_c = executeOptions.onCompleted) === null || _c === void 0 ? void 0 : _c.call(executeOptions, response.data);
459
+ return response;
460
+ }).catch(function (error) {
461
+ var _a, _b, _c, _d;
462
+ if (mutationId === ref.current.mutationId &&
463
+ ref.current.isMounted) {
464
+ var result_2 = {
465
+ loading: false,
466
+ error: error,
467
+ data: void 0,
468
+ called: true,
469
+ client: client,
470
+ };
471
+ if (!equality.equal(ref.current.result, result_2)) {
472
+ setResult(ref.current.result = result_2);
473
+ }
474
+ }
475
+ if (((_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onError) || clientOptions.onError) {
476
+ (_c = (_b = ref.current.options) === null || _b === void 0 ? void 0 : _b.onError) === null || _c === void 0 ? void 0 : _c.call(_b, error);
477
+ (_d = executeOptions.onError) === null || _d === void 0 ? void 0 : _d.call(executeOptions, error);
478
+ return { data: void 0, errors: error };
479
+ }
480
+ throw error;
481
+ });
482
+ }, []);
483
+ var reset = React.useCallback(function () {
484
+ setResult({ called: false, loading: false, client: client });
485
+ }, []);
486
+ React.useEffect(function () {
487
+ ref.current.isMounted = true;
488
+ return function () {
489
+ ref.current.isMounted = false;
490
+ };
491
+ }, []);
492
+ return [execute, tslib.__assign({ reset: reset }, result)];
493
+ }
494
+
495
+ function useSubscription(subscription, options) {
496
+ var client = useApolloClient(options === null || options === void 0 ? void 0 : options.client);
497
+ parser.verifyDocumentType(subscription, parser.DocumentType.Subscription);
498
+ var _a = React.useState({
499
+ loading: !(options === null || options === void 0 ? void 0 : options.skip),
500
+ error: void 0,
501
+ data: void 0,
502
+ variables: options === null || options === void 0 ? void 0 : options.variables,
503
+ }), result = _a[0], setResult = _a[1];
504
+ var _b = React.useState(function () {
505
+ if (options === null || options === void 0 ? void 0 : options.skip) {
506
+ return null;
507
+ }
508
+ return client.subscribe({
509
+ query: subscription,
510
+ variables: options === null || options === void 0 ? void 0 : options.variables,
511
+ fetchPolicy: options === null || options === void 0 ? void 0 : options.fetchPolicy,
512
+ context: options === null || options === void 0 ? void 0 : options.context,
513
+ });
514
+ }), observable = _b[0], setObservable = _b[1];
515
+ var canResetObservableRef = React.useRef(false);
516
+ React.useEffect(function () {
517
+ return function () {
518
+ canResetObservableRef.current = true;
519
+ };
520
+ }, []);
521
+ var ref = React.useRef({ client: client, subscription: subscription, options: options });
522
+ React.useEffect(function () {
523
+ var _a, _b, _c, _d;
524
+ var shouldResubscribe = options === null || options === void 0 ? void 0 : options.shouldResubscribe;
525
+ if (typeof shouldResubscribe === 'function') {
526
+ shouldResubscribe = !!shouldResubscribe(options);
527
+ }
528
+ if (options === null || options === void 0 ? void 0 : options.skip) {
529
+ if (!(options === null || options === void 0 ? void 0 : options.skip) !== !((_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.skip) || canResetObservableRef.current) {
530
+ setResult({
531
+ loading: false,
532
+ data: void 0,
533
+ error: void 0,
534
+ variables: options === null || options === void 0 ? void 0 : options.variables,
535
+ });
536
+ setObservable(null);
537
+ canResetObservableRef.current = false;
538
+ }
539
+ }
540
+ else if ((shouldResubscribe !== false &&
541
+ (client !== ref.current.client ||
542
+ subscription !== ref.current.subscription ||
543
+ (options === null || options === void 0 ? void 0 : options.fetchPolicy) !== ((_b = ref.current.options) === null || _b === void 0 ? void 0 : _b.fetchPolicy) ||
544
+ !(options === null || options === void 0 ? void 0 : options.skip) !== !((_c = ref.current.options) === null || _c === void 0 ? void 0 : _c.skip) ||
545
+ !equality.equal(options === null || options === void 0 ? void 0 : options.variables, (_d = ref.current.options) === null || _d === void 0 ? void 0 : _d.variables))) ||
546
+ canResetObservableRef.current) {
547
+ setResult({
548
+ loading: true,
549
+ data: void 0,
550
+ error: void 0,
551
+ variables: options === null || options === void 0 ? void 0 : options.variables,
552
+ });
553
+ setObservable(client.subscribe({
554
+ query: subscription,
555
+ variables: options === null || options === void 0 ? void 0 : options.variables,
556
+ fetchPolicy: options === null || options === void 0 ? void 0 : options.fetchPolicy,
557
+ context: options === null || options === void 0 ? void 0 : options.context,
558
+ }));
559
+ canResetObservableRef.current = false;
560
+ }
561
+ Object.assign(ref.current, { client: client, subscription: subscription, options: options });
562
+ }, [client, subscription, options, canResetObservableRef.current]);
563
+ React.useEffect(function () {
564
+ if (!observable) {
565
+ return;
566
+ }
567
+ var subscription = observable.subscribe({
568
+ next: function (fetchResult) {
569
+ var _a, _b;
570
+ var result = {
571
+ loading: false,
572
+ data: fetchResult.data,
573
+ error: void 0,
574
+ variables: options === null || options === void 0 ? void 0 : options.variables,
575
+ };
576
+ setResult(result);
577
+ (_b = (_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onSubscriptionData) === null || _b === void 0 ? void 0 : _b.call(_a, {
578
+ client: client,
579
+ subscriptionData: result
580
+ });
581
+ },
582
+ error: function (error) {
583
+ setResult({
584
+ loading: false,
585
+ data: void 0,
586
+ error: error,
587
+ variables: options === null || options === void 0 ? void 0 : options.variables,
588
+ });
589
+ },
590
+ complete: function () {
591
+ var _a, _b;
592
+ (_b = (_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onSubscriptionComplete) === null || _b === void 0 ? void 0 : _b.call(_a);
593
+ },
594
+ });
595
+ return function () {
596
+ subscription.unsubscribe();
597
+ };
598
+ }, [observable]);
599
+ return result;
600
+ }
601
+
602
+ function useReactiveVar(rv) {
603
+ var value = rv();
604
+ var setValue = React.useState(value)[1];
605
+ React.useEffect(function () {
606
+ var probablySameValue = rv();
607
+ if (value !== probablySameValue) {
608
+ setValue(probablySameValue);
609
+ }
610
+ else {
611
+ return rv.onNextChange(setValue);
612
+ }
613
+ }, [value]);
614
+ return value;
615
+ }
616
+
617
+ exports.useApolloClient = useApolloClient;
618
+ exports.useLazyQuery = useLazyQuery;
619
+ exports.useMutation = useMutation;
620
+ exports.useQuery = useQuery;
621
+ exports.useReactiveVar = useReactiveVar;
622
+ exports.useSubscription = useSubscription;
623
+ //# 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"}