@apollo/client 3.4.4 → 3.4.8

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 (66) hide show
  1. package/apollo-client.cjs.js +971 -76
  2. package/apollo-client.cjs.js.map +1 -1
  3. package/apollo-core.cjs.js +5768 -0
  4. package/apollo-core.cjs.js.map +1 -0
  5. package/apollo-core.cjs.min.js +1 -0
  6. package/cache/cache.cjs.js +12 -9
  7. package/cache/cache.cjs.js.map +1 -1
  8. package/cache/inmemory/policies.js +9 -6
  9. package/cache/inmemory/policies.js.map +1 -1
  10. package/cache/inmemory/writeToStore.d.ts +1 -1
  11. package/cache/inmemory/writeToStore.d.ts.map +1 -1
  12. package/cache/inmemory/writeToStore.js +3 -3
  13. package/cache/inmemory/writeToStore.js.map +1 -1
  14. package/core/ObservableQuery.d.ts +9 -6
  15. package/core/ObservableQuery.d.ts.map +1 -1
  16. package/core/ObservableQuery.js +70 -45
  17. package/core/ObservableQuery.js.map +1 -1
  18. package/core/QueryInfo.d.ts +5 -3
  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 +3 -3
  23. package/core/QueryManager.d.ts.map +1 -1
  24. package/core/QueryManager.js +15 -13
  25. package/core/QueryManager.js.map +1 -1
  26. package/core/core.cjs.js +89 -59
  27. package/core/core.cjs.js.map +1 -1
  28. package/core/watchQueryOptions.d.ts +2 -1
  29. package/core/watchQueryOptions.d.ts.map +1 -1
  30. package/core/watchQueryOptions.js.map +1 -1
  31. package/invariantErrorCodes.js +4 -2
  32. package/link/http/createHttpLink.d.ts.map +1 -1
  33. package/link/http/createHttpLink.js +7 -5
  34. package/link/http/createHttpLink.js.map +1 -1
  35. package/link/http/http.cjs.js +6 -5
  36. package/link/http/http.cjs.js.map +1 -1
  37. package/package.json +8 -8
  38. package/react/data/QueryData.d.ts +2 -1
  39. package/react/data/QueryData.d.ts.map +1 -1
  40. package/react/data/QueryData.js +8 -8
  41. package/react/data/QueryData.js.map +1 -1
  42. package/react/data/data.cjs.js +8 -8
  43. package/react/data/data.cjs.js.map +1 -1
  44. package/react/hooks/hooks.cjs.js +1 -0
  45. package/react/hooks/hooks.cjs.js.map +1 -1
  46. package/react/hooks/utils/useBaseQuery.d.ts.map +1 -1
  47. package/react/hooks/utils/useBaseQuery.js +1 -0
  48. package/react/hooks/utils/useBaseQuery.js.map +1 -1
  49. package/testing/testing.cjs.js +0 -5
  50. package/testing/testing.cjs.js.map +1 -1
  51. package/utilities/index.d.ts +1 -0
  52. package/utilities/index.d.ts.map +1 -1
  53. package/utilities/index.js +1 -0
  54. package/utilities/index.js.map +1 -1
  55. package/utilities/testing/index.d.ts +0 -1
  56. package/utilities/testing/index.d.ts.map +1 -1
  57. package/utilities/testing/index.js +0 -1
  58. package/utilities/testing/index.js.map +1 -1
  59. package/utilities/utilities.cjs.js +1 -0
  60. package/utilities/utilities.cjs.js.map +1 -1
  61. package/version.js +1 -1
  62. package/apollo-client.cjs.min.js +0 -1
  63. package/utilities/testing/stripSymbols.d.ts +0 -2
  64. package/utilities/testing/stripSymbols.d.ts.map +0 -1
  65. package/utilities/testing/stripSymbols.js +0 -4
  66. package/utilities/testing/stripSymbols.js.map +0 -1
@@ -2,17 +2,32 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var tslib = require('tslib');
5
6
  var tsInvariant = require('ts-invariant');
7
+ var equality = require('@wry/equality');
6
8
  var process$1 = require('ts-invariant/process');
7
9
  var graphql = require('graphql');
8
- var tslib = require('tslib');
9
- var equality = require('@wry/equality');
10
10
  var zenObservableTs = require('zen-observable-ts');
11
11
  require('symbol-observable');
12
12
  var optimism = require('optimism');
13
13
  var context = require('@wry/context');
14
14
  var trie = require('@wry/trie');
15
15
  var graphqlTag = require('graphql-tag');
16
+ var React = require('react');
17
+
18
+ function _interopNamespace(e) {
19
+ if (e && e.__esModule) return e;
20
+ var n = Object.create(null);
21
+ if (e) {
22
+ Object.keys(e).forEach(function (k) {
23
+ n[k] = e[k];
24
+ });
25
+ }
26
+ n['default'] = e;
27
+ return Object.freeze(n);
28
+ }
29
+
30
+ var React__namespace = /*#__PURE__*/_interopNamespace(React);
16
31
 
17
32
  function maybe(thunk) {
18
33
  try {
@@ -1292,7 +1307,7 @@ var concat = ApolloLink.concat;
1292
1307
 
1293
1308
  var execute = ApolloLink.execute;
1294
1309
 
1295
- var version = '3.4.4';
1310
+ var version = '3.4.8';
1296
1311
 
1297
1312
  var hasOwnProperty$1 = Object.prototype.hasOwnProperty;
1298
1313
  function parseAndCheckHttpResponse(operations) {
@@ -1460,12 +1475,12 @@ function rewriteURIForGET(chosenURI, body) {
1460
1475
  return { newURI: newURI };
1461
1476
  }
1462
1477
 
1478
+ var backupFetch = maybe(function () { return fetch; });
1463
1479
  var createHttpLink = function (linkOptions) {
1464
1480
  if (linkOptions === void 0) { linkOptions = {}; }
1465
- var _a = linkOptions.uri, uri = _a === void 0 ? '/graphql' : _a, fetcher = linkOptions.fetch, includeExtensions = linkOptions.includeExtensions, useGETForQueries = linkOptions.useGETForQueries, _b = linkOptions.includeUnusedVariables, includeUnusedVariables = _b === void 0 ? false : _b, requestOptions = tslib.__rest(linkOptions, ["uri", "fetch", "includeExtensions", "useGETForQueries", "includeUnusedVariables"]);
1466
- checkFetcher(fetcher);
1467
- if (!fetcher) {
1468
- fetcher = fetch;
1481
+ var _a = linkOptions.uri, uri = _a === void 0 ? '/graphql' : _a, preferredFetch = linkOptions.fetch, includeExtensions = linkOptions.includeExtensions, useGETForQueries = linkOptions.useGETForQueries, _b = linkOptions.includeUnusedVariables, includeUnusedVariables = _b === void 0 ? false : _b, requestOptions = tslib.__rest(linkOptions, ["uri", "fetch", "includeExtensions", "useGETForQueries", "includeUnusedVariables"]);
1482
+ if (__DEV__) {
1483
+ checkFetcher(preferredFetch || backupFetch);
1469
1484
  }
1470
1485
  var linkConfig = {
1471
1486
  http: { includeExtensions: includeExtensions },
@@ -1540,7 +1555,8 @@ var createHttpLink = function (linkOptions) {
1540
1555
  }
1541
1556
  }
1542
1557
  return new zenObservableTs.Observable(function (observer) {
1543
- fetcher(chosenURI, options)
1558
+ var currentFetch = preferredFetch || maybe(function () { return fetch; }) || backupFetch;
1559
+ currentFetch(chosenURI, options)
1544
1560
  .then(function (response) {
1545
1561
  operation.setContext({ response: response });
1546
1562
  return response;
@@ -2542,7 +2558,7 @@ var StoreWriter = (function () {
2542
2558
  context.incomingById.forEach(function (_a, dataId) {
2543
2559
  var fields = _a.fields, mergeTree = _a.mergeTree, selections = _a.selections;
2544
2560
  var entityRef = makeReference(dataId);
2545
- if (mergeTree.map.size) {
2561
+ if (mergeTree && mergeTree.map.size) {
2546
2562
  var applied = _this.applyMerges(mergeTree, entityRef, fields, context);
2547
2563
  if (isReference(applied)) {
2548
2564
  return;
@@ -2560,7 +2576,7 @@ var StoreWriter = (function () {
2560
2576
  }
2561
2577
  });
2562
2578
  var hasMergeFunction_1 = function (storeFieldName) {
2563
- var childTree = mergeTree.map.get(storeFieldName);
2579
+ var childTree = mergeTree && mergeTree.map.get(storeFieldName);
2564
2580
  return Boolean(childTree && childTree.info && childTree.info.merge);
2565
2581
  };
2566
2582
  Object.keys(fields).forEach(function (storeFieldName) {
@@ -2669,7 +2685,7 @@ var StoreWriter = (function () {
2669
2685
  else {
2670
2686
  context.incomingById.set(dataId, {
2671
2687
  fields: incomingFields,
2672
- mergeTree: mergeTree,
2688
+ mergeTree: mergeTreeIsEmpty(mergeTree) ? void 0 : mergeTree,
2673
2689
  selections: selections,
2674
2690
  });
2675
2691
  }
@@ -3359,24 +3375,27 @@ function makeAliasMap(selectionSet, fragmentMap) {
3359
3375
  }
3360
3376
  function computeKeyObject(response, specifier, strict, aliasMap) {
3361
3377
  var keyObj = Object.create(null);
3362
- var prevKey;
3378
+ var lastResponseKey;
3379
+ var lastActualKey;
3363
3380
  specifier.forEach(function (s) {
3364
3381
  if (Array.isArray(s)) {
3365
- if (typeof prevKey === "string") {
3382
+ if (typeof lastActualKey === "string" &&
3383
+ typeof lastResponseKey === "string") {
3366
3384
  var subsets = aliasMap && aliasMap.subsets;
3367
- var subset = subsets && subsets[prevKey];
3368
- keyObj[prevKey] = computeKeyObject(response[prevKey], s, strict, subset);
3385
+ var subset = subsets && subsets[lastActualKey];
3386
+ keyObj[lastActualKey] =
3387
+ computeKeyObject(response[lastResponseKey], s, strict, subset);
3369
3388
  }
3370
3389
  }
3371
3390
  else {
3372
3391
  var aliases = aliasMap && aliasMap.aliases;
3373
3392
  var responseName = aliases && aliases[s] || s;
3374
3393
  if (hasOwn.call(response, responseName)) {
3375
- keyObj[prevKey = s] = response[responseName];
3394
+ keyObj[lastActualKey = s] = response[lastResponseKey = responseName];
3376
3395
  }
3377
3396
  else {
3378
3397
  __DEV__ ? tsInvariant.invariant(!strict, "Missing field '" + responseName + "' while computing key fields") : tsInvariant.invariant(!strict, 5);
3379
- prevKey = void 0;
3398
+ lastResponseKey = lastActualKey = void 0;
3380
3399
  }
3381
3400
  }
3382
3401
  });
@@ -3735,11 +3754,12 @@ var ObservableQuery = (function (_super) {
3735
3754
  catch (_a) { }
3736
3755
  var first = !_this.observers.size;
3737
3756
  _this.observers.add(observer);
3738
- if (_this.lastError) {
3739
- observer.error && observer.error(_this.lastError);
3757
+ var last = _this.last;
3758
+ if (last && last.error) {
3759
+ observer.error && observer.error(last.error);
3740
3760
  }
3741
- else if (_this.lastResult) {
3742
- observer.next && observer.next(_this.lastResult);
3761
+ else if (last && last.result) {
3762
+ observer.next && observer.next(last.result);
3743
3763
  }
3744
3764
  if (first) {
3745
3765
  _this.reobserve().catch(function () { });
@@ -3752,21 +3772,9 @@ var ObservableQuery = (function (_super) {
3752
3772
  }) || this;
3753
3773
  _this.observers = new Set();
3754
3774
  _this.subscriptions = new Set();
3755
- _this.observer = {
3756
- next: function (result) {
3757
- if (_this.lastError || _this.isDifferentFromLastResult(result)) {
3758
- _this.updateLastResult(result);
3759
- iterateObserversSafely(_this.observers, 'next', result);
3760
- }
3761
- },
3762
- error: function (error) {
3763
- _this.updateLastResult(tslib.__assign(tslib.__assign({}, _this.lastResult), { error: error, errors: error.graphQLErrors, networkStatus: exports.NetworkStatus.error, loading: false }));
3764
- iterateObserversSafely(_this.observers, 'error', _this.lastError = error);
3765
- },
3766
- };
3767
3775
  _this.isTornDown = false;
3768
3776
  _this.options = options;
3769
- _this.queryId = queryManager.generateQueryId();
3777
+ _this.queryId = queryInfo.queryId || queryManager.generateQueryId();
3770
3778
  var opDef = getOperationDefinition(options.query);
3771
3779
  _this.queryName = opDef && opDef.name && opDef.name.value;
3772
3780
  _this.initialFetchPolicy = options.fetchPolicy || "cache-first";
@@ -3802,15 +3810,20 @@ var ObservableQuery = (function (_super) {
3802
3810
  };
3803
3811
  ObservableQuery.prototype.getCurrentResult = function (saveAsLastResult) {
3804
3812
  if (saveAsLastResult === void 0) { saveAsLastResult = true; }
3805
- var _a = this, lastResult = _a.lastResult, _b = _a.options.fetchPolicy, fetchPolicy = _b === void 0 ? "cache-first" : _b;
3813
+ var lastResult = this.getLastResult(true);
3806
3814
  var networkStatus = this.queryInfo.networkStatus ||
3807
3815
  (lastResult && lastResult.networkStatus) ||
3808
3816
  exports.NetworkStatus.ready;
3809
3817
  var result = tslib.__assign(tslib.__assign({}, lastResult), { loading: isNetworkRequestInFlight(networkStatus), networkStatus: networkStatus });
3810
3818
  if (!this.queryManager.transform(this.options.query).hasForcedResolvers) {
3811
3819
  var diff = this.queryInfo.getDiff();
3812
- result.data = (diff.complete ||
3813
- this.options.returnPartialData) ? diff.result : void 0;
3820
+ if (diff.complete || this.options.returnPartialData) {
3821
+ result.data = diff.result;
3822
+ }
3823
+ if (equality.equal(result.data, {})) {
3824
+ result.data = void 0;
3825
+ }
3826
+ var _a = this.options.fetchPolicy, fetchPolicy = _a === void 0 ? "cache-first" : _a;
3814
3827
  if (diff.complete) {
3815
3828
  if (result.networkStatus === exports.NetworkStatus.loading &&
3816
3829
  (fetchPolicy === 'cache-first' ||
@@ -3823,12 +3836,13 @@ var ObservableQuery = (function (_super) {
3823
3836
  else if (fetchPolicy !== "no-cache") {
3824
3837
  result.partial = true;
3825
3838
  }
3826
- if (!diff.complete &&
3839
+ if (__DEV__ &&
3840
+ !diff.complete &&
3827
3841
  !this.options.partialRefetch &&
3828
3842
  !result.loading &&
3829
3843
  !result.data &&
3830
3844
  !result.error) {
3831
- result.error = new ApolloError({ clientErrors: diff.missing });
3845
+ logMissingFieldErrors(diff.missing);
3832
3846
  }
3833
3847
  }
3834
3848
  if (saveAsLastResult) {
@@ -3837,18 +3851,24 @@ var ObservableQuery = (function (_super) {
3837
3851
  return result;
3838
3852
  };
3839
3853
  ObservableQuery.prototype.isDifferentFromLastResult = function (newResult) {
3840
- return !equality.equal(this.lastResultSnapshot, newResult);
3854
+ return !this.last || !equality.equal(this.last.result, newResult);
3855
+ };
3856
+ ObservableQuery.prototype.getLast = function (key, variablesMustMatch) {
3857
+ var last = this.last;
3858
+ if (last &&
3859
+ last[key] &&
3860
+ (!variablesMustMatch || equality.equal(last.variables, this.variables))) {
3861
+ return last[key];
3862
+ }
3841
3863
  };
3842
- ObservableQuery.prototype.getLastResult = function () {
3843
- return this.lastResult;
3864
+ ObservableQuery.prototype.getLastResult = function (variablesMustMatch) {
3865
+ return this.getLast("result", variablesMustMatch);
3844
3866
  };
3845
- ObservableQuery.prototype.getLastError = function () {
3846
- return this.lastError;
3867
+ ObservableQuery.prototype.getLastError = function (variablesMustMatch) {
3868
+ return this.getLast("error", variablesMustMatch);
3847
3869
  };
3848
3870
  ObservableQuery.prototype.resetLastResults = function () {
3849
- delete this.lastResult;
3850
- delete this.lastResultSnapshot;
3851
- delete this.lastError;
3871
+ delete this.last;
3852
3872
  this.isTornDown = false;
3853
3873
  };
3854
3874
  ObservableQuery.prototype.resetQueryStoreErrors = function () {
@@ -3961,12 +3981,10 @@ var ObservableQuery = (function (_super) {
3961
3981
  }, exports.NetworkStatus.setVariables);
3962
3982
  };
3963
3983
  ObservableQuery.prototype.updateQuery = function (mapFn) {
3964
- var _a;
3965
3984
  var queryManager = this.queryManager;
3966
3985
  var result = queryManager.cache.diff({
3967
3986
  query: this.options.query,
3968
3987
  variables: this.variables,
3969
- previousResult: (_a = this.lastResult) === null || _a === void 0 ? void 0 : _a.data,
3970
3988
  returnPartialData: true,
3971
3989
  optimistic: false,
3972
3990
  }).result;
@@ -4035,18 +4053,18 @@ var ObservableQuery = (function (_super) {
4035
4053
  };
4036
4054
  poll();
4037
4055
  };
4038
- ObservableQuery.prototype.updateLastResult = function (newResult) {
4039
- var previousResult = this.lastResult;
4040
- this.lastResult = newResult;
4041
- this.lastResultSnapshot = this.queryManager.assumeImmutableResults
4042
- ? newResult
4043
- : cloneDeep(newResult);
4056
+ ObservableQuery.prototype.updateLastResult = function (newResult, variables) {
4057
+ if (variables === void 0) { variables = this.variables; }
4058
+ this.last = tslib.__assign(tslib.__assign({}, this.last), { result: this.queryManager.assumeImmutableResults
4059
+ ? newResult
4060
+ : cloneDeep(newResult), variables: variables });
4044
4061
  if (!isNonEmptyArray(newResult.errors)) {
4045
- delete this.lastError;
4062
+ delete this.last.error;
4046
4063
  }
4047
- return previousResult;
4064
+ return this.last;
4048
4065
  };
4049
4066
  ObservableQuery.prototype.reobserve = function (newOptions, newNetworkStatus) {
4067
+ var _this = this;
4050
4068
  this.isTornDown = false;
4051
4069
  var useDisposableConcast = newNetworkStatus === exports.NetworkStatus.refetch ||
4052
4070
  newNetworkStatus === exports.NetworkStatus.fetchMore ||
@@ -4067,18 +4085,39 @@ var ObservableQuery = (function (_super) {
4067
4085
  }
4068
4086
  }
4069
4087
  }
4088
+ var variables = options.variables && tslib.__assign({}, options.variables);
4070
4089
  var concast = this.fetch(options, newNetworkStatus);
4090
+ var observer = {
4091
+ next: function (result) {
4092
+ _this.reportResult(result, variables);
4093
+ },
4094
+ error: function (error) {
4095
+ _this.reportError(error, variables);
4096
+ },
4097
+ };
4071
4098
  if (!useDisposableConcast) {
4072
- if (this.concast) {
4099
+ if (this.concast && this.observer) {
4073
4100
  this.concast.removeObserver(this.observer, true);
4074
4101
  }
4075
4102
  this.concast = concast;
4103
+ this.observer = observer;
4076
4104
  }
4077
- concast.addObserver(this.observer);
4105
+ concast.addObserver(observer);
4078
4106
  return concast.promise;
4079
4107
  };
4080
4108
  ObservableQuery.prototype.observe = function () {
4081
- this.observer.next(this.getCurrentResult(false));
4109
+ this.reportResult(this.getCurrentResult(false), this.variables);
4110
+ };
4111
+ ObservableQuery.prototype.reportResult = function (result, variables) {
4112
+ if (this.getLastError() || this.isDifferentFromLastResult(result)) {
4113
+ this.updateLastResult(result, variables);
4114
+ iterateObserversSafely(this.observers, 'next', result);
4115
+ }
4116
+ };
4117
+ ObservableQuery.prototype.reportError = function (error, variables) {
4118
+ var errorResult = tslib.__assign(tslib.__assign({}, this.getLastResult()), { error: error, errors: error.graphQLErrors, networkStatus: exports.NetworkStatus.error, loading: false });
4119
+ this.updateLastResult(errorResult, variables);
4120
+ iterateObserversSafely(this.observers, 'error', this.last.error = error);
4082
4121
  };
4083
4122
  ObservableQuery.prototype.hasObservers = function () {
4084
4123
  return this.observers.size > 0;
@@ -4086,9 +4125,10 @@ var ObservableQuery = (function (_super) {
4086
4125
  ObservableQuery.prototype.tearDownQuery = function () {
4087
4126
  if (this.isTornDown)
4088
4127
  return;
4089
- if (this.concast) {
4128
+ if (this.concast && this.observer) {
4090
4129
  this.concast.removeObserver(this.observer);
4091
4130
  delete this.concast;
4131
+ delete this.observer;
4092
4132
  }
4093
4133
  this.stopPolling();
4094
4134
  this.subscriptions.forEach(function (sub) { return sub.unsubscribe(); });
@@ -4103,6 +4143,11 @@ fixObservableSubclass(ObservableQuery);
4103
4143
  function defaultSubscriptionObserverErrorCallback(error) {
4104
4144
  __DEV__ && tsInvariant.invariant.error('Unhandled error', error.message, error.stack);
4105
4145
  }
4146
+ function logMissingFieldErrors(missing) {
4147
+ if (__DEV__ && isNonEmptyArray(missing)) {
4148
+ __DEV__ && tsInvariant.invariant.debug("Missing cache result fields: " + missing.map(function (m) { return m.path.join('.'); }).join(', '), missing);
4149
+ }
4150
+ }
4106
4151
  function applyNextFetchPolicy(options) {
4107
4152
  var _a = options.fetchPolicy, fetchPolicy = _a === void 0 ? "cache-first" : _a, nextFetchPolicy = options.nextFetchPolicy;
4108
4153
  if (nextFetchPolicy) {
@@ -4390,8 +4435,9 @@ function cancelNotifyTimeout(info) {
4390
4435
  }
4391
4436
  }
4392
4437
  var QueryInfo = (function () {
4393
- function QueryInfo(cache) {
4394
- this.cache = cache;
4438
+ function QueryInfo(queryManager, queryId) {
4439
+ if (queryId === void 0) { queryId = queryManager.generateQueryId(); }
4440
+ this.queryId = queryId;
4395
4441
  this.listeners = new Set();
4396
4442
  this.document = null;
4397
4443
  this.lastRequestId = 1;
@@ -4399,6 +4445,7 @@ var QueryInfo = (function () {
4399
4445
  this.stopped = false;
4400
4446
  this.dirty = false;
4401
4447
  this.observableQuery = null;
4448
+ var cache = this.cache = queryManager.cache;
4402
4449
  if (!destructiveMethodCounts.has(cache)) {
4403
4450
  destructiveMethodCounts.set(cache, 0);
4404
4451
  wrapDestructiveCacheMethod(cache, "evict");
@@ -4672,22 +4719,24 @@ var QueryManager = (function () {
4672
4719
  this.fetchCancelFns.clear();
4673
4720
  };
4674
4721
  QueryManager.prototype.mutate = function (_a) {
4675
- 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, fetchPolicy = _a.fetchPolicy, keepRootFields = _a.keepRootFields, context = _a.context;
4722
+ 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;
4676
4723
  return tslib.__awaiter(this, void 0, void 0, function () {
4677
4724
  var mutationId, mutationStoreValue, self;
4678
- return tslib.__generator(this, function (_e) {
4679
- switch (_e.label) {
4725
+ return tslib.__generator(this, function (_f) {
4726
+ switch (_f.label) {
4680
4727
  case 0:
4681
4728
  __DEV__ ? tsInvariant.invariant(mutation, 'mutation option is required. You must specify your GraphQL document in the mutation option.') : tsInvariant.invariant(mutation, 15);
4682
- __DEV__ ? tsInvariant.invariant(!fetchPolicy || fetchPolicy === 'no-cache', "Mutations only support a 'no-cache' fetchPolicy. If you don't want to disable the cache, remove your fetchPolicy setting to proceed with the default mutation behavior.") : tsInvariant.invariant(!fetchPolicy || fetchPolicy === 'no-cache', 16);
4729
+ __DEV__ ? tsInvariant.invariant(fetchPolicy === 'network-only' ||
4730
+ fetchPolicy === 'no-cache', "Mutations support only 'network-only' or 'no-cache' fetchPolicy strings. The default `network-only` behavior automatically writes mutation results to the cache. Passing `no-cache` skips the cache write.") : tsInvariant.invariant(fetchPolicy === 'network-only' ||
4731
+ fetchPolicy === 'no-cache', 16);
4683
4732
  mutationId = this.generateMutationId();
4684
4733
  mutation = this.transform(mutation).document;
4685
4734
  variables = this.getVariables(mutation, variables);
4686
4735
  if (!this.transform(mutation).hasClientExports) return [3, 2];
4687
4736
  return [4, this.localState.addExportedVariables(mutation, variables, context)];
4688
4737
  case 1:
4689
- variables = (_e.sent());
4690
- _e.label = 2;
4738
+ variables = (_f.sent());
4739
+ _f.label = 2;
4691
4740
  case 2:
4692
4741
  mutationStoreValue = this.mutationStore &&
4693
4742
  (this.mutationStore[mutationId] = {
@@ -4946,7 +4995,7 @@ var QueryManager = (function () {
4946
4995
  if (typeof options.notifyOnNetworkStatusChange === 'undefined') {
4947
4996
  options.notifyOnNetworkStatusChange = false;
4948
4997
  }
4949
- var queryInfo = new QueryInfo(this.cache);
4998
+ var queryInfo = new QueryInfo(this);
4950
4999
  var observable = new ObservableQuery({
4951
5000
  queryManager: this,
4952
5001
  queryInfo: queryInfo,
@@ -5062,6 +5111,7 @@ var QueryManager = (function () {
5062
5111
  queryInfo: queryInfo,
5063
5112
  options: tslib.__assign(tslib.__assign({}, options), { fetchPolicy: "network-only" }),
5064
5113
  });
5114
+ tsInvariant.invariant(oq.queryId === queryId);
5065
5115
  queryInfo.setObservableQuery(oq);
5066
5116
  queries.set(queryId, oq);
5067
5117
  });
@@ -5356,10 +5406,9 @@ var QueryManager = (function () {
5356
5406
  if (networkStatus === void 0) { networkStatus = queryInfo.networkStatus || exports.NetworkStatus.loading; }
5357
5407
  var data = diff.result;
5358
5408
  if (__DEV__ &&
5359
- isNonEmptyArray(diff.missing) &&
5360
- !equality.equal(data, {}) &&
5361
- !returnPartialData) {
5362
- __DEV__ && tsInvariant.invariant.debug("Missing cache result fields: " + diff.missing.map(function (m) { return m.path.join('.'); }).join(', '), diff.missing);
5409
+ !returnPartialData &&
5410
+ !equality.equal(data, {})) {
5411
+ logMissingFieldErrors(diff.missing);
5363
5412
  }
5364
5413
  var fromData = function (data) { return zenObservableTs.Observable.of(tslib.__assign({ data: data, loading: isNetworkRequestInFlight(networkStatus), networkStatus: networkStatus }, (diff.complete ? null : { partial: true }))); };
5365
5414
  if (data && _this.transform(query).hasForcedResolvers) {
@@ -5446,7 +5495,7 @@ var QueryManager = (function () {
5446
5495
  };
5447
5496
  QueryManager.prototype.getQuery = function (queryId) {
5448
5497
  if (queryId && !this.queries.has(queryId)) {
5449
- this.queries.set(queryId, new QueryInfo(this.cache));
5498
+ this.queries.set(queryId, new QueryInfo(this, queryId));
5450
5499
  }
5451
5500
  return this.queries.get(queryId);
5452
5501
  };
@@ -5689,7 +5738,841 @@ var ApolloClient = (function () {
5689
5738
  return ApolloClient;
5690
5739
  }());
5691
5740
 
5692
- tsInvariant.setVerbosity(DEV ? "log" : "silent");
5741
+ var cache$1 = new (canUseWeakMap ? WeakMap : Map)();
5742
+ function getApolloContext() {
5743
+ var context = cache$1.get(React__namespace.createContext);
5744
+ if (!context) {
5745
+ context = React__namespace.createContext({});
5746
+ context.displayName = 'ApolloContext';
5747
+ cache$1.set(React__namespace.createContext, context);
5748
+ }
5749
+ return context;
5750
+ }
5751
+
5752
+ var ApolloConsumer = function (props) {
5753
+ var ApolloContext = getApolloContext();
5754
+ return React__namespace.createElement(ApolloContext.Consumer, null, function (context) {
5755
+ __DEV__ ? tsInvariant.invariant(context && context.client, 'Could not find "client" in the context of ApolloConsumer. ' +
5756
+ 'Wrap the root component in an <ApolloProvider>.') : tsInvariant.invariant(context && context.client, 30);
5757
+ return props.children(context.client);
5758
+ });
5759
+ };
5760
+
5761
+ var ApolloProvider = function (_a) {
5762
+ var client = _a.client, children = _a.children;
5763
+ var ApolloContext = getApolloContext();
5764
+ return React__namespace.createElement(ApolloContext.Consumer, null, function (context) {
5765
+ if (context === void 0) { context = {}; }
5766
+ if (client && context.client !== client) {
5767
+ context = Object.assign({}, context, { client: client });
5768
+ }
5769
+ __DEV__ ? tsInvariant.invariant(context.client, 'ApolloProvider was not passed a client instance. Make ' +
5770
+ 'sure you pass in your client via the "client" prop.') : tsInvariant.invariant(context.client, 31);
5771
+ return (React__namespace.createElement(ApolloContext.Provider, { value: context }, children));
5772
+ });
5773
+ };
5774
+
5775
+ function useApolloClient() {
5776
+ var client = React__namespace.useContext(getApolloContext()).client;
5777
+ __DEV__ ? tsInvariant.invariant(client, 'No Apollo Client instance can be found. Please ensure that you ' +
5778
+ 'have called `ApolloProvider` higher up in your tree.') : tsInvariant.invariant(client, 36);
5779
+ return client;
5780
+ }
5781
+
5782
+ exports.DocumentType = void 0;
5783
+ (function (DocumentType) {
5784
+ DocumentType[DocumentType["Query"] = 0] = "Query";
5785
+ DocumentType[DocumentType["Mutation"] = 1] = "Mutation";
5786
+ DocumentType[DocumentType["Subscription"] = 2] = "Subscription";
5787
+ })(exports.DocumentType || (exports.DocumentType = {}));
5788
+ var cache = new Map();
5789
+ function operationName(type) {
5790
+ var name;
5791
+ switch (type) {
5792
+ case exports.DocumentType.Query:
5793
+ name = 'Query';
5794
+ break;
5795
+ case exports.DocumentType.Mutation:
5796
+ name = 'Mutation';
5797
+ break;
5798
+ case exports.DocumentType.Subscription:
5799
+ name = 'Subscription';
5800
+ break;
5801
+ }
5802
+ return name;
5803
+ }
5804
+ function parser(document) {
5805
+ var cached = cache.get(document);
5806
+ if (cached)
5807
+ return cached;
5808
+ var variables, type, name;
5809
+ __DEV__ ? tsInvariant.invariant(!!document && !!document.kind, "Argument of " + document + " passed to parser was not a valid GraphQL " +
5810
+ "DocumentNode. You may need to use 'graphql-tag' or another method " +
5811
+ "to convert your operation into a document") : tsInvariant.invariant(!!document && !!document.kind, 38);
5812
+ var fragments = document.definitions.filter(function (x) { return x.kind === 'FragmentDefinition'; });
5813
+ var queries = document.definitions.filter(function (x) {
5814
+ return x.kind === 'OperationDefinition' && x.operation === 'query';
5815
+ });
5816
+ var mutations = document.definitions.filter(function (x) {
5817
+ return x.kind === 'OperationDefinition' && x.operation === 'mutation';
5818
+ });
5819
+ var subscriptions = document.definitions.filter(function (x) {
5820
+ return x.kind === 'OperationDefinition' && x.operation === 'subscription';
5821
+ });
5822
+ __DEV__ ? tsInvariant.invariant(!fragments.length ||
5823
+ (queries.length || mutations.length || subscriptions.length), "Passing only a fragment to 'graphql' is not yet supported. " +
5824
+ "You must include a query, subscription or mutation as well") : tsInvariant.invariant(!fragments.length ||
5825
+ (queries.length || mutations.length || subscriptions.length), 39);
5826
+ __DEV__ ? tsInvariant.invariant(queries.length + mutations.length + subscriptions.length <= 1, "react-apollo only supports a query, subscription, or a mutation per HOC. " +
5827
+ (document + " had " + queries.length + " queries, " + subscriptions.length + " ") +
5828
+ ("subscriptions and " + mutations.length + " mutations. ") +
5829
+ "You can use 'compose' to join multiple operation types to a component") : tsInvariant.invariant(queries.length + mutations.length + subscriptions.length <= 1, 40);
5830
+ type = queries.length ? exports.DocumentType.Query : exports.DocumentType.Mutation;
5831
+ if (!queries.length && !mutations.length)
5832
+ type = exports.DocumentType.Subscription;
5833
+ var definitions = queries.length
5834
+ ? queries
5835
+ : mutations.length
5836
+ ? mutations
5837
+ : subscriptions;
5838
+ __DEV__ ? tsInvariant.invariant(definitions.length === 1, "react-apollo only supports one definition per HOC. " + document + " had " +
5839
+ (definitions.length + " definitions. ") +
5840
+ "You can use 'compose' to join multiple operation types to a component") : tsInvariant.invariant(definitions.length === 1, 41);
5841
+ var definition = definitions[0];
5842
+ variables = definition.variableDefinitions || [];
5843
+ if (definition.name && definition.name.kind === 'Name') {
5844
+ name = definition.name.value;
5845
+ }
5846
+ else {
5847
+ name = 'data';
5848
+ }
5849
+ var payload = { name: name, type: type, variables: variables };
5850
+ cache.set(document, payload);
5851
+ return payload;
5852
+ }
5853
+
5854
+ var OperationData = (function () {
5855
+ function OperationData(options, context) {
5856
+ this.isMounted = false;
5857
+ this.previousOptions = {};
5858
+ this.context = {};
5859
+ this.options = {};
5860
+ this.options = options || {};
5861
+ this.context = context || {};
5862
+ }
5863
+ OperationData.prototype.getOptions = function () {
5864
+ return this.options;
5865
+ };
5866
+ OperationData.prototype.setOptions = function (newOptions, storePrevious) {
5867
+ if (storePrevious === void 0) { storePrevious = false; }
5868
+ if (storePrevious && !equality.equal(this.options, newOptions)) {
5869
+ this.previousOptions = this.options;
5870
+ }
5871
+ this.options = newOptions;
5872
+ };
5873
+ OperationData.prototype.unmount = function () {
5874
+ this.isMounted = false;
5875
+ };
5876
+ OperationData.prototype.refreshClient = function () {
5877
+ var client = (this.options && this.options.client) ||
5878
+ (this.context && this.context.client);
5879
+ __DEV__ ? tsInvariant.invariant(!!client, 'Could not find "client" in the context or passed in as an option. ' +
5880
+ 'Wrap the root component in an <ApolloProvider>, or pass an ' +
5881
+ 'ApolloClient instance in via options.') : tsInvariant.invariant(!!client, 32);
5882
+ var isNew = false;
5883
+ if (client !== this.client) {
5884
+ isNew = true;
5885
+ this.client = client;
5886
+ this.cleanup();
5887
+ }
5888
+ return {
5889
+ client: this.client,
5890
+ isNew: isNew
5891
+ };
5892
+ };
5893
+ OperationData.prototype.verifyDocumentType = function (document, type) {
5894
+ var operation = parser(document);
5895
+ var requiredOperationName = operationName(type);
5896
+ var usedOperationName = operationName(operation.type);
5897
+ __DEV__ ? tsInvariant.invariant(operation.type === type, "Running a " + requiredOperationName + " requires a graphql " +
5898
+ (requiredOperationName + ", but a " + usedOperationName + " was used instead.")) : tsInvariant.invariant(operation.type === type, 33);
5899
+ };
5900
+ return OperationData;
5901
+ }());
5902
+
5903
+ var SubscriptionData = (function (_super) {
5904
+ tslib.__extends(SubscriptionData, _super);
5905
+ function SubscriptionData(_a) {
5906
+ var options = _a.options, context = _a.context, setResult = _a.setResult;
5907
+ var _this = _super.call(this, options, context) || this;
5908
+ _this.currentObservable = {};
5909
+ _this.setResult = setResult;
5910
+ _this.initialize(options);
5911
+ return _this;
5912
+ }
5913
+ SubscriptionData.prototype.execute = function (result) {
5914
+ if (this.getOptions().skip === true) {
5915
+ this.cleanup();
5916
+ return {
5917
+ loading: false,
5918
+ error: undefined,
5919
+ data: undefined,
5920
+ variables: this.getOptions().variables
5921
+ };
5922
+ }
5923
+ var currentResult = result;
5924
+ if (this.refreshClient().isNew) {
5925
+ currentResult = this.getLoadingResult();
5926
+ }
5927
+ var shouldResubscribe = this.getOptions().shouldResubscribe;
5928
+ if (typeof shouldResubscribe === 'function') {
5929
+ shouldResubscribe = !!shouldResubscribe(this.getOptions());
5930
+ }
5931
+ if (shouldResubscribe !== false &&
5932
+ this.previousOptions &&
5933
+ Object.keys(this.previousOptions).length > 0 &&
5934
+ (this.previousOptions.subscription !== this.getOptions().subscription ||
5935
+ !equality.equal(this.previousOptions.variables, this.getOptions().variables) ||
5936
+ this.previousOptions.skip !== this.getOptions().skip)) {
5937
+ this.cleanup();
5938
+ currentResult = this.getLoadingResult();
5939
+ }
5940
+ this.initialize(this.getOptions());
5941
+ this.startSubscription();
5942
+ this.previousOptions = this.getOptions();
5943
+ return tslib.__assign(tslib.__assign({}, currentResult), { variables: this.getOptions().variables });
5944
+ };
5945
+ SubscriptionData.prototype.afterExecute = function () {
5946
+ this.isMounted = true;
5947
+ };
5948
+ SubscriptionData.prototype.cleanup = function () {
5949
+ this.endSubscription();
5950
+ delete this.currentObservable.query;
5951
+ };
5952
+ SubscriptionData.prototype.initialize = function (options) {
5953
+ if (this.currentObservable.query || this.getOptions().skip === true)
5954
+ return;
5955
+ this.currentObservable.query = this.refreshClient().client.subscribe({
5956
+ query: options.subscription,
5957
+ variables: options.variables,
5958
+ fetchPolicy: options.fetchPolicy,
5959
+ context: options.context,
5960
+ });
5961
+ };
5962
+ SubscriptionData.prototype.startSubscription = function () {
5963
+ if (this.currentObservable.subscription)
5964
+ return;
5965
+ this.currentObservable.subscription = this.currentObservable.query.subscribe({
5966
+ next: this.updateCurrentData.bind(this),
5967
+ error: this.updateError.bind(this),
5968
+ complete: this.completeSubscription.bind(this)
5969
+ });
5970
+ };
5971
+ SubscriptionData.prototype.getLoadingResult = function () {
5972
+ return {
5973
+ loading: true,
5974
+ error: undefined,
5975
+ data: undefined
5976
+ };
5977
+ };
5978
+ SubscriptionData.prototype.updateResult = function (result) {
5979
+ if (this.isMounted) {
5980
+ this.setResult(result);
5981
+ }
5982
+ };
5983
+ SubscriptionData.prototype.updateCurrentData = function (result) {
5984
+ var onSubscriptionData = this.getOptions().onSubscriptionData;
5985
+ this.updateResult({
5986
+ data: result.data,
5987
+ loading: false,
5988
+ error: undefined
5989
+ });
5990
+ if (onSubscriptionData) {
5991
+ onSubscriptionData({
5992
+ client: this.refreshClient().client,
5993
+ subscriptionData: result
5994
+ });
5995
+ }
5996
+ };
5997
+ SubscriptionData.prototype.updateError = function (error) {
5998
+ this.updateResult({
5999
+ error: error,
6000
+ loading: false
6001
+ });
6002
+ };
6003
+ SubscriptionData.prototype.completeSubscription = function () {
6004
+ var _this = this;
6005
+ Promise.resolve().then(function () {
6006
+ var onSubscriptionComplete = _this.getOptions().onSubscriptionComplete;
6007
+ if (onSubscriptionComplete)
6008
+ onSubscriptionComplete();
6009
+ _this.endSubscription();
6010
+ });
6011
+ };
6012
+ SubscriptionData.prototype.endSubscription = function () {
6013
+ if (this.currentObservable.subscription) {
6014
+ this.currentObservable.subscription.unsubscribe();
6015
+ delete this.currentObservable.subscription;
6016
+ }
6017
+ };
6018
+ return SubscriptionData;
6019
+ }(OperationData));
6020
+
6021
+ var MutationData = (function (_super) {
6022
+ tslib.__extends(MutationData, _super);
6023
+ function MutationData(_a) {
6024
+ var options = _a.options, context = _a.context, result = _a.result, setResult = _a.setResult;
6025
+ var _this = _super.call(this, options, context) || this;
6026
+ _this.runMutation = function (mutationFunctionOptions) {
6027
+ if (mutationFunctionOptions === void 0) { mutationFunctionOptions = {}; }
6028
+ _this.onMutationStart();
6029
+ var mutationId = _this.generateNewMutationId();
6030
+ return _this.mutate(mutationFunctionOptions)
6031
+ .then(function (response) {
6032
+ _this.onMutationCompleted(response, mutationId);
6033
+ return response;
6034
+ })
6035
+ .catch(function (error) {
6036
+ var onError = _this.getOptions().onError;
6037
+ _this.onMutationError(error, mutationId);
6038
+ if (onError) {
6039
+ onError(error);
6040
+ return {
6041
+ data: undefined,
6042
+ errors: error,
6043
+ };
6044
+ }
6045
+ else {
6046
+ throw error;
6047
+ }
6048
+ });
6049
+ };
6050
+ _this.verifyDocumentType(options.mutation, exports.DocumentType.Mutation);
6051
+ _this.result = result;
6052
+ _this.setResult = setResult;
6053
+ _this.mostRecentMutationId = 0;
6054
+ return _this;
6055
+ }
6056
+ MutationData.prototype.execute = function (result) {
6057
+ this.isMounted = true;
6058
+ this.verifyDocumentType(this.getOptions().mutation, exports.DocumentType.Mutation);
6059
+ return [
6060
+ this.runMutation,
6061
+ tslib.__assign(tslib.__assign({}, result), { client: this.refreshClient().client })
6062
+ ];
6063
+ };
6064
+ MutationData.prototype.afterExecute = function () {
6065
+ this.isMounted = true;
6066
+ return this.unmount.bind(this);
6067
+ };
6068
+ MutationData.prototype.cleanup = function () {
6069
+ };
6070
+ MutationData.prototype.mutate = function (options) {
6071
+ return this.refreshClient().client.mutate(mergeOptions(this.getOptions(), options));
6072
+ };
6073
+ MutationData.prototype.onMutationStart = function () {
6074
+ if (!this.result.loading && !this.getOptions().ignoreResults) {
6075
+ this.updateResult({
6076
+ loading: true,
6077
+ error: undefined,
6078
+ data: undefined,
6079
+ called: true
6080
+ });
6081
+ }
6082
+ };
6083
+ MutationData.prototype.onMutationCompleted = function (response, mutationId) {
6084
+ var _a = this.getOptions(), onCompleted = _a.onCompleted, ignoreResults = _a.ignoreResults;
6085
+ var data = response.data, errors = response.errors;
6086
+ var error = errors && errors.length > 0
6087
+ ? new ApolloError({ graphQLErrors: errors })
6088
+ : undefined;
6089
+ var callOncomplete = function () {
6090
+ return onCompleted ? onCompleted(data) : null;
6091
+ };
6092
+ if (this.isMostRecentMutation(mutationId) && !ignoreResults) {
6093
+ this.updateResult({
6094
+ called: true,
6095
+ loading: false,
6096
+ data: data,
6097
+ error: error
6098
+ });
6099
+ }
6100
+ callOncomplete();
6101
+ };
6102
+ MutationData.prototype.onMutationError = function (error, mutationId) {
6103
+ if (this.isMostRecentMutation(mutationId)) {
6104
+ this.updateResult({
6105
+ loading: false,
6106
+ error: error,
6107
+ data: undefined,
6108
+ called: true
6109
+ });
6110
+ }
6111
+ };
6112
+ MutationData.prototype.generateNewMutationId = function () {
6113
+ return ++this.mostRecentMutationId;
6114
+ };
6115
+ MutationData.prototype.isMostRecentMutation = function (mutationId) {
6116
+ return this.mostRecentMutationId === mutationId;
6117
+ };
6118
+ MutationData.prototype.updateResult = function (result) {
6119
+ if (this.isMounted &&
6120
+ (!this.previousResult || !equality.equal(this.previousResult, result))) {
6121
+ this.setResult(result);
6122
+ this.previousResult = result;
6123
+ return result;
6124
+ }
6125
+ };
6126
+ return MutationData;
6127
+ }(OperationData));
6128
+
6129
+ var QueryData = (function (_super) {
6130
+ tslib.__extends(QueryData, _super);
6131
+ function QueryData(_a) {
6132
+ var options = _a.options, context = _a.context, onNewData = _a.onNewData;
6133
+ var _this = _super.call(this, options, context) || this;
6134
+ _this.runLazy = false;
6135
+ _this.previous = Object.create(null);
6136
+ _this.runLazyQuery = function (options) {
6137
+ _this.cleanup();
6138
+ _this.runLazy = true;
6139
+ _this.lazyOptions = options;
6140
+ _this.onNewData();
6141
+ };
6142
+ _this.obsRefetch = function (variables) { var _a; return (_a = _this.currentObservable) === null || _a === void 0 ? void 0 : _a.refetch(variables); };
6143
+ _this.obsFetchMore = function (fetchMoreOptions) { var _a; return (_a = _this.currentObservable) === null || _a === void 0 ? void 0 : _a.fetchMore(fetchMoreOptions); };
6144
+ _this.obsUpdateQuery = function (mapFn) { var _a; return (_a = _this.currentObservable) === null || _a === void 0 ? void 0 : _a.updateQuery(mapFn); };
6145
+ _this.obsStartPolling = function (pollInterval) {
6146
+ var _a;
6147
+ (_a = _this.currentObservable) === null || _a === void 0 ? void 0 : _a.startPolling(pollInterval);
6148
+ };
6149
+ _this.obsStopPolling = function () {
6150
+ var _a;
6151
+ (_a = _this.currentObservable) === null || _a === void 0 ? void 0 : _a.stopPolling();
6152
+ };
6153
+ _this.obsSubscribeToMore = function (options) { var _a; return (_a = _this.currentObservable) === null || _a === void 0 ? void 0 : _a.subscribeToMore(options); };
6154
+ _this.onNewData = onNewData;
6155
+ return _this;
6156
+ }
6157
+ QueryData.prototype.execute = function () {
6158
+ this.refreshClient();
6159
+ var _a = this.getOptions(), skip = _a.skip, query = _a.query;
6160
+ if (skip || query !== this.previous.query) {
6161
+ this.removeQuerySubscription();
6162
+ this.removeObservable(!skip);
6163
+ this.previous.query = query;
6164
+ }
6165
+ this.updateObservableQuery();
6166
+ return this.getExecuteSsrResult() || this.getExecuteResult();
6167
+ };
6168
+ QueryData.prototype.executeLazy = function () {
6169
+ return !this.runLazy
6170
+ ? [
6171
+ this.runLazyQuery,
6172
+ {
6173
+ loading: false,
6174
+ networkStatus: exports.NetworkStatus.ready,
6175
+ called: false,
6176
+ data: undefined
6177
+ }
6178
+ ]
6179
+ : [this.runLazyQuery, this.execute()];
6180
+ };
6181
+ QueryData.prototype.fetchData = function () {
6182
+ var _this = this;
6183
+ var options = this.getOptions();
6184
+ if (options.skip || options.ssr === false)
6185
+ return false;
6186
+ return new Promise(function (resolve) { return _this.startQuerySubscription(resolve); });
6187
+ };
6188
+ QueryData.prototype.afterExecute = function (_a) {
6189
+ var _b = _a === void 0 ? {} : _a, _c = _b.lazy, lazy = _c === void 0 ? false : _c;
6190
+ this.isMounted = true;
6191
+ var options = this.getOptions();
6192
+ if (this.currentObservable &&
6193
+ !this.ssrInitiated() &&
6194
+ !this.client.disableNetworkFetches) {
6195
+ this.startQuerySubscription();
6196
+ }
6197
+ if (!lazy || this.runLazy) {
6198
+ this.handleErrorOrCompleted();
6199
+ }
6200
+ this.previousOptions = options;
6201
+ return this.unmount.bind(this);
6202
+ };
6203
+ QueryData.prototype.cleanup = function () {
6204
+ this.removeQuerySubscription();
6205
+ this.removeObservable(true);
6206
+ delete this.previous.result;
6207
+ };
6208
+ QueryData.prototype.getOptions = function () {
6209
+ var options = _super.prototype.getOptions.call(this);
6210
+ if (this.lazyOptions) {
6211
+ options.variables = tslib.__assign(tslib.__assign({}, options.variables), this.lazyOptions.variables);
6212
+ options.context = tslib.__assign(tslib.__assign({}, options.context), this.lazyOptions.context);
6213
+ }
6214
+ if (this.runLazy) {
6215
+ delete options.skip;
6216
+ }
6217
+ return options;
6218
+ };
6219
+ QueryData.prototype.ssrInitiated = function () {
6220
+ return this.context && this.context.renderPromises;
6221
+ };
6222
+ QueryData.prototype.getExecuteSsrResult = function () {
6223
+ var _a = this.getOptions(), ssr = _a.ssr, skip = _a.skip;
6224
+ var ssrDisabled = ssr === false;
6225
+ var fetchDisabled = this.refreshClient().client.disableNetworkFetches;
6226
+ var ssrLoading = tslib.__assign({ loading: true, networkStatus: exports.NetworkStatus.loading, called: true, data: undefined, stale: false, client: this.client }, this.observableQueryFields());
6227
+ if (ssrDisabled && (this.ssrInitiated() || fetchDisabled)) {
6228
+ this.previous.result = ssrLoading;
6229
+ return ssrLoading;
6230
+ }
6231
+ if (this.ssrInitiated()) {
6232
+ var result = this.getExecuteResult() || ssrLoading;
6233
+ if (result.loading && !skip) {
6234
+ this.context.renderPromises.addQueryPromise(this, function () { return null; });
6235
+ }
6236
+ return result;
6237
+ }
6238
+ };
6239
+ QueryData.prototype.prepareObservableQueryOptions = function () {
6240
+ var options = this.getOptions();
6241
+ this.verifyDocumentType(options.query, exports.DocumentType.Query);
6242
+ var displayName = options.displayName || 'Query';
6243
+ if (this.ssrInitiated() &&
6244
+ (options.fetchPolicy === 'network-only' ||
6245
+ options.fetchPolicy === 'cache-and-network')) {
6246
+ options.fetchPolicy = 'cache-first';
6247
+ }
6248
+ return tslib.__assign(tslib.__assign({}, options), { displayName: displayName, context: options.context });
6249
+ };
6250
+ QueryData.prototype.initializeObservableQuery = function () {
6251
+ if (this.ssrInitiated()) {
6252
+ this.currentObservable = this.context.renderPromises.getSSRObservable(this.getOptions());
6253
+ }
6254
+ if (!this.currentObservable) {
6255
+ var observableQueryOptions = this.prepareObservableQueryOptions();
6256
+ this.previous.observableQueryOptions = tslib.__assign(tslib.__assign({}, observableQueryOptions), { children: void 0 });
6257
+ this.currentObservable = this.refreshClient().client.watchQuery(tslib.__assign({}, observableQueryOptions));
6258
+ if (this.ssrInitiated()) {
6259
+ this.context.renderPromises.registerSSRObservable(this.currentObservable, observableQueryOptions);
6260
+ }
6261
+ }
6262
+ };
6263
+ QueryData.prototype.updateObservableQuery = function () {
6264
+ if (!this.currentObservable) {
6265
+ this.initializeObservableQuery();
6266
+ return;
6267
+ }
6268
+ var newObservableQueryOptions = tslib.__assign(tslib.__assign({}, this.prepareObservableQueryOptions()), { children: void 0 });
6269
+ if (this.getOptions().skip) {
6270
+ this.previous.observableQueryOptions = newObservableQueryOptions;
6271
+ return;
6272
+ }
6273
+ if (!equality.equal(newObservableQueryOptions, this.previous.observableQueryOptions)) {
6274
+ this.previous.observableQueryOptions = newObservableQueryOptions;
6275
+ this.currentObservable
6276
+ .setOptions(newObservableQueryOptions)
6277
+ .catch(function () { });
6278
+ }
6279
+ };
6280
+ QueryData.prototype.startQuerySubscription = function (onNewData) {
6281
+ var _this = this;
6282
+ if (onNewData === void 0) { onNewData = this.onNewData; }
6283
+ if (this.currentSubscription || this.getOptions().skip)
6284
+ return;
6285
+ this.currentSubscription = this.currentObservable.subscribe({
6286
+ next: function (_a) {
6287
+ var loading = _a.loading, networkStatus = _a.networkStatus, data = _a.data;
6288
+ var previousResult = _this.previous.result;
6289
+ if (previousResult &&
6290
+ previousResult.loading === loading &&
6291
+ previousResult.networkStatus === networkStatus &&
6292
+ equality.equal(previousResult.data, data)) {
6293
+ return;
6294
+ }
6295
+ onNewData();
6296
+ },
6297
+ error: function (error) {
6298
+ _this.resubscribeToQuery();
6299
+ if (!error.hasOwnProperty('graphQLErrors'))
6300
+ throw error;
6301
+ var previousResult = _this.previous.result;
6302
+ if ((previousResult && previousResult.loading) ||
6303
+ !equality.equal(error, _this.previous.error)) {
6304
+ _this.previous.error = error;
6305
+ onNewData();
6306
+ }
6307
+ }
6308
+ });
6309
+ };
6310
+ QueryData.prototype.resubscribeToQuery = function () {
6311
+ this.removeQuerySubscription();
6312
+ var currentObservable = this.currentObservable;
6313
+ if (currentObservable) {
6314
+ var last = currentObservable["last"];
6315
+ try {
6316
+ currentObservable.resetLastResults();
6317
+ this.startQuerySubscription();
6318
+ }
6319
+ finally {
6320
+ currentObservable["last"] = last;
6321
+ }
6322
+ }
6323
+ };
6324
+ QueryData.prototype.getExecuteResult = function () {
6325
+ var result = this.observableQueryFields();
6326
+ var options = this.getOptions();
6327
+ if (options.skip) {
6328
+ result = tslib.__assign(tslib.__assign({}, result), { data: undefined, error: undefined, loading: false, networkStatus: exports.NetworkStatus.ready, called: true });
6329
+ }
6330
+ else if (this.currentObservable) {
6331
+ var currentResult = this.currentObservable.getCurrentResult();
6332
+ var data = currentResult.data, loading = currentResult.loading, partial = currentResult.partial, networkStatus = currentResult.networkStatus, errors = currentResult.errors;
6333
+ var error = currentResult.error;
6334
+ if (errors && errors.length > 0) {
6335
+ error = new ApolloError({ graphQLErrors: errors });
6336
+ }
6337
+ result = tslib.__assign(tslib.__assign({}, result), { data: data, loading: loading, networkStatus: networkStatus, error: error, called: true });
6338
+ if (loading) ;
6339
+ else if (error) {
6340
+ Object.assign(result, {
6341
+ data: (this.currentObservable.getLastResult() || {})
6342
+ .data
6343
+ });
6344
+ }
6345
+ else {
6346
+ var fetchPolicy = this.currentObservable.options.fetchPolicy;
6347
+ var partialRefetch = options.partialRefetch;
6348
+ if (partialRefetch &&
6349
+ partial &&
6350
+ (!data || Object.keys(data).length === 0) &&
6351
+ fetchPolicy !== 'cache-only') {
6352
+ Object.assign(result, {
6353
+ loading: true,
6354
+ networkStatus: exports.NetworkStatus.loading
6355
+ });
6356
+ result.refetch();
6357
+ return result;
6358
+ }
6359
+ }
6360
+ }
6361
+ result.client = this.client;
6362
+ this.setOptions(options, true);
6363
+ var previousResult = this.previous.result;
6364
+ this.previous.loading =
6365
+ previousResult && previousResult.loading || false;
6366
+ result.previousData = previousResult &&
6367
+ (previousResult.data || previousResult.previousData);
6368
+ this.previous.result = result;
6369
+ this.currentObservable && this.currentObservable.resetQueryStoreErrors();
6370
+ return result;
6371
+ };
6372
+ QueryData.prototype.handleErrorOrCompleted = function () {
6373
+ if (!this.currentObservable || !this.previous.result)
6374
+ return;
6375
+ var _a = this.previous.result, data = _a.data, loading = _a.loading, error = _a.error;
6376
+ if (!loading) {
6377
+ var _b = this.getOptions(), query = _b.query, variables = _b.variables, onCompleted = _b.onCompleted, onError = _b.onError, skip = _b.skip;
6378
+ if (this.previousOptions &&
6379
+ !this.previous.loading &&
6380
+ equality.equal(this.previousOptions.query, query) &&
6381
+ equality.equal(this.previousOptions.variables, variables)) {
6382
+ return;
6383
+ }
6384
+ if (onCompleted && !error && !skip) {
6385
+ onCompleted(data);
6386
+ }
6387
+ else if (onError && error) {
6388
+ onError(error);
6389
+ }
6390
+ }
6391
+ };
6392
+ QueryData.prototype.removeQuerySubscription = function () {
6393
+ if (this.currentSubscription) {
6394
+ this.currentSubscription.unsubscribe();
6395
+ delete this.currentSubscription;
6396
+ }
6397
+ };
6398
+ QueryData.prototype.removeObservable = function (andDelete) {
6399
+ if (this.currentObservable) {
6400
+ this.currentObservable["tearDownQuery"]();
6401
+ if (andDelete) {
6402
+ delete this.currentObservable;
6403
+ }
6404
+ }
6405
+ };
6406
+ QueryData.prototype.observableQueryFields = function () {
6407
+ var _a;
6408
+ return {
6409
+ variables: (_a = this.currentObservable) === null || _a === void 0 ? void 0 : _a.variables,
6410
+ refetch: this.obsRefetch,
6411
+ fetchMore: this.obsFetchMore,
6412
+ updateQuery: this.obsUpdateQuery,
6413
+ startPolling: this.obsStartPolling,
6414
+ stopPolling: this.obsStopPolling,
6415
+ subscribeToMore: this.obsSubscribeToMore
6416
+ };
6417
+ };
6418
+ return QueryData;
6419
+ }(OperationData));
6420
+
6421
+ function useDeepMemo(memoFn, key) {
6422
+ var ref = React.useRef();
6423
+ if (!ref.current || !equality.equal(key, ref.current.key)) {
6424
+ ref.current = { key: key, value: memoFn() };
6425
+ }
6426
+ return ref.current.value;
6427
+ }
6428
+
6429
+ function useAfterFastRefresh(effectFn) {
6430
+ if (__DEV__) {
6431
+ var didRefresh_1 = React.useRef(false);
6432
+ React.useEffect(function () {
6433
+ return function () {
6434
+ didRefresh_1.current = true;
6435
+ };
6436
+ }, []);
6437
+ React.useEffect(function () {
6438
+ if (didRefresh_1.current === true) {
6439
+ didRefresh_1.current = false;
6440
+ effectFn();
6441
+ }
6442
+ }, []);
6443
+ }
6444
+ }
6445
+
6446
+ function useBaseQuery(query, options, lazy) {
6447
+ if (lazy === void 0) { lazy = false; }
6448
+ var context = React.useContext(getApolloContext());
6449
+ var _a = React.useReducer(function (x) { return x + 1; }, 0), tick = _a[0], forceUpdate = _a[1];
6450
+ var updatedOptions = options ? tslib.__assign(tslib.__assign({}, options), { query: query }) : { query: query };
6451
+ var queryDataRef = React.useRef();
6452
+ var queryData = queryDataRef.current || (queryDataRef.current = new QueryData({
6453
+ options: updatedOptions,
6454
+ context: context,
6455
+ onNewData: function () {
6456
+ if (!queryData.ssrInitiated()) {
6457
+ Promise.resolve().then(function () { return queryDataRef.current && queryDataRef.current.isMounted && forceUpdate(); });
6458
+ }
6459
+ else {
6460
+ forceUpdate();
6461
+ }
6462
+ }
6463
+ }));
6464
+ queryData.setOptions(updatedOptions);
6465
+ queryData.context = context;
6466
+ var memo = {
6467
+ options: tslib.__assign(tslib.__assign({}, updatedOptions), { onError: void 0, onCompleted: void 0 }),
6468
+ context: context,
6469
+ tick: tick
6470
+ };
6471
+ var result = useDeepMemo(function () { return (lazy ? queryData.executeLazy() : queryData.execute()); }, memo);
6472
+ var queryResult = lazy
6473
+ ? result[1]
6474
+ : result;
6475
+ if (__DEV__) {
6476
+ useAfterFastRefresh(forceUpdate);
6477
+ }
6478
+ React.useEffect(function () {
6479
+ return function () {
6480
+ queryData.cleanup();
6481
+ queryDataRef.current = void 0;
6482
+ };
6483
+ }, []);
6484
+ React.useEffect(function () { return queryData.afterExecute({ lazy: lazy }); }, [
6485
+ queryResult.loading,
6486
+ queryResult.networkStatus,
6487
+ queryResult.error,
6488
+ queryResult.data,
6489
+ queryData.currentObservable,
6490
+ ]);
6491
+ return result;
6492
+ }
6493
+
6494
+ function useLazyQuery(query, options) {
6495
+ return useBaseQuery(query, options, true);
6496
+ }
6497
+
6498
+ function useMutation(mutation, options) {
6499
+ var context = React.useContext(getApolloContext());
6500
+ var _a = React.useState({ called: false, loading: false }), result = _a[0], setResult = _a[1];
6501
+ var updatedOptions = options ? tslib.__assign(tslib.__assign({}, options), { mutation: mutation }) : { mutation: mutation };
6502
+ var mutationDataRef = React.useRef();
6503
+ function getMutationDataRef() {
6504
+ if (!mutationDataRef.current) {
6505
+ mutationDataRef.current = new MutationData({
6506
+ options: updatedOptions,
6507
+ context: context,
6508
+ result: result,
6509
+ setResult: setResult
6510
+ });
6511
+ }
6512
+ return mutationDataRef.current;
6513
+ }
6514
+ var mutationData = getMutationDataRef();
6515
+ mutationData.setOptions(updatedOptions);
6516
+ mutationData.context = context;
6517
+ React.useEffect(function () { return mutationData.afterExecute(); });
6518
+ return mutationData.execute(result);
6519
+ }
6520
+
6521
+ function useQuery(query, options) {
6522
+ return useBaseQuery(query, options, false);
6523
+ }
6524
+
6525
+ function useSubscription(subscription, options) {
6526
+ var _a = React.useReducer(function (x) { return x + 1; }, 0), forceUpdate = _a[1];
6527
+ var context = React.useContext(getApolloContext());
6528
+ var updatedOptions = options
6529
+ ? tslib.__assign(tslib.__assign({}, options), { subscription: subscription }) : { subscription: subscription };
6530
+ var _b = React.useState({
6531
+ loading: !updatedOptions.skip,
6532
+ error: void 0,
6533
+ data: void 0,
6534
+ }), result = _b[0], setResult = _b[1];
6535
+ var subscriptionDataRef = React.useRef();
6536
+ function getSubscriptionDataRef() {
6537
+ if (!subscriptionDataRef.current) {
6538
+ subscriptionDataRef.current = new SubscriptionData({
6539
+ options: updatedOptions,
6540
+ context: context,
6541
+ setResult: setResult
6542
+ });
6543
+ }
6544
+ return subscriptionDataRef.current;
6545
+ }
6546
+ var subscriptionData = getSubscriptionDataRef();
6547
+ subscriptionData.setOptions(updatedOptions, true);
6548
+ subscriptionData.context = context;
6549
+ if (__DEV__) {
6550
+ useAfterFastRefresh(forceUpdate);
6551
+ }
6552
+ React.useEffect(function () { return subscriptionData.afterExecute(); });
6553
+ React.useEffect(function () {
6554
+ return function () {
6555
+ subscriptionData.cleanup();
6556
+ subscriptionDataRef.current = void 0;
6557
+ };
6558
+ }, []);
6559
+ return subscriptionData.execute(result);
6560
+ }
6561
+
6562
+ function useReactiveVar(rv) {
6563
+ var value = rv();
6564
+ var setValue = React.useState(value)[1];
6565
+ React.useEffect(function () {
6566
+ var probablySameValue = rv();
6567
+ if (value !== probablySameValue) {
6568
+ setValue(probablySameValue);
6569
+ }
6570
+ else {
6571
+ return rv.onNextChange(setValue);
6572
+ }
6573
+ }, [value]);
6574
+ return value;
6575
+ }
5693
6576
 
5694
6577
  exports.setLogVerbosity = tsInvariant.setVerbosity;
5695
6578
  exports.Observable = zenObservableTs.Observable;
@@ -5700,8 +6583,10 @@ exports.gql = graphqlTag.gql;
5700
6583
  exports.resetCaches = graphqlTag.resetCaches;
5701
6584
  exports.ApolloCache = ApolloCache;
5702
6585
  exports.ApolloClient = ApolloClient;
6586
+ exports.ApolloConsumer = ApolloConsumer;
5703
6587
  exports.ApolloError = ApolloError;
5704
6588
  exports.ApolloLink = ApolloLink;
6589
+ exports.ApolloProvider = ApolloProvider;
5705
6590
  exports.HttpLink = HttpLink;
5706
6591
  exports.InMemoryCache = InMemoryCache;
5707
6592
  exports.MissingFieldError = MissingFieldError;
@@ -5718,12 +6603,16 @@ exports.fallbackHttpConfig = fallbackHttpConfig;
5718
6603
  exports.from = from;
5719
6604
  exports.fromError = fromError;
5720
6605
  exports.fromPromise = fromPromise;
6606
+ exports.getApolloContext = getApolloContext;
5721
6607
  exports.isApolloError = isApolloError;
5722
6608
  exports.isReference = isReference;
5723
6609
  exports.makeReference = makeReference;
5724
6610
  exports.makeVar = makeVar;
5725
6611
  exports.mergeOptions = mergeOptions;
6612
+ exports.operationName = operationName;
5726
6613
  exports.parseAndCheckHttpResponse = parseAndCheckHttpResponse;
6614
+ exports.parser = parser;
6615
+ exports.resetApolloContext = getApolloContext;
5727
6616
  exports.rewriteURIForGET = rewriteURIForGET;
5728
6617
  exports.selectHttpOptionsAndBody = selectHttpOptionsAndBody;
5729
6618
  exports.selectURI = selectURI;
@@ -5731,4 +6620,10 @@ exports.serializeFetchParameter = serializeFetchParameter;
5731
6620
  exports.split = split;
5732
6621
  exports.throwServerError = throwServerError;
5733
6622
  exports.toPromise = toPromise;
6623
+ exports.useApolloClient = useApolloClient;
6624
+ exports.useLazyQuery = useLazyQuery;
6625
+ exports.useMutation = useMutation;
6626
+ exports.useQuery = useQuery;
6627
+ exports.useReactiveVar = useReactiveVar;
6628
+ exports.useSubscription = useSubscription;
5734
6629
  //# sourceMappingURL=apollo-client.cjs.js.map