@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
package/core/core.cjs CHANGED
@@ -5,17 +5,17 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var globals = require('../utilities/globals');
6
6
  var tslib = require('tslib');
7
7
  var core = require('../link/core');
8
- var utilities = require('../utilities');
9
8
  var http = require('../link/http');
10
9
  var equality = require('@wry/equality');
11
10
  var cache = require('../cache');
11
+ var utilities = require('../utilities');
12
12
  var errors = require('../errors');
13
13
  var graphql = require('graphql');
14
14
  var utils = require('../link/utils');
15
15
  var tsInvariant = require('ts-invariant');
16
16
  var graphqlTag = require('graphql-tag');
17
17
 
18
- var version = '3.5.10';
18
+ var version = '3.6.9';
19
19
 
20
20
  exports.NetworkStatus = void 0;
21
21
  (function (NetworkStatus) {
@@ -32,7 +32,6 @@ function isNetworkRequestInFlight(networkStatus) {
32
32
  }
33
33
 
34
34
  var assign = Object.assign, hasOwnProperty$1 = Object.hasOwnProperty;
35
- var warnedAboutUpdateQuery = false;
36
35
  var ObservableQuery = (function (_super) {
37
36
  tslib.__extends(ObservableQuery, _super);
38
37
  function ObservableQuery(_a) {
@@ -65,16 +64,24 @@ var ObservableQuery = (function (_super) {
65
64
  }) || this;
66
65
  _this.observers = new Set();
67
66
  _this.subscriptions = new Set();
67
+ _this.queryInfo = queryInfo;
68
+ _this.queryManager = queryManager;
68
69
  _this.isTornDown = false;
69
- _this.options = options;
70
+ var _b = queryManager.defaultOptions.watchQuery, _c = _b === void 0 ? {} : _b, _d = _c.fetchPolicy, defaultFetchPolicy = _d === void 0 ? "cache-first" : _d;
71
+ var _e = options.fetchPolicy, fetchPolicy = _e === void 0 ? defaultFetchPolicy : _e, _f = options.initialFetchPolicy, initialFetchPolicy = _f === void 0 ? (fetchPolicy === "standby" ? defaultFetchPolicy : fetchPolicy) : _f;
72
+ _this.options = tslib.__assign(tslib.__assign({}, options), { initialFetchPolicy: initialFetchPolicy, fetchPolicy: fetchPolicy });
70
73
  _this.queryId = queryInfo.queryId || queryManager.generateQueryId();
71
- var opDef = utilities.getOperationDefinition(options.query);
74
+ var opDef = utilities.getOperationDefinition(_this.query);
72
75
  _this.queryName = opDef && opDef.name && opDef.name.value;
73
- _this.initialFetchPolicy = options.fetchPolicy || "cache-first";
74
- _this.queryManager = queryManager;
75
- _this.queryInfo = queryInfo;
76
76
  return _this;
77
77
  }
78
+ Object.defineProperty(ObservableQuery.prototype, "query", {
79
+ get: function () {
80
+ return this.queryManager.transform(this.options.query).document;
81
+ },
82
+ enumerable: false,
83
+ configurable: true
84
+ });
78
85
  Object.defineProperty(ObservableQuery.prototype, "variables", {
79
86
  get: function () {
80
87
  return this.options.variables;
@@ -188,7 +195,7 @@ var ObservableQuery = (function (_super) {
188
195
  reobserveOptions.fetchPolicy = 'network-only';
189
196
  }
190
197
  if (__DEV__ && variables && hasOwnProperty$1.call(variables, "variables")) {
191
- var queryDef = utilities.getQueryDefinition(this.options.query);
198
+ var queryDef = utilities.getQueryDefinition(this.query);
192
199
  var vars = queryDef.variableDefinitions;
193
200
  if (!vars || !vars.some(function (v) { return v.variable.name.value === "variables"; })) {
194
201
  __DEV__ && globals.invariant.warn("Called refetch(".concat(JSON.stringify(variables), ") for query ").concat(((_a = queryDef.name) === null || _a === void 0 ? void 0 : _a.value) || JSON.stringify(queryDef), ", which does not declare a $variables variable.\nDid you mean to call refetch(variables) instead of refetch({ variables })?"));
@@ -202,37 +209,51 @@ var ObservableQuery = (function (_super) {
202
209
  };
203
210
  ObservableQuery.prototype.fetchMore = function (fetchMoreOptions) {
204
211
  var _this = this;
205
- var combinedOptions = tslib.__assign(tslib.__assign({}, (fetchMoreOptions.query ? fetchMoreOptions : tslib.__assign(tslib.__assign(tslib.__assign({}, this.options), fetchMoreOptions), { variables: tslib.__assign(tslib.__assign({}, this.options.variables), fetchMoreOptions.variables) }))), { fetchPolicy: "no-cache" });
212
+ var combinedOptions = tslib.__assign(tslib.__assign({}, (fetchMoreOptions.query ? fetchMoreOptions : tslib.__assign(tslib.__assign(tslib.__assign(tslib.__assign({}, this.options), { query: this.query }), fetchMoreOptions), { variables: tslib.__assign(tslib.__assign({}, this.options.variables), fetchMoreOptions.variables) }))), { fetchPolicy: "no-cache" });
206
213
  var qid = this.queryManager.generateQueryId();
214
+ var queryInfo = this.queryInfo;
215
+ var originalNetworkStatus = queryInfo.networkStatus;
216
+ queryInfo.networkStatus = exports.NetworkStatus.fetchMore;
207
217
  if (combinedOptions.notifyOnNetworkStatusChange) {
208
- this.queryInfo.networkStatus = exports.NetworkStatus.fetchMore;
209
218
  this.observe();
210
219
  }
220
+ var updatedQuerySet = new Set();
211
221
  return this.queryManager.fetchQuery(qid, combinedOptions, exports.NetworkStatus.fetchMore).then(function (fetchMoreResult) {
212
- var data = fetchMoreResult.data;
213
- var updateQuery = fetchMoreOptions.updateQuery;
214
- if (updateQuery) {
215
- if (__DEV__ &&
216
- !warnedAboutUpdateQuery) {
217
- __DEV__ && globals.invariant.warn("The updateQuery callback for fetchMore is deprecated, and will be removed\nin the next major version of Apollo Client.\n\nPlease convert updateQuery functions to field policies with appropriate\nread and merge functions, or use/adapt a helper function (such as\nconcatPagination, offsetLimitPagination, or relayStylePagination) from\n@apollo/client/utilities.\n\nThe field policy system handles pagination more effectively than a\nhand-written updateQuery function, and you only need to define the policy\nonce, rather than every time you call fetchMore.");
218
- warnedAboutUpdateQuery = true;
219
- }
220
- _this.updateQuery(function (previous) { return updateQuery(previous, {
221
- fetchMoreResult: data,
222
- variables: combinedOptions.variables,
223
- }); });
224
- }
225
- else {
226
- _this.queryManager.cache.writeQuery({
227
- query: combinedOptions.query,
228
- variables: combinedOptions.variables,
229
- data: data,
230
- });
222
+ _this.queryManager.removeQuery(qid);
223
+ if (queryInfo.networkStatus === exports.NetworkStatus.fetchMore) {
224
+ queryInfo.networkStatus = originalNetworkStatus;
231
225
  }
226
+ _this.queryManager.cache.batch({
227
+ update: function (cache) {
228
+ var updateQuery = fetchMoreOptions.updateQuery;
229
+ if (updateQuery) {
230
+ cache.updateQuery({
231
+ query: _this.query,
232
+ variables: _this.variables,
233
+ returnPartialData: true,
234
+ optimistic: false,
235
+ }, function (previous) { return updateQuery(previous, {
236
+ fetchMoreResult: fetchMoreResult.data,
237
+ variables: combinedOptions.variables,
238
+ }); });
239
+ }
240
+ else {
241
+ cache.writeQuery({
242
+ query: combinedOptions.query,
243
+ variables: combinedOptions.variables,
244
+ data: fetchMoreResult.data,
245
+ });
246
+ }
247
+ },
248
+ onWatchUpdated: function (watch) {
249
+ updatedQuerySet.add(watch.query);
250
+ },
251
+ });
232
252
  return fetchMoreResult;
233
253
  }).finally(function () {
234
- _this.queryManager.stopQuery(qid);
235
- _this.reobserve();
254
+ if (!updatedQuerySet.has(_this.query)) {
255
+ reobserveCacheFirst(_this);
256
+ }
236
257
  });
237
258
  };
238
259
  ObservableQuery.prototype.subscribeToMore = function (options) {
@@ -285,7 +306,7 @@ var ObservableQuery = (function (_super) {
285
306
  return Promise.resolve();
286
307
  }
287
308
  return this.reobserve({
288
- fetchPolicy: this.initialFetchPolicy,
309
+ fetchPolicy: this.options.initialFetchPolicy,
289
310
  variables: variables,
290
311
  }, exports.NetworkStatus.setVariables);
291
312
  };
@@ -317,6 +338,27 @@ var ObservableQuery = (function (_super) {
317
338
  this.options.pollInterval = 0;
318
339
  this.updatePolling();
319
340
  };
341
+ ObservableQuery.prototype.applyNextFetchPolicy = function (reason, options) {
342
+ if (options.nextFetchPolicy) {
343
+ var _a = options.fetchPolicy, fetchPolicy = _a === void 0 ? "cache-first" : _a, _b = options.initialFetchPolicy, initialFetchPolicy = _b === void 0 ? fetchPolicy : _b;
344
+ if (fetchPolicy === "standby") ;
345
+ else if (typeof options.nextFetchPolicy === "function") {
346
+ options.fetchPolicy = options.nextFetchPolicy(fetchPolicy, {
347
+ reason: reason,
348
+ options: options,
349
+ observable: this,
350
+ initialFetchPolicy: initialFetchPolicy,
351
+ });
352
+ }
353
+ else if (reason === "variables-changed") {
354
+ options.fetchPolicy = initialFetchPolicy;
355
+ }
356
+ else {
357
+ options.fetchPolicy = options.nextFetchPolicy;
358
+ }
359
+ }
360
+ return options.fetchPolicy;
361
+ };
320
362
  ObservableQuery.prototype.fetch = function (options, newNetworkStatus) {
321
363
  this.queryManager.setObservableQuery(this);
322
364
  return this.queryManager.fetchQueryObservable(this.queryId, options, newNetworkStatus);
@@ -379,16 +421,19 @@ var ObservableQuery = (function (_super) {
379
421
  newNetworkStatus === exports.NetworkStatus.fetchMore ||
380
422
  newNetworkStatus === exports.NetworkStatus.poll;
381
423
  var oldVariables = this.options.variables;
424
+ var oldFetchPolicy = this.options.fetchPolicy;
425
+ var mergedOptions = utilities.compact(this.options, newOptions || {});
382
426
  var options = useDisposableConcast
383
- ? utilities.compact(this.options, newOptions)
384
- : assign(this.options, utilities.compact(newOptions));
427
+ ? mergedOptions
428
+ : assign(this.options, mergedOptions);
385
429
  if (!useDisposableConcast) {
386
430
  this.updatePolling();
387
431
  if (newOptions &&
388
432
  newOptions.variables &&
389
- !newOptions.fetchPolicy &&
390
- !equality.equal(newOptions.variables, oldVariables)) {
391
- options.fetchPolicy = this.initialFetchPolicy;
433
+ !equality.equal(newOptions.variables, oldVariables) &&
434
+ options.fetchPolicy !== "standby" &&
435
+ options.fetchPolicy === oldFetchPolicy) {
436
+ this.applyNextFetchPolicy("variables-changed", options);
392
437
  if (newNetworkStatus === void 0) {
393
438
  newNetworkStatus = exports.NetworkStatus.setVariables;
394
439
  }
@@ -406,7 +451,7 @@ var ObservableQuery = (function (_super) {
406
451
  };
407
452
  if (!useDisposableConcast) {
408
453
  if (this.concast && this.observer) {
409
- this.concast.removeObserver(this.observer, true);
454
+ this.concast.removeObserver(this.observer);
410
455
  }
411
456
  this.concast = concast;
412
457
  this.observer = observer;
@@ -452,6 +497,23 @@ var ObservableQuery = (function (_super) {
452
497
  return ObservableQuery;
453
498
  }(utilities.Observable));
454
499
  utilities.fixObservableSubclass(ObservableQuery);
500
+ function reobserveCacheFirst(obsQuery) {
501
+ var _a = obsQuery.options, fetchPolicy = _a.fetchPolicy, nextFetchPolicy = _a.nextFetchPolicy;
502
+ if (fetchPolicy === "cache-and-network" ||
503
+ fetchPolicy === "network-only") {
504
+ return obsQuery.reobserve({
505
+ fetchPolicy: "cache-first",
506
+ nextFetchPolicy: function () {
507
+ this.nextFetchPolicy = nextFetchPolicy;
508
+ if (typeof nextFetchPolicy === "function") {
509
+ return nextFetchPolicy.apply(this, arguments);
510
+ }
511
+ return fetchPolicy;
512
+ },
513
+ });
514
+ }
515
+ return obsQuery.reobserve();
516
+ }
455
517
  function defaultSubscriptionObserverErrorCallback(error) {
456
518
  __DEV__ && globals.invariant.error('Unhandled error', error.message, error.stack);
457
519
  }
@@ -460,14 +522,6 @@ function logMissingFieldErrors(missing) {
460
522
  __DEV__ && globals.invariant.debug("Missing cache result fields: ".concat(JSON.stringify(missing)), missing);
461
523
  }
462
524
  }
463
- function applyNextFetchPolicy(options) {
464
- var _a = options.fetchPolicy, fetchPolicy = _a === void 0 ? "cache-first" : _a, nextFetchPolicy = options.nextFetchPolicy;
465
- if (nextFetchPolicy) {
466
- options.fetchPolicy = typeof nextFetchPolicy === "function"
467
- ? nextFetchPolicy.call(options, fetchPolicy)
468
- : nextFetchPolicy;
469
- }
470
- }
471
525
 
472
526
  var LocalState = (function () {
473
527
  function LocalState(_a) {
@@ -850,11 +904,12 @@ var QueryInfo = (function () {
850
904
  if (oq) {
851
905
  oq["queryInfo"] = this;
852
906
  this.listeners.add(this.oqListener = function () {
853
- if (_this.getDiff().fromOptimisticTransaction) {
907
+ var diff = _this.getDiff();
908
+ if (diff.fromOptimisticTransaction) {
854
909
  oq["observe"]();
855
910
  }
856
911
  else {
857
- oq.reobserve();
912
+ reobserveCacheFirst(oq);
858
913
  }
859
914
  });
860
915
  }
@@ -999,7 +1054,7 @@ function shouldWriteResult(result, errorPolicy) {
999
1054
  var hasOwnProperty = Object.prototype.hasOwnProperty;
1000
1055
  var QueryManager = (function () {
1001
1056
  function QueryManager(_a) {
1002
- var cache = _a.cache, link = _a.link, _b = _a.queryDeduplication, queryDeduplication = _b === void 0 ? false : _b, onBroadcast = _a.onBroadcast, _c = _a.ssrMode, ssrMode = _c === void 0 ? false : _c, _d = _a.clientAwareness, clientAwareness = _d === void 0 ? {} : _d, localState = _a.localState, assumeImmutableResults = _a.assumeImmutableResults;
1057
+ var cache = _a.cache, link = _a.link, defaultOptions = _a.defaultOptions, _b = _a.queryDeduplication, queryDeduplication = _b === void 0 ? false : _b, onBroadcast = _a.onBroadcast, _c = _a.ssrMode, ssrMode = _c === void 0 ? false : _c, _d = _a.clientAwareness, clientAwareness = _d === void 0 ? {} : _d, localState = _a.localState, assumeImmutableResults = _a.assumeImmutableResults;
1003
1058
  this.clientAwareness = {};
1004
1059
  this.queries = new Map();
1005
1060
  this.fetchCancelFns = new Map();
@@ -1010,6 +1065,7 @@ var QueryManager = (function () {
1010
1065
  this.inFlightLinkObservables = new Map();
1011
1066
  this.cache = cache;
1012
1067
  this.link = link;
1068
+ this.defaultOptions = defaultOptions || Object.create(null);
1013
1069
  this.queryDeduplication = queryDeduplication;
1014
1070
  this.clientAwareness = clientAwareness;
1015
1071
  this.localState = localState || new LocalState({ cache: cache });
@@ -1031,11 +1087,12 @@ var QueryManager = (function () {
1031
1087
  this.fetchCancelFns.clear();
1032
1088
  };
1033
1089
  QueryManager.prototype.mutate = function (_a) {
1034
- var mutation = _a.mutation, variables = _a.variables, optimisticResponse = _a.optimisticResponse, updateQueries = _a.updateQueries, _b = _a.refetchQueries, refetchQueries = _b === void 0 ? [] : _b, _c = _a.awaitRefetchQueries, awaitRefetchQueries = _c === void 0 ? false : _c, updateWithProxyFn = _a.update, onQueryUpdated = _a.onQueryUpdated, _d = _a.errorPolicy, errorPolicy = _d === void 0 ? 'none' : _d, _e = _a.fetchPolicy, fetchPolicy = _e === void 0 ? 'network-only' : _e, keepRootFields = _a.keepRootFields, context = _a.context;
1090
+ var _b, _c;
1091
+ var mutation = _a.mutation, variables = _a.variables, optimisticResponse = _a.optimisticResponse, updateQueries = _a.updateQueries, _d = _a.refetchQueries, refetchQueries = _d === void 0 ? [] : _d, _e = _a.awaitRefetchQueries, awaitRefetchQueries = _e === void 0 ? false : _e, updateWithProxyFn = _a.update, onQueryUpdated = _a.onQueryUpdated, _f = _a.fetchPolicy, fetchPolicy = _f === void 0 ? ((_b = this.defaultOptions.mutate) === null || _b === void 0 ? void 0 : _b.fetchPolicy) || "network-only" : _f, _g = _a.errorPolicy, errorPolicy = _g === void 0 ? ((_c = this.defaultOptions.mutate) === null || _c === void 0 ? void 0 : _c.errorPolicy) || "none" : _g, keepRootFields = _a.keepRootFields, context = _a.context;
1035
1092
  return tslib.__awaiter(this, void 0, void 0, function () {
1036
1093
  var mutationId, mutationStoreValue, self;
1037
- return tslib.__generator(this, function (_f) {
1038
- switch (_f.label) {
1094
+ return tslib.__generator(this, function (_h) {
1095
+ switch (_h.label) {
1039
1096
  case 0:
1040
1097
  __DEV__ ? globals.invariant(mutation, 'mutation option is required. You must specify your GraphQL document in the mutation option.') : globals.invariant(mutation, 12);
1041
1098
  __DEV__ ? globals.invariant(fetchPolicy === 'network-only' ||
@@ -1047,8 +1104,8 @@ var QueryManager = (function () {
1047
1104
  if (!this.transform(mutation).hasClientExports) return [3, 2];
1048
1105
  return [4, this.localState.addExportedVariables(mutation, variables, context)];
1049
1106
  case 1:
1050
- variables = (_f.sent());
1051
- _f.label = 2;
1107
+ variables = (_h.sent());
1108
+ _h.label = 2;
1052
1109
  case 2:
1053
1110
  mutationStoreValue = this.mutationStore &&
1054
1111
  (this.mutationStore[mutationId] = {
@@ -1315,9 +1372,9 @@ var QueryManager = (function () {
1315
1372
  });
1316
1373
  this.queries.set(observable.queryId, queryInfo);
1317
1374
  queryInfo.init({
1318
- document: options.query,
1375
+ document: observable.query,
1319
1376
  observableQuery: observable,
1320
- variables: options.variables,
1377
+ variables: observable.variables,
1321
1378
  });
1322
1379
  return observable;
1323
1380
  };
@@ -1501,8 +1558,10 @@ var QueryManager = (function () {
1501
1558
  };
1502
1559
  QueryManager.prototype.removeQuery = function (queryId) {
1503
1560
  this.fetchCancelFns.delete(queryId);
1504
- this.getQuery(queryId).stop();
1505
- this.queries.delete(queryId);
1561
+ if (this.queries.has(queryId)) {
1562
+ this.getQuery(queryId).stop();
1563
+ this.queries.delete(queryId);
1564
+ }
1506
1565
  };
1507
1566
  QueryManager.prototype.broadcastQueries = function () {
1508
1567
  if (this.onBroadcast)
@@ -1586,10 +1645,11 @@ var QueryManager = (function () {
1586
1645
  var aqr = {
1587
1646
  data: result.data,
1588
1647
  loading: false,
1589
- networkStatus: queryInfo.networkStatus || exports.NetworkStatus.ready,
1648
+ networkStatus: exports.NetworkStatus.ready,
1590
1649
  };
1591
1650
  if (hasErrors && options.errorPolicy !== "ignore") {
1592
1651
  aqr.errors = result.errors;
1652
+ aqr.networkStatus = exports.NetworkStatus.error;
1593
1653
  }
1594
1654
  return aqr;
1595
1655
  }, function (networkError) {
@@ -1608,7 +1668,8 @@ var QueryManager = (function () {
1608
1668
  var query = this.transform(options.query).document;
1609
1669
  var variables = this.getVariables(query, options.variables);
1610
1670
  var queryInfo = this.getQuery(queryId);
1611
- var _a = options.fetchPolicy, fetchPolicy = _a === void 0 ? "cache-first" : _a, _b = options.errorPolicy, errorPolicy = _b === void 0 ? "none" : _b, _c = options.returnPartialData, returnPartialData = _c === void 0 ? false : _c, _d = options.notifyOnNetworkStatusChange, notifyOnNetworkStatusChange = _d === void 0 ? false : _d, _e = options.context, context = _e === void 0 ? {} : _e;
1671
+ var defaults = this.defaultOptions.watchQuery;
1672
+ var _a = options.fetchPolicy, fetchPolicy = _a === void 0 ? defaults && defaults.fetchPolicy || "cache-first" : _a, _b = options.errorPolicy, errorPolicy = _b === void 0 ? defaults && defaults.errorPolicy || "none" : _b, _c = options.returnPartialData, returnPartialData = _c === void 0 ? false : _c, _d = options.notifyOnNetworkStatusChange, notifyOnNetworkStatusChange = _d === void 0 ? false : _d, _e = options.context, context = _e === void 0 ? {} : _e;
1612
1673
  var normalized = Object.assign({}, options, {
1613
1674
  query: query,
1614
1675
  variables: variables,
@@ -1620,18 +1681,23 @@ var QueryManager = (function () {
1620
1681
  });
1621
1682
  var fromVariables = function (variables) {
1622
1683
  normalized.variables = variables;
1623
- return _this.fetchQueryByPolicy(queryInfo, normalized, networkStatus);
1684
+ var concastSources = _this.fetchQueryByPolicy(queryInfo, normalized, networkStatus);
1685
+ if (normalized.fetchPolicy !== "standby" &&
1686
+ concastSources.length > 0 &&
1687
+ queryInfo.observableQuery) {
1688
+ queryInfo.observableQuery["applyNextFetchPolicy"]("after-fetch", options);
1689
+ }
1690
+ return concastSources;
1624
1691
  };
1692
+ var cleanupCancelFn = function () { return _this.fetchCancelFns.delete(queryId); };
1625
1693
  this.fetchCancelFns.set(queryId, function (reason) {
1694
+ cleanupCancelFn();
1626
1695
  setTimeout(function () { return concast.cancel(reason); });
1627
1696
  });
1628
1697
  var concast = new utilities.Concast(this.transform(normalized.query).hasClientExports
1629
1698
  ? this.localState.addExportedVariables(normalized.query, normalized.variables, normalized.context).then(fromVariables)
1630
1699
  : fromVariables(normalized.variables));
1631
- concast.cleanup(function () {
1632
- _this.fetchCancelFns.delete(queryId);
1633
- applyNextFetchPolicy(options);
1634
- });
1700
+ concast.promise.then(cleanupCancelFn, cleanupCancelFn);
1635
1701
  return concast;
1636
1702
  };
1637
1703
  QueryManager.prototype.refetchQueries = function (_a) {
@@ -1707,7 +1773,7 @@ var QueryManager = (function () {
1707
1773
  var query = _a.query, variables = _a.variables, fetchPolicy = _a.fetchPolicy, refetchWritePolicy = _a.refetchWritePolicy, errorPolicy = _a.errorPolicy, returnPartialData = _a.returnPartialData, context = _a.context, notifyOnNetworkStatusChange = _a.notifyOnNetworkStatusChange;
1708
1774
  var oldNetworkStatus = queryInfo.networkStatus;
1709
1775
  queryInfo.init({
1710
- document: query,
1776
+ document: this.transform(query).document,
1711
1777
  variables: variables,
1712
1778
  networkStatus: networkStatus,
1713
1779
  });
@@ -1736,14 +1802,12 @@ var QueryManager = (function () {
1736
1802
  (networkStatus === exports.NetworkStatus.refetch &&
1737
1803
  refetchWritePolicy !== "merge") ? 1
1738
1804
  : 2;
1739
- var resultsFromLink = function () {
1740
- return _this.getResultsFromLink(queryInfo, cacheWriteBehavior, {
1741
- variables: variables,
1742
- context: context,
1743
- fetchPolicy: fetchPolicy,
1744
- errorPolicy: errorPolicy,
1745
- });
1746
- };
1805
+ var resultsFromLink = function () { return _this.getResultsFromLink(queryInfo, cacheWriteBehavior, {
1806
+ variables: variables,
1807
+ context: context,
1808
+ fetchPolicy: fetchPolicy,
1809
+ errorPolicy: errorPolicy,
1810
+ }); };
1747
1811
  var shouldNotify = notifyOnNetworkStatusChange &&
1748
1812
  typeof oldNetworkStatus === "number" &&
1749
1813
  oldNetworkStatus !== networkStatus &&
@@ -1818,15 +1882,9 @@ var QueryManager = (function () {
1818
1882
  }());
1819
1883
 
1820
1884
  var hasSuggestedDevtools = false;
1821
- function mergeOptions(defaults, options) {
1822
- return utilities.compact(defaults, options, options.variables && {
1823
- variables: tslib.__assign(tslib.__assign({}, defaults.variables), options.variables),
1824
- });
1825
- }
1826
1885
  var ApolloClient = (function () {
1827
1886
  function ApolloClient(options) {
1828
1887
  var _this = this;
1829
- this.defaultOptions = {};
1830
1888
  this.resetStoreCallbacks = [];
1831
1889
  this.clearStoreCallbacks = [];
1832
1890
  var uri = options.uri, credentials = options.credentials, headers = options.headers, cache = options.cache, _a = options.ssrMode, ssrMode = _a === void 0 ? false : _a, _b = options.ssrForceFetchDelay, ssrForceFetchDelay = _b === void 0 ? 0 : _b, _c = options.connectToDevTools, connectToDevTools = _c === void 0 ? typeof window === 'object' &&
@@ -1847,7 +1905,7 @@ var ApolloClient = (function () {
1847
1905
  this.cache = cache;
1848
1906
  this.disableNetworkFetches = ssrMode || ssrForceFetchDelay > 0;
1849
1907
  this.queryDeduplication = queryDeduplication;
1850
- this.defaultOptions = defaultOptions || {};
1908
+ this.defaultOptions = defaultOptions || Object.create(null);
1851
1909
  this.typeDefs = typeDefs;
1852
1910
  if (ssrForceFetchDelay) {
1853
1911
  setTimeout(function () { return (_this.disableNetworkFetches = false); }, ssrForceFetchDelay);
@@ -1894,6 +1952,7 @@ var ApolloClient = (function () {
1894
1952
  this.queryManager = new QueryManager({
1895
1953
  cache: this.cache,
1896
1954
  link: this.link,
1955
+ defaultOptions: this.defaultOptions,
1897
1956
  queryDeduplication: queryDeduplication,
1898
1957
  ssrMode: ssrMode,
1899
1958
  clientAwareness: {
@@ -1921,7 +1980,7 @@ var ApolloClient = (function () {
1921
1980
  };
1922
1981
  ApolloClient.prototype.watchQuery = function (options) {
1923
1982
  if (this.defaultOptions.watchQuery) {
1924
- options = mergeOptions(this.defaultOptions.watchQuery, options);
1983
+ options = utilities.mergeOptions(this.defaultOptions.watchQuery, options);
1925
1984
  }
1926
1985
  if (this.disableNetworkFetches &&
1927
1986
  (options.fetchPolicy === 'network-only' ||
@@ -1932,7 +1991,7 @@ var ApolloClient = (function () {
1932
1991
  };
1933
1992
  ApolloClient.prototype.query = function (options) {
1934
1993
  if (this.defaultOptions.query) {
1935
- options = mergeOptions(this.defaultOptions.query, options);
1994
+ options = utilities.mergeOptions(this.defaultOptions.query, options);
1936
1995
  }
1937
1996
  __DEV__ ? globals.invariant(options.fetchPolicy !== 'cache-and-network', 'The cache-and-network fetchPolicy does not work with client.query, because ' +
1938
1997
  'client.query can only return a single result. Please use client.watchQuery ' +
@@ -1945,7 +2004,7 @@ var ApolloClient = (function () {
1945
2004
  };
1946
2005
  ApolloClient.prototype.mutate = function (options) {
1947
2006
  if (this.defaultOptions.mutate) {
1948
- options = mergeOptions(this.defaultOptions.mutate, options);
2007
+ options = utilities.mergeOptions(this.defaultOptions.mutate, options);
1949
2008
  }
1950
2009
  return this.queryManager.mutate(options);
1951
2010
  };
@@ -2054,15 +2113,16 @@ var ApolloClient = (function () {
2054
2113
 
2055
2114
  tsInvariant.setVerbosity(globals.DEV ? "log" : "silent");
2056
2115
 
2057
- exports.Observable = utilities.Observable;
2058
- exports.isReference = utilities.isReference;
2059
- exports.makeReference = utilities.makeReference;
2060
2116
  exports.ApolloCache = cache.ApolloCache;
2061
2117
  exports.Cache = cache.Cache;
2062
2118
  exports.InMemoryCache = cache.InMemoryCache;
2063
2119
  exports.MissingFieldError = cache.MissingFieldError;
2064
2120
  exports.defaultDataIdFromObject = cache.defaultDataIdFromObject;
2065
2121
  exports.makeVar = cache.makeVar;
2122
+ exports.Observable = utilities.Observable;
2123
+ exports.isReference = utilities.isReference;
2124
+ exports.makeReference = utilities.makeReference;
2125
+ exports.mergeOptions = utilities.mergeOptions;
2066
2126
  exports.ApolloError = errors.ApolloError;
2067
2127
  exports.isApolloError = errors.isApolloError;
2068
2128
  exports.fromError = utils.fromError;
@@ -2077,8 +2137,6 @@ exports.gql = graphqlTag.gql;
2077
2137
  exports.resetCaches = graphqlTag.resetCaches;
2078
2138
  exports.ApolloClient = ApolloClient;
2079
2139
  exports.ObservableQuery = ObservableQuery;
2080
- exports.applyNextFetchPolicy = applyNextFetchPolicy;
2081
- exports.mergeOptions = mergeOptions;
2082
2140
  for (var k in core) {
2083
2141
  if (k !== 'default' && !exports.hasOwnProperty(k)) exports[k] = core[k];
2084
2142
  }