@apollo/client 3.4.3 → 3.4.7

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 (61) hide show
  1. package/apollo-client.cjs.js +901 -29
  2. package/apollo-client.cjs.js.map +1 -1
  3. package/apollo-core.cjs.js +5745 -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 +3 -3
  7. package/cache/cache.cjs.js.map +1 -1
  8. package/cache/inmemory/writeToStore.d.ts +1 -1
  9. package/cache/inmemory/writeToStore.d.ts.map +1 -1
  10. package/cache/inmemory/writeToStore.js +3 -3
  11. package/cache/inmemory/writeToStore.js.map +1 -1
  12. package/core/ObservableQuery.d.ts +2 -0
  13. package/core/ObservableQuery.d.ts.map +1 -1
  14. package/core/ObservableQuery.js +9 -4
  15. package/core/ObservableQuery.js.map +1 -1
  16. package/core/QueryInfo.d.ts +5 -3
  17. package/core/QueryInfo.d.ts.map +1 -1
  18. package/core/QueryInfo.js +4 -2
  19. package/core/QueryInfo.js.map +1 -1
  20. package/core/QueryManager.d.ts +3 -3
  21. package/core/QueryManager.d.ts.map +1 -1
  22. package/core/QueryManager.js +15 -13
  23. package/core/QueryManager.js.map +1 -1
  24. package/core/core.cjs.js +28 -18
  25. package/core/core.cjs.js.map +1 -1
  26. package/core/watchQueryOptions.d.ts +2 -1
  27. package/core/watchQueryOptions.d.ts.map +1 -1
  28. package/core/watchQueryOptions.js.map +1 -1
  29. package/invariantErrorCodes.js +4 -2
  30. package/link/http/createHttpLink.d.ts.map +1 -1
  31. package/link/http/createHttpLink.js +7 -5
  32. package/link/http/createHttpLink.js.map +1 -1
  33. package/link/http/http.cjs.js +6 -5
  34. package/link/http/http.cjs.js.map +1 -1
  35. package/package.json +8 -11
  36. package/react/data/QueryData.d.ts +2 -1
  37. package/react/data/QueryData.d.ts.map +1 -1
  38. package/react/data/QueryData.js.map +1 -1
  39. package/react/hooks/hooks.cjs.js +1 -0
  40. package/react/hooks/hooks.cjs.js.map +1 -1
  41. package/react/hooks/utils/useBaseQuery.d.ts.map +1 -1
  42. package/react/hooks/utils/useBaseQuery.js +1 -0
  43. package/react/hooks/utils/useBaseQuery.js.map +1 -1
  44. package/testing/testing.cjs.js +0 -5
  45. package/testing/testing.cjs.js.map +1 -1
  46. package/utilities/index.d.ts +1 -0
  47. package/utilities/index.d.ts.map +1 -1
  48. package/utilities/index.js +1 -0
  49. package/utilities/index.js.map +1 -1
  50. package/utilities/testing/index.d.ts +0 -1
  51. package/utilities/testing/index.d.ts.map +1 -1
  52. package/utilities/testing/index.js +0 -1
  53. package/utilities/testing/index.js.map +1 -1
  54. package/utilities/utilities.cjs.js +1 -0
  55. package/utilities/utilities.cjs.js.map +1 -1
  56. package/version.js +1 -1
  57. package/apollo-client.cjs.min.js +0 -1
  58. package/utilities/testing/stripSymbols.d.ts +0 -2
  59. package/utilities/testing/stripSymbols.d.ts.map +0 -1
  60. package/utilities/testing/stripSymbols.js +0 -4
  61. 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.3';
1310
+ var version = '3.4.7';
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
  }
@@ -3766,7 +3782,7 @@ var ObservableQuery = (function (_super) {
3766
3782
  };
3767
3783
  _this.isTornDown = false;
3768
3784
  _this.options = options;
3769
- _this.queryId = queryManager.generateQueryId();
3785
+ _this.queryId = queryInfo.queryId || queryManager.generateQueryId();
3770
3786
  var opDef = getOperationDefinition(options.query);
3771
3787
  _this.queryName = opDef && opDef.name && opDef.name.value;
3772
3788
  _this.initialFetchPolicy = options.fetchPolicy || "cache-first";
@@ -3823,12 +3839,13 @@ var ObservableQuery = (function (_super) {
3823
3839
  else if (fetchPolicy !== "no-cache") {
3824
3840
  result.partial = true;
3825
3841
  }
3826
- if (!diff.complete &&
3842
+ if (__DEV__ &&
3843
+ !diff.complete &&
3827
3844
  !this.options.partialRefetch &&
3828
3845
  !result.loading &&
3829
3846
  !result.data &&
3830
3847
  !result.error) {
3831
- result.error = new ApolloError({ clientErrors: diff.missing });
3848
+ logMissingFieldErrors(diff.missing);
3832
3849
  }
3833
3850
  }
3834
3851
  if (saveAsLastResult) {
@@ -4103,6 +4120,11 @@ fixObservableSubclass(ObservableQuery);
4103
4120
  function defaultSubscriptionObserverErrorCallback(error) {
4104
4121
  __DEV__ && tsInvariant.invariant.error('Unhandled error', error.message, error.stack);
4105
4122
  }
4123
+ function logMissingFieldErrors(missing) {
4124
+ if (__DEV__ && isNonEmptyArray(missing)) {
4125
+ __DEV__ && tsInvariant.invariant.debug("Missing cache result fields: " + missing.map(function (m) { return m.path.join('.'); }).join(', '), missing);
4126
+ }
4127
+ }
4106
4128
  function applyNextFetchPolicy(options) {
4107
4129
  var _a = options.fetchPolicy, fetchPolicy = _a === void 0 ? "cache-first" : _a, nextFetchPolicy = options.nextFetchPolicy;
4108
4130
  if (nextFetchPolicy) {
@@ -4390,8 +4412,9 @@ function cancelNotifyTimeout(info) {
4390
4412
  }
4391
4413
  }
4392
4414
  var QueryInfo = (function () {
4393
- function QueryInfo(cache) {
4394
- this.cache = cache;
4415
+ function QueryInfo(queryManager, queryId) {
4416
+ if (queryId === void 0) { queryId = queryManager.generateQueryId(); }
4417
+ this.queryId = queryId;
4395
4418
  this.listeners = new Set();
4396
4419
  this.document = null;
4397
4420
  this.lastRequestId = 1;
@@ -4399,6 +4422,7 @@ var QueryInfo = (function () {
4399
4422
  this.stopped = false;
4400
4423
  this.dirty = false;
4401
4424
  this.observableQuery = null;
4425
+ var cache = this.cache = queryManager.cache;
4402
4426
  if (!destructiveMethodCounts.has(cache)) {
4403
4427
  destructiveMethodCounts.set(cache, 0);
4404
4428
  wrapDestructiveCacheMethod(cache, "evict");
@@ -4672,22 +4696,24 @@ var QueryManager = (function () {
4672
4696
  this.fetchCancelFns.clear();
4673
4697
  };
4674
4698
  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;
4699
+ 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
4700
  return tslib.__awaiter(this, void 0, void 0, function () {
4677
4701
  var mutationId, mutationStoreValue, self;
4678
- return tslib.__generator(this, function (_e) {
4679
- switch (_e.label) {
4702
+ return tslib.__generator(this, function (_f) {
4703
+ switch (_f.label) {
4680
4704
  case 0:
4681
4705
  __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);
4706
+ __DEV__ ? tsInvariant.invariant(fetchPolicy === 'network-only' ||
4707
+ 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' ||
4708
+ fetchPolicy === 'no-cache', 16);
4683
4709
  mutationId = this.generateMutationId();
4684
4710
  mutation = this.transform(mutation).document;
4685
4711
  variables = this.getVariables(mutation, variables);
4686
4712
  if (!this.transform(mutation).hasClientExports) return [3, 2];
4687
4713
  return [4, this.localState.addExportedVariables(mutation, variables, context)];
4688
4714
  case 1:
4689
- variables = (_e.sent());
4690
- _e.label = 2;
4715
+ variables = (_f.sent());
4716
+ _f.label = 2;
4691
4717
  case 2:
4692
4718
  mutationStoreValue = this.mutationStore &&
4693
4719
  (this.mutationStore[mutationId] = {
@@ -4946,7 +4972,7 @@ var QueryManager = (function () {
4946
4972
  if (typeof options.notifyOnNetworkStatusChange === 'undefined') {
4947
4973
  options.notifyOnNetworkStatusChange = false;
4948
4974
  }
4949
- var queryInfo = new QueryInfo(this.cache);
4975
+ var queryInfo = new QueryInfo(this);
4950
4976
  var observable = new ObservableQuery({
4951
4977
  queryManager: this,
4952
4978
  queryInfo: queryInfo,
@@ -5062,6 +5088,7 @@ var QueryManager = (function () {
5062
5088
  queryInfo: queryInfo,
5063
5089
  options: tslib.__assign(tslib.__assign({}, options), { fetchPolicy: "network-only" }),
5064
5090
  });
5091
+ tsInvariant.invariant(oq.queryId === queryId);
5065
5092
  queryInfo.setObservableQuery(oq);
5066
5093
  queries.set(queryId, oq);
5067
5094
  });
@@ -5356,10 +5383,9 @@ var QueryManager = (function () {
5356
5383
  if (networkStatus === void 0) { networkStatus = queryInfo.networkStatus || exports.NetworkStatus.loading; }
5357
5384
  var data = diff.result;
5358
5385
  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);
5386
+ !returnPartialData &&
5387
+ !equality.equal(data, {})) {
5388
+ logMissingFieldErrors(diff.missing);
5363
5389
  }
5364
5390
  var fromData = function (data) { return zenObservableTs.Observable.of(tslib.__assign({ data: data, loading: isNetworkRequestInFlight(networkStatus), networkStatus: networkStatus }, (diff.complete ? null : { partial: true }))); };
5365
5391
  if (data && _this.transform(query).hasForcedResolvers) {
@@ -5446,7 +5472,7 @@ var QueryManager = (function () {
5446
5472
  };
5447
5473
  QueryManager.prototype.getQuery = function (queryId) {
5448
5474
  if (queryId && !this.queries.has(queryId)) {
5449
- this.queries.set(queryId, new QueryInfo(this.cache));
5475
+ this.queries.set(queryId, new QueryInfo(this, queryId));
5450
5476
  }
5451
5477
  return this.queries.get(queryId);
5452
5478
  };
@@ -5689,7 +5715,841 @@ var ApolloClient = (function () {
5689
5715
  return ApolloClient;
5690
5716
  }());
5691
5717
 
5692
- tsInvariant.setVerbosity(DEV ? "log" : "silent");
5718
+ var cache$1 = new (canUseWeakMap ? WeakMap : Map)();
5719
+ function getApolloContext() {
5720
+ var context = cache$1.get(React__namespace.createContext);
5721
+ if (!context) {
5722
+ context = React__namespace.createContext({});
5723
+ context.displayName = 'ApolloContext';
5724
+ cache$1.set(React__namespace.createContext, context);
5725
+ }
5726
+ return context;
5727
+ }
5728
+
5729
+ var ApolloConsumer = function (props) {
5730
+ var ApolloContext = getApolloContext();
5731
+ return React__namespace.createElement(ApolloContext.Consumer, null, function (context) {
5732
+ __DEV__ ? tsInvariant.invariant(context && context.client, 'Could not find "client" in the context of ApolloConsumer. ' +
5733
+ 'Wrap the root component in an <ApolloProvider>.') : tsInvariant.invariant(context && context.client, 30);
5734
+ return props.children(context.client);
5735
+ });
5736
+ };
5737
+
5738
+ var ApolloProvider = function (_a) {
5739
+ var client = _a.client, children = _a.children;
5740
+ var ApolloContext = getApolloContext();
5741
+ return React__namespace.createElement(ApolloContext.Consumer, null, function (context) {
5742
+ if (context === void 0) { context = {}; }
5743
+ if (client && context.client !== client) {
5744
+ context = Object.assign({}, context, { client: client });
5745
+ }
5746
+ __DEV__ ? tsInvariant.invariant(context.client, 'ApolloProvider was not passed a client instance. Make ' +
5747
+ 'sure you pass in your client via the "client" prop.') : tsInvariant.invariant(context.client, 31);
5748
+ return (React__namespace.createElement(ApolloContext.Provider, { value: context }, children));
5749
+ });
5750
+ };
5751
+
5752
+ function useApolloClient() {
5753
+ var client = React__namespace.useContext(getApolloContext()).client;
5754
+ __DEV__ ? tsInvariant.invariant(client, 'No Apollo Client instance can be found. Please ensure that you ' +
5755
+ 'have called `ApolloProvider` higher up in your tree.') : tsInvariant.invariant(client, 36);
5756
+ return client;
5757
+ }
5758
+
5759
+ exports.DocumentType = void 0;
5760
+ (function (DocumentType) {
5761
+ DocumentType[DocumentType["Query"] = 0] = "Query";
5762
+ DocumentType[DocumentType["Mutation"] = 1] = "Mutation";
5763
+ DocumentType[DocumentType["Subscription"] = 2] = "Subscription";
5764
+ })(exports.DocumentType || (exports.DocumentType = {}));
5765
+ var cache = new Map();
5766
+ function operationName(type) {
5767
+ var name;
5768
+ switch (type) {
5769
+ case exports.DocumentType.Query:
5770
+ name = 'Query';
5771
+ break;
5772
+ case exports.DocumentType.Mutation:
5773
+ name = 'Mutation';
5774
+ break;
5775
+ case exports.DocumentType.Subscription:
5776
+ name = 'Subscription';
5777
+ break;
5778
+ }
5779
+ return name;
5780
+ }
5781
+ function parser(document) {
5782
+ var cached = cache.get(document);
5783
+ if (cached)
5784
+ return cached;
5785
+ var variables, type, name;
5786
+ __DEV__ ? tsInvariant.invariant(!!document && !!document.kind, "Argument of " + document + " passed to parser was not a valid GraphQL " +
5787
+ "DocumentNode. You may need to use 'graphql-tag' or another method " +
5788
+ "to convert your operation into a document") : tsInvariant.invariant(!!document && !!document.kind, 38);
5789
+ var fragments = document.definitions.filter(function (x) { return x.kind === 'FragmentDefinition'; });
5790
+ var queries = document.definitions.filter(function (x) {
5791
+ return x.kind === 'OperationDefinition' && x.operation === 'query';
5792
+ });
5793
+ var mutations = document.definitions.filter(function (x) {
5794
+ return x.kind === 'OperationDefinition' && x.operation === 'mutation';
5795
+ });
5796
+ var subscriptions = document.definitions.filter(function (x) {
5797
+ return x.kind === 'OperationDefinition' && x.operation === 'subscription';
5798
+ });
5799
+ __DEV__ ? tsInvariant.invariant(!fragments.length ||
5800
+ (queries.length || mutations.length || subscriptions.length), "Passing only a fragment to 'graphql' is not yet supported. " +
5801
+ "You must include a query, subscription or mutation as well") : tsInvariant.invariant(!fragments.length ||
5802
+ (queries.length || mutations.length || subscriptions.length), 39);
5803
+ __DEV__ ? tsInvariant.invariant(queries.length + mutations.length + subscriptions.length <= 1, "react-apollo only supports a query, subscription, or a mutation per HOC. " +
5804
+ (document + " had " + queries.length + " queries, " + subscriptions.length + " ") +
5805
+ ("subscriptions and " + mutations.length + " mutations. ") +
5806
+ "You can use 'compose' to join multiple operation types to a component") : tsInvariant.invariant(queries.length + mutations.length + subscriptions.length <= 1, 40);
5807
+ type = queries.length ? exports.DocumentType.Query : exports.DocumentType.Mutation;
5808
+ if (!queries.length && !mutations.length)
5809
+ type = exports.DocumentType.Subscription;
5810
+ var definitions = queries.length
5811
+ ? queries
5812
+ : mutations.length
5813
+ ? mutations
5814
+ : subscriptions;
5815
+ __DEV__ ? tsInvariant.invariant(definitions.length === 1, "react-apollo only supports one definition per HOC. " + document + " had " +
5816
+ (definitions.length + " definitions. ") +
5817
+ "You can use 'compose' to join multiple operation types to a component") : tsInvariant.invariant(definitions.length === 1, 41);
5818
+ var definition = definitions[0];
5819
+ variables = definition.variableDefinitions || [];
5820
+ if (definition.name && definition.name.kind === 'Name') {
5821
+ name = definition.name.value;
5822
+ }
5823
+ else {
5824
+ name = 'data';
5825
+ }
5826
+ var payload = { name: name, type: type, variables: variables };
5827
+ cache.set(document, payload);
5828
+ return payload;
5829
+ }
5830
+
5831
+ var OperationData = (function () {
5832
+ function OperationData(options, context) {
5833
+ this.isMounted = false;
5834
+ this.previousOptions = {};
5835
+ this.context = {};
5836
+ this.options = {};
5837
+ this.options = options || {};
5838
+ this.context = context || {};
5839
+ }
5840
+ OperationData.prototype.getOptions = function () {
5841
+ return this.options;
5842
+ };
5843
+ OperationData.prototype.setOptions = function (newOptions, storePrevious) {
5844
+ if (storePrevious === void 0) { storePrevious = false; }
5845
+ if (storePrevious && !equality.equal(this.options, newOptions)) {
5846
+ this.previousOptions = this.options;
5847
+ }
5848
+ this.options = newOptions;
5849
+ };
5850
+ OperationData.prototype.unmount = function () {
5851
+ this.isMounted = false;
5852
+ };
5853
+ OperationData.prototype.refreshClient = function () {
5854
+ var client = (this.options && this.options.client) ||
5855
+ (this.context && this.context.client);
5856
+ __DEV__ ? tsInvariant.invariant(!!client, 'Could not find "client" in the context or passed in as an option. ' +
5857
+ 'Wrap the root component in an <ApolloProvider>, or pass an ' +
5858
+ 'ApolloClient instance in via options.') : tsInvariant.invariant(!!client, 32);
5859
+ var isNew = false;
5860
+ if (client !== this.client) {
5861
+ isNew = true;
5862
+ this.client = client;
5863
+ this.cleanup();
5864
+ }
5865
+ return {
5866
+ client: this.client,
5867
+ isNew: isNew
5868
+ };
5869
+ };
5870
+ OperationData.prototype.verifyDocumentType = function (document, type) {
5871
+ var operation = parser(document);
5872
+ var requiredOperationName = operationName(type);
5873
+ var usedOperationName = operationName(operation.type);
5874
+ __DEV__ ? tsInvariant.invariant(operation.type === type, "Running a " + requiredOperationName + " requires a graphql " +
5875
+ (requiredOperationName + ", but a " + usedOperationName + " was used instead.")) : tsInvariant.invariant(operation.type === type, 33);
5876
+ };
5877
+ return OperationData;
5878
+ }());
5879
+
5880
+ var SubscriptionData = (function (_super) {
5881
+ tslib.__extends(SubscriptionData, _super);
5882
+ function SubscriptionData(_a) {
5883
+ var options = _a.options, context = _a.context, setResult = _a.setResult;
5884
+ var _this = _super.call(this, options, context) || this;
5885
+ _this.currentObservable = {};
5886
+ _this.setResult = setResult;
5887
+ _this.initialize(options);
5888
+ return _this;
5889
+ }
5890
+ SubscriptionData.prototype.execute = function (result) {
5891
+ if (this.getOptions().skip === true) {
5892
+ this.cleanup();
5893
+ return {
5894
+ loading: false,
5895
+ error: undefined,
5896
+ data: undefined,
5897
+ variables: this.getOptions().variables
5898
+ };
5899
+ }
5900
+ var currentResult = result;
5901
+ if (this.refreshClient().isNew) {
5902
+ currentResult = this.getLoadingResult();
5903
+ }
5904
+ var shouldResubscribe = this.getOptions().shouldResubscribe;
5905
+ if (typeof shouldResubscribe === 'function') {
5906
+ shouldResubscribe = !!shouldResubscribe(this.getOptions());
5907
+ }
5908
+ if (shouldResubscribe !== false &&
5909
+ this.previousOptions &&
5910
+ Object.keys(this.previousOptions).length > 0 &&
5911
+ (this.previousOptions.subscription !== this.getOptions().subscription ||
5912
+ !equality.equal(this.previousOptions.variables, this.getOptions().variables) ||
5913
+ this.previousOptions.skip !== this.getOptions().skip)) {
5914
+ this.cleanup();
5915
+ currentResult = this.getLoadingResult();
5916
+ }
5917
+ this.initialize(this.getOptions());
5918
+ this.startSubscription();
5919
+ this.previousOptions = this.getOptions();
5920
+ return tslib.__assign(tslib.__assign({}, currentResult), { variables: this.getOptions().variables });
5921
+ };
5922
+ SubscriptionData.prototype.afterExecute = function () {
5923
+ this.isMounted = true;
5924
+ };
5925
+ SubscriptionData.prototype.cleanup = function () {
5926
+ this.endSubscription();
5927
+ delete this.currentObservable.query;
5928
+ };
5929
+ SubscriptionData.prototype.initialize = function (options) {
5930
+ if (this.currentObservable.query || this.getOptions().skip === true)
5931
+ return;
5932
+ this.currentObservable.query = this.refreshClient().client.subscribe({
5933
+ query: options.subscription,
5934
+ variables: options.variables,
5935
+ fetchPolicy: options.fetchPolicy,
5936
+ context: options.context,
5937
+ });
5938
+ };
5939
+ SubscriptionData.prototype.startSubscription = function () {
5940
+ if (this.currentObservable.subscription)
5941
+ return;
5942
+ this.currentObservable.subscription = this.currentObservable.query.subscribe({
5943
+ next: this.updateCurrentData.bind(this),
5944
+ error: this.updateError.bind(this),
5945
+ complete: this.completeSubscription.bind(this)
5946
+ });
5947
+ };
5948
+ SubscriptionData.prototype.getLoadingResult = function () {
5949
+ return {
5950
+ loading: true,
5951
+ error: undefined,
5952
+ data: undefined
5953
+ };
5954
+ };
5955
+ SubscriptionData.prototype.updateResult = function (result) {
5956
+ if (this.isMounted) {
5957
+ this.setResult(result);
5958
+ }
5959
+ };
5960
+ SubscriptionData.prototype.updateCurrentData = function (result) {
5961
+ var onSubscriptionData = this.getOptions().onSubscriptionData;
5962
+ this.updateResult({
5963
+ data: result.data,
5964
+ loading: false,
5965
+ error: undefined
5966
+ });
5967
+ if (onSubscriptionData) {
5968
+ onSubscriptionData({
5969
+ client: this.refreshClient().client,
5970
+ subscriptionData: result
5971
+ });
5972
+ }
5973
+ };
5974
+ SubscriptionData.prototype.updateError = function (error) {
5975
+ this.updateResult({
5976
+ error: error,
5977
+ loading: false
5978
+ });
5979
+ };
5980
+ SubscriptionData.prototype.completeSubscription = function () {
5981
+ var _this = this;
5982
+ Promise.resolve().then(function () {
5983
+ var onSubscriptionComplete = _this.getOptions().onSubscriptionComplete;
5984
+ if (onSubscriptionComplete)
5985
+ onSubscriptionComplete();
5986
+ _this.endSubscription();
5987
+ });
5988
+ };
5989
+ SubscriptionData.prototype.endSubscription = function () {
5990
+ if (this.currentObservable.subscription) {
5991
+ this.currentObservable.subscription.unsubscribe();
5992
+ delete this.currentObservable.subscription;
5993
+ }
5994
+ };
5995
+ return SubscriptionData;
5996
+ }(OperationData));
5997
+
5998
+ var MutationData = (function (_super) {
5999
+ tslib.__extends(MutationData, _super);
6000
+ function MutationData(_a) {
6001
+ var options = _a.options, context = _a.context, result = _a.result, setResult = _a.setResult;
6002
+ var _this = _super.call(this, options, context) || this;
6003
+ _this.runMutation = function (mutationFunctionOptions) {
6004
+ if (mutationFunctionOptions === void 0) { mutationFunctionOptions = {}; }
6005
+ _this.onMutationStart();
6006
+ var mutationId = _this.generateNewMutationId();
6007
+ return _this.mutate(mutationFunctionOptions)
6008
+ .then(function (response) {
6009
+ _this.onMutationCompleted(response, mutationId);
6010
+ return response;
6011
+ })
6012
+ .catch(function (error) {
6013
+ var onError = _this.getOptions().onError;
6014
+ _this.onMutationError(error, mutationId);
6015
+ if (onError) {
6016
+ onError(error);
6017
+ return {
6018
+ data: undefined,
6019
+ errors: error,
6020
+ };
6021
+ }
6022
+ else {
6023
+ throw error;
6024
+ }
6025
+ });
6026
+ };
6027
+ _this.verifyDocumentType(options.mutation, exports.DocumentType.Mutation);
6028
+ _this.result = result;
6029
+ _this.setResult = setResult;
6030
+ _this.mostRecentMutationId = 0;
6031
+ return _this;
6032
+ }
6033
+ MutationData.prototype.execute = function (result) {
6034
+ this.isMounted = true;
6035
+ this.verifyDocumentType(this.getOptions().mutation, exports.DocumentType.Mutation);
6036
+ return [
6037
+ this.runMutation,
6038
+ tslib.__assign(tslib.__assign({}, result), { client: this.refreshClient().client })
6039
+ ];
6040
+ };
6041
+ MutationData.prototype.afterExecute = function () {
6042
+ this.isMounted = true;
6043
+ return this.unmount.bind(this);
6044
+ };
6045
+ MutationData.prototype.cleanup = function () {
6046
+ };
6047
+ MutationData.prototype.mutate = function (options) {
6048
+ return this.refreshClient().client.mutate(mergeOptions(this.getOptions(), options));
6049
+ };
6050
+ MutationData.prototype.onMutationStart = function () {
6051
+ if (!this.result.loading && !this.getOptions().ignoreResults) {
6052
+ this.updateResult({
6053
+ loading: true,
6054
+ error: undefined,
6055
+ data: undefined,
6056
+ called: true
6057
+ });
6058
+ }
6059
+ };
6060
+ MutationData.prototype.onMutationCompleted = function (response, mutationId) {
6061
+ var _a = this.getOptions(), onCompleted = _a.onCompleted, ignoreResults = _a.ignoreResults;
6062
+ var data = response.data, errors = response.errors;
6063
+ var error = errors && errors.length > 0
6064
+ ? new ApolloError({ graphQLErrors: errors })
6065
+ : undefined;
6066
+ var callOncomplete = function () {
6067
+ return onCompleted ? onCompleted(data) : null;
6068
+ };
6069
+ if (this.isMostRecentMutation(mutationId) && !ignoreResults) {
6070
+ this.updateResult({
6071
+ called: true,
6072
+ loading: false,
6073
+ data: data,
6074
+ error: error
6075
+ });
6076
+ }
6077
+ callOncomplete();
6078
+ };
6079
+ MutationData.prototype.onMutationError = function (error, mutationId) {
6080
+ if (this.isMostRecentMutation(mutationId)) {
6081
+ this.updateResult({
6082
+ loading: false,
6083
+ error: error,
6084
+ data: undefined,
6085
+ called: true
6086
+ });
6087
+ }
6088
+ };
6089
+ MutationData.prototype.generateNewMutationId = function () {
6090
+ return ++this.mostRecentMutationId;
6091
+ };
6092
+ MutationData.prototype.isMostRecentMutation = function (mutationId) {
6093
+ return this.mostRecentMutationId === mutationId;
6094
+ };
6095
+ MutationData.prototype.updateResult = function (result) {
6096
+ if (this.isMounted &&
6097
+ (!this.previousResult || !equality.equal(this.previousResult, result))) {
6098
+ this.setResult(result);
6099
+ this.previousResult = result;
6100
+ return result;
6101
+ }
6102
+ };
6103
+ return MutationData;
6104
+ }(OperationData));
6105
+
6106
+ var QueryData = (function (_super) {
6107
+ tslib.__extends(QueryData, _super);
6108
+ function QueryData(_a) {
6109
+ var options = _a.options, context = _a.context, onNewData = _a.onNewData;
6110
+ var _this = _super.call(this, options, context) || this;
6111
+ _this.runLazy = false;
6112
+ _this.previous = Object.create(null);
6113
+ _this.runLazyQuery = function (options) {
6114
+ _this.cleanup();
6115
+ _this.runLazy = true;
6116
+ _this.lazyOptions = options;
6117
+ _this.onNewData();
6118
+ };
6119
+ _this.obsRefetch = function (variables) { var _a; return (_a = _this.currentObservable) === null || _a === void 0 ? void 0 : _a.refetch(variables); };
6120
+ _this.obsFetchMore = function (fetchMoreOptions) { var _a; return (_a = _this.currentObservable) === null || _a === void 0 ? void 0 : _a.fetchMore(fetchMoreOptions); };
6121
+ _this.obsUpdateQuery = function (mapFn) { var _a; return (_a = _this.currentObservable) === null || _a === void 0 ? void 0 : _a.updateQuery(mapFn); };
6122
+ _this.obsStartPolling = function (pollInterval) {
6123
+ var _a;
6124
+ (_a = _this.currentObservable) === null || _a === void 0 ? void 0 : _a.startPolling(pollInterval);
6125
+ };
6126
+ _this.obsStopPolling = function () {
6127
+ var _a;
6128
+ (_a = _this.currentObservable) === null || _a === void 0 ? void 0 : _a.stopPolling();
6129
+ };
6130
+ _this.obsSubscribeToMore = function (options) { var _a; return (_a = _this.currentObservable) === null || _a === void 0 ? void 0 : _a.subscribeToMore(options); };
6131
+ _this.onNewData = onNewData;
6132
+ return _this;
6133
+ }
6134
+ QueryData.prototype.execute = function () {
6135
+ this.refreshClient();
6136
+ var _a = this.getOptions(), skip = _a.skip, query = _a.query;
6137
+ if (skip || query !== this.previous.query) {
6138
+ this.removeQuerySubscription();
6139
+ this.removeObservable(!skip);
6140
+ this.previous.query = query;
6141
+ }
6142
+ this.updateObservableQuery();
6143
+ return this.getExecuteSsrResult() || this.getExecuteResult();
6144
+ };
6145
+ QueryData.prototype.executeLazy = function () {
6146
+ return !this.runLazy
6147
+ ? [
6148
+ this.runLazyQuery,
6149
+ {
6150
+ loading: false,
6151
+ networkStatus: exports.NetworkStatus.ready,
6152
+ called: false,
6153
+ data: undefined
6154
+ }
6155
+ ]
6156
+ : [this.runLazyQuery, this.execute()];
6157
+ };
6158
+ QueryData.prototype.fetchData = function () {
6159
+ var _this = this;
6160
+ var options = this.getOptions();
6161
+ if (options.skip || options.ssr === false)
6162
+ return false;
6163
+ return new Promise(function (resolve) { return _this.startQuerySubscription(resolve); });
6164
+ };
6165
+ QueryData.prototype.afterExecute = function (_a) {
6166
+ var _b = _a === void 0 ? {} : _a, _c = _b.lazy, lazy = _c === void 0 ? false : _c;
6167
+ this.isMounted = true;
6168
+ var options = this.getOptions();
6169
+ if (this.currentObservable &&
6170
+ !this.ssrInitiated() &&
6171
+ !this.client.disableNetworkFetches) {
6172
+ this.startQuerySubscription();
6173
+ }
6174
+ if (!lazy || this.runLazy) {
6175
+ this.handleErrorOrCompleted();
6176
+ }
6177
+ this.previousOptions = options;
6178
+ return this.unmount.bind(this);
6179
+ };
6180
+ QueryData.prototype.cleanup = function () {
6181
+ this.removeQuerySubscription();
6182
+ this.removeObservable(true);
6183
+ delete this.previous.result;
6184
+ };
6185
+ QueryData.prototype.getOptions = function () {
6186
+ var options = _super.prototype.getOptions.call(this);
6187
+ if (this.lazyOptions) {
6188
+ options.variables = tslib.__assign(tslib.__assign({}, options.variables), this.lazyOptions.variables);
6189
+ options.context = tslib.__assign(tslib.__assign({}, options.context), this.lazyOptions.context);
6190
+ }
6191
+ if (this.runLazy) {
6192
+ delete options.skip;
6193
+ }
6194
+ return options;
6195
+ };
6196
+ QueryData.prototype.ssrInitiated = function () {
6197
+ return this.context && this.context.renderPromises;
6198
+ };
6199
+ QueryData.prototype.getExecuteSsrResult = function () {
6200
+ var _a = this.getOptions(), ssr = _a.ssr, skip = _a.skip;
6201
+ var ssrDisabled = ssr === false;
6202
+ var fetchDisabled = this.refreshClient().client.disableNetworkFetches;
6203
+ var ssrLoading = tslib.__assign({ loading: true, networkStatus: exports.NetworkStatus.loading, called: true, data: undefined, stale: false, client: this.client }, this.observableQueryFields());
6204
+ if (ssrDisabled && (this.ssrInitiated() || fetchDisabled)) {
6205
+ this.previous.result = ssrLoading;
6206
+ return ssrLoading;
6207
+ }
6208
+ if (this.ssrInitiated()) {
6209
+ var result = this.getExecuteResult() || ssrLoading;
6210
+ if (result.loading && !skip) {
6211
+ this.context.renderPromises.addQueryPromise(this, function () { return null; });
6212
+ }
6213
+ return result;
6214
+ }
6215
+ };
6216
+ QueryData.prototype.prepareObservableQueryOptions = function () {
6217
+ var options = this.getOptions();
6218
+ this.verifyDocumentType(options.query, exports.DocumentType.Query);
6219
+ var displayName = options.displayName || 'Query';
6220
+ if (this.ssrInitiated() &&
6221
+ (options.fetchPolicy === 'network-only' ||
6222
+ options.fetchPolicy === 'cache-and-network')) {
6223
+ options.fetchPolicy = 'cache-first';
6224
+ }
6225
+ return tslib.__assign(tslib.__assign({}, options), { displayName: displayName, context: options.context });
6226
+ };
6227
+ QueryData.prototype.initializeObservableQuery = function () {
6228
+ if (this.ssrInitiated()) {
6229
+ this.currentObservable = this.context.renderPromises.getSSRObservable(this.getOptions());
6230
+ }
6231
+ if (!this.currentObservable) {
6232
+ var observableQueryOptions = this.prepareObservableQueryOptions();
6233
+ this.previous.observableQueryOptions = tslib.__assign(tslib.__assign({}, observableQueryOptions), { children: void 0 });
6234
+ this.currentObservable = this.refreshClient().client.watchQuery(tslib.__assign({}, observableQueryOptions));
6235
+ if (this.ssrInitiated()) {
6236
+ this.context.renderPromises.registerSSRObservable(this.currentObservable, observableQueryOptions);
6237
+ }
6238
+ }
6239
+ };
6240
+ QueryData.prototype.updateObservableQuery = function () {
6241
+ if (!this.currentObservable) {
6242
+ this.initializeObservableQuery();
6243
+ return;
6244
+ }
6245
+ var newObservableQueryOptions = tslib.__assign(tslib.__assign({}, this.prepareObservableQueryOptions()), { children: void 0 });
6246
+ if (this.getOptions().skip) {
6247
+ this.previous.observableQueryOptions = newObservableQueryOptions;
6248
+ return;
6249
+ }
6250
+ if (!equality.equal(newObservableQueryOptions, this.previous.observableQueryOptions)) {
6251
+ this.previous.observableQueryOptions = newObservableQueryOptions;
6252
+ this.currentObservable
6253
+ .setOptions(newObservableQueryOptions)
6254
+ .catch(function () { });
6255
+ }
6256
+ };
6257
+ QueryData.prototype.startQuerySubscription = function (onNewData) {
6258
+ var _this = this;
6259
+ if (onNewData === void 0) { onNewData = this.onNewData; }
6260
+ if (this.currentSubscription || this.getOptions().skip)
6261
+ return;
6262
+ this.currentSubscription = this.currentObservable.subscribe({
6263
+ next: function (_a) {
6264
+ var loading = _a.loading, networkStatus = _a.networkStatus, data = _a.data;
6265
+ var previousResult = _this.previous.result;
6266
+ if (previousResult &&
6267
+ previousResult.loading === loading &&
6268
+ previousResult.networkStatus === networkStatus &&
6269
+ equality.equal(previousResult.data, data)) {
6270
+ return;
6271
+ }
6272
+ onNewData();
6273
+ },
6274
+ error: function (error) {
6275
+ _this.resubscribeToQuery();
6276
+ if (!error.hasOwnProperty('graphQLErrors'))
6277
+ throw error;
6278
+ var previousResult = _this.previous.result;
6279
+ if ((previousResult && previousResult.loading) ||
6280
+ !equality.equal(error, _this.previous.error)) {
6281
+ _this.previous.error = error;
6282
+ onNewData();
6283
+ }
6284
+ }
6285
+ });
6286
+ };
6287
+ QueryData.prototype.resubscribeToQuery = function () {
6288
+ this.removeQuerySubscription();
6289
+ var currentObservable = this.currentObservable;
6290
+ if (currentObservable) {
6291
+ var lastError = currentObservable.getLastError();
6292
+ var lastResult = currentObservable.getLastResult();
6293
+ currentObservable.resetLastResults();
6294
+ this.startQuerySubscription();
6295
+ Object.assign(currentObservable, {
6296
+ lastError: lastError,
6297
+ lastResult: lastResult
6298
+ });
6299
+ }
6300
+ };
6301
+ QueryData.prototype.getExecuteResult = function () {
6302
+ var result = this.observableQueryFields();
6303
+ var options = this.getOptions();
6304
+ if (options.skip) {
6305
+ result = tslib.__assign(tslib.__assign({}, result), { data: undefined, error: undefined, loading: false, networkStatus: exports.NetworkStatus.ready, called: true });
6306
+ }
6307
+ else if (this.currentObservable) {
6308
+ var currentResult = this.currentObservable.getCurrentResult();
6309
+ var data = currentResult.data, loading = currentResult.loading, partial = currentResult.partial, networkStatus = currentResult.networkStatus, errors = currentResult.errors;
6310
+ var error = currentResult.error;
6311
+ if (errors && errors.length > 0) {
6312
+ error = new ApolloError({ graphQLErrors: errors });
6313
+ }
6314
+ result = tslib.__assign(tslib.__assign({}, result), { data: data, loading: loading, networkStatus: networkStatus, error: error, called: true });
6315
+ if (loading) ;
6316
+ else if (error) {
6317
+ Object.assign(result, {
6318
+ data: (this.currentObservable.getLastResult() || {})
6319
+ .data
6320
+ });
6321
+ }
6322
+ else {
6323
+ var fetchPolicy = this.currentObservable.options.fetchPolicy;
6324
+ var partialRefetch = options.partialRefetch;
6325
+ if (partialRefetch &&
6326
+ partial &&
6327
+ (!data || Object.keys(data).length === 0) &&
6328
+ fetchPolicy !== 'cache-only') {
6329
+ Object.assign(result, {
6330
+ loading: true,
6331
+ networkStatus: exports.NetworkStatus.loading
6332
+ });
6333
+ result.refetch();
6334
+ return result;
6335
+ }
6336
+ }
6337
+ }
6338
+ result.client = this.client;
6339
+ this.setOptions(options, true);
6340
+ var previousResult = this.previous.result;
6341
+ this.previous.loading =
6342
+ previousResult && previousResult.loading || false;
6343
+ result.previousData = previousResult &&
6344
+ (previousResult.data || previousResult.previousData);
6345
+ this.previous.result = result;
6346
+ this.currentObservable && this.currentObservable.resetQueryStoreErrors();
6347
+ return result;
6348
+ };
6349
+ QueryData.prototype.handleErrorOrCompleted = function () {
6350
+ if (!this.currentObservable || !this.previous.result)
6351
+ return;
6352
+ var _a = this.previous.result, data = _a.data, loading = _a.loading, error = _a.error;
6353
+ if (!loading) {
6354
+ var _b = this.getOptions(), query = _b.query, variables = _b.variables, onCompleted = _b.onCompleted, onError = _b.onError, skip = _b.skip;
6355
+ if (this.previousOptions &&
6356
+ !this.previous.loading &&
6357
+ equality.equal(this.previousOptions.query, query) &&
6358
+ equality.equal(this.previousOptions.variables, variables)) {
6359
+ return;
6360
+ }
6361
+ if (onCompleted && !error && !skip) {
6362
+ onCompleted(data);
6363
+ }
6364
+ else if (onError && error) {
6365
+ onError(error);
6366
+ }
6367
+ }
6368
+ };
6369
+ QueryData.prototype.removeQuerySubscription = function () {
6370
+ if (this.currentSubscription) {
6371
+ this.currentSubscription.unsubscribe();
6372
+ delete this.currentSubscription;
6373
+ }
6374
+ };
6375
+ QueryData.prototype.removeObservable = function (andDelete) {
6376
+ if (this.currentObservable) {
6377
+ this.currentObservable["tearDownQuery"]();
6378
+ if (andDelete) {
6379
+ delete this.currentObservable;
6380
+ }
6381
+ }
6382
+ };
6383
+ QueryData.prototype.observableQueryFields = function () {
6384
+ var _a;
6385
+ return {
6386
+ variables: (_a = this.currentObservable) === null || _a === void 0 ? void 0 : _a.variables,
6387
+ refetch: this.obsRefetch,
6388
+ fetchMore: this.obsFetchMore,
6389
+ updateQuery: this.obsUpdateQuery,
6390
+ startPolling: this.obsStartPolling,
6391
+ stopPolling: this.obsStopPolling,
6392
+ subscribeToMore: this.obsSubscribeToMore
6393
+ };
6394
+ };
6395
+ return QueryData;
6396
+ }(OperationData));
6397
+
6398
+ function useDeepMemo(memoFn, key) {
6399
+ var ref = React.useRef();
6400
+ if (!ref.current || !equality.equal(key, ref.current.key)) {
6401
+ ref.current = { key: key, value: memoFn() };
6402
+ }
6403
+ return ref.current.value;
6404
+ }
6405
+
6406
+ function useAfterFastRefresh(effectFn) {
6407
+ if (__DEV__) {
6408
+ var didRefresh_1 = React.useRef(false);
6409
+ React.useEffect(function () {
6410
+ return function () {
6411
+ didRefresh_1.current = true;
6412
+ };
6413
+ }, []);
6414
+ React.useEffect(function () {
6415
+ if (didRefresh_1.current === true) {
6416
+ didRefresh_1.current = false;
6417
+ effectFn();
6418
+ }
6419
+ }, []);
6420
+ }
6421
+ }
6422
+
6423
+ function useBaseQuery(query, options, lazy) {
6424
+ if (lazy === void 0) { lazy = false; }
6425
+ var context = React.useContext(getApolloContext());
6426
+ var _a = React.useReducer(function (x) { return x + 1; }, 0), tick = _a[0], forceUpdate = _a[1];
6427
+ var updatedOptions = options ? tslib.__assign(tslib.__assign({}, options), { query: query }) : { query: query };
6428
+ var queryDataRef = React.useRef();
6429
+ var queryData = queryDataRef.current || (queryDataRef.current = new QueryData({
6430
+ options: updatedOptions,
6431
+ context: context,
6432
+ onNewData: function () {
6433
+ if (!queryData.ssrInitiated()) {
6434
+ Promise.resolve().then(function () { return queryDataRef.current && queryDataRef.current.isMounted && forceUpdate(); });
6435
+ }
6436
+ else {
6437
+ forceUpdate();
6438
+ }
6439
+ }
6440
+ }));
6441
+ queryData.setOptions(updatedOptions);
6442
+ queryData.context = context;
6443
+ var memo = {
6444
+ options: tslib.__assign(tslib.__assign({}, updatedOptions), { onError: void 0, onCompleted: void 0 }),
6445
+ context: context,
6446
+ tick: tick
6447
+ };
6448
+ var result = useDeepMemo(function () { return (lazy ? queryData.executeLazy() : queryData.execute()); }, memo);
6449
+ var queryResult = lazy
6450
+ ? result[1]
6451
+ : result;
6452
+ if (__DEV__) {
6453
+ useAfterFastRefresh(forceUpdate);
6454
+ }
6455
+ React.useEffect(function () {
6456
+ return function () {
6457
+ queryData.cleanup();
6458
+ queryDataRef.current = void 0;
6459
+ };
6460
+ }, []);
6461
+ React.useEffect(function () { return queryData.afterExecute({ lazy: lazy }); }, [
6462
+ queryResult.loading,
6463
+ queryResult.networkStatus,
6464
+ queryResult.error,
6465
+ queryResult.data,
6466
+ queryData.currentObservable,
6467
+ ]);
6468
+ return result;
6469
+ }
6470
+
6471
+ function useLazyQuery(query, options) {
6472
+ return useBaseQuery(query, options, true);
6473
+ }
6474
+
6475
+ function useMutation(mutation, options) {
6476
+ var context = React.useContext(getApolloContext());
6477
+ var _a = React.useState({ called: false, loading: false }), result = _a[0], setResult = _a[1];
6478
+ var updatedOptions = options ? tslib.__assign(tslib.__assign({}, options), { mutation: mutation }) : { mutation: mutation };
6479
+ var mutationDataRef = React.useRef();
6480
+ function getMutationDataRef() {
6481
+ if (!mutationDataRef.current) {
6482
+ mutationDataRef.current = new MutationData({
6483
+ options: updatedOptions,
6484
+ context: context,
6485
+ result: result,
6486
+ setResult: setResult
6487
+ });
6488
+ }
6489
+ return mutationDataRef.current;
6490
+ }
6491
+ var mutationData = getMutationDataRef();
6492
+ mutationData.setOptions(updatedOptions);
6493
+ mutationData.context = context;
6494
+ React.useEffect(function () { return mutationData.afterExecute(); });
6495
+ return mutationData.execute(result);
6496
+ }
6497
+
6498
+ function useQuery(query, options) {
6499
+ return useBaseQuery(query, options, false);
6500
+ }
6501
+
6502
+ function useSubscription(subscription, options) {
6503
+ var _a = React.useReducer(function (x) { return x + 1; }, 0), forceUpdate = _a[1];
6504
+ var context = React.useContext(getApolloContext());
6505
+ var updatedOptions = options
6506
+ ? tslib.__assign(tslib.__assign({}, options), { subscription: subscription }) : { subscription: subscription };
6507
+ var _b = React.useState({
6508
+ loading: !updatedOptions.skip,
6509
+ error: void 0,
6510
+ data: void 0,
6511
+ }), result = _b[0], setResult = _b[1];
6512
+ var subscriptionDataRef = React.useRef();
6513
+ function getSubscriptionDataRef() {
6514
+ if (!subscriptionDataRef.current) {
6515
+ subscriptionDataRef.current = new SubscriptionData({
6516
+ options: updatedOptions,
6517
+ context: context,
6518
+ setResult: setResult
6519
+ });
6520
+ }
6521
+ return subscriptionDataRef.current;
6522
+ }
6523
+ var subscriptionData = getSubscriptionDataRef();
6524
+ subscriptionData.setOptions(updatedOptions, true);
6525
+ subscriptionData.context = context;
6526
+ if (__DEV__) {
6527
+ useAfterFastRefresh(forceUpdate);
6528
+ }
6529
+ React.useEffect(function () { return subscriptionData.afterExecute(); });
6530
+ React.useEffect(function () {
6531
+ return function () {
6532
+ subscriptionData.cleanup();
6533
+ subscriptionDataRef.current = void 0;
6534
+ };
6535
+ }, []);
6536
+ return subscriptionData.execute(result);
6537
+ }
6538
+
6539
+ function useReactiveVar(rv) {
6540
+ var value = rv();
6541
+ var setValue = React.useState(value)[1];
6542
+ React.useEffect(function () {
6543
+ var probablySameValue = rv();
6544
+ if (value !== probablySameValue) {
6545
+ setValue(probablySameValue);
6546
+ }
6547
+ else {
6548
+ return rv.onNextChange(setValue);
6549
+ }
6550
+ }, [value]);
6551
+ return value;
6552
+ }
5693
6553
 
5694
6554
  exports.setLogVerbosity = tsInvariant.setVerbosity;
5695
6555
  exports.Observable = zenObservableTs.Observable;
@@ -5700,8 +6560,10 @@ exports.gql = graphqlTag.gql;
5700
6560
  exports.resetCaches = graphqlTag.resetCaches;
5701
6561
  exports.ApolloCache = ApolloCache;
5702
6562
  exports.ApolloClient = ApolloClient;
6563
+ exports.ApolloConsumer = ApolloConsumer;
5703
6564
  exports.ApolloError = ApolloError;
5704
6565
  exports.ApolloLink = ApolloLink;
6566
+ exports.ApolloProvider = ApolloProvider;
5705
6567
  exports.HttpLink = HttpLink;
5706
6568
  exports.InMemoryCache = InMemoryCache;
5707
6569
  exports.MissingFieldError = MissingFieldError;
@@ -5718,12 +6580,16 @@ exports.fallbackHttpConfig = fallbackHttpConfig;
5718
6580
  exports.from = from;
5719
6581
  exports.fromError = fromError;
5720
6582
  exports.fromPromise = fromPromise;
6583
+ exports.getApolloContext = getApolloContext;
5721
6584
  exports.isApolloError = isApolloError;
5722
6585
  exports.isReference = isReference;
5723
6586
  exports.makeReference = makeReference;
5724
6587
  exports.makeVar = makeVar;
5725
6588
  exports.mergeOptions = mergeOptions;
6589
+ exports.operationName = operationName;
5726
6590
  exports.parseAndCheckHttpResponse = parseAndCheckHttpResponse;
6591
+ exports.parser = parser;
6592
+ exports.resetApolloContext = getApolloContext;
5727
6593
  exports.rewriteURIForGET = rewriteURIForGET;
5728
6594
  exports.selectHttpOptionsAndBody = selectHttpOptionsAndBody;
5729
6595
  exports.selectURI = selectURI;
@@ -5731,4 +6597,10 @@ exports.serializeFetchParameter = serializeFetchParameter;
5731
6597
  exports.split = split;
5732
6598
  exports.throwServerError = throwServerError;
5733
6599
  exports.toPromise = toPromise;
6600
+ exports.useApolloClient = useApolloClient;
6601
+ exports.useLazyQuery = useLazyQuery;
6602
+ exports.useMutation = useMutation;
6603
+ exports.useQuery = useQuery;
6604
+ exports.useReactiveVar = useReactiveVar;
6605
+ exports.useSubscription = useSubscription;
5734
6606
  //# sourceMappingURL=apollo-client.cjs.js.map