@apollo/client 3.6.3 → 3.6.4

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 (58) hide show
  1. package/apollo-client.cjs +74 -14
  2. package/apollo-client.cjs.map +1 -1
  3. package/apollo-client.min.cjs +1 -1
  4. package/cache/cache.cjs.native.js +2289 -0
  5. package/core/core.cjs +1 -1
  6. package/core/core.cjs.map +1 -1
  7. package/core/core.cjs.native.js +2141 -0
  8. package/errors/errors.cjs.native.js +48 -0
  9. package/invariantErrorCodes.js +1 -1
  10. package/link/batch/batch.cjs.native.js +161 -0
  11. package/link/batch-http/batch-http.cjs.native.js +127 -0
  12. package/link/context/context.cjs.native.js +38 -0
  13. package/link/core/core.cjs.native.js +121 -0
  14. package/link/error/error.cjs.native.js +90 -0
  15. package/link/http/http.cjs.native.js +320 -0
  16. package/link/persisted-queries/persisted-queries.cjs.native.js +174 -0
  17. package/link/retry/retry.cjs.native.js +170 -0
  18. package/link/schema/schema.cjs.native.js +56 -0
  19. package/link/subscriptions/subscriptions.cjs.native.js +45 -0
  20. package/link/utils/utils.cjs.native.js +115 -0
  21. package/link/ws/ws.cjs.native.js +28 -0
  22. package/main.cjs.native.js +16 -0
  23. package/package.json +13 -14
  24. package/react/components/components.cjs.native.js +79 -0
  25. package/react/context/context.cjs.native.js +67 -0
  26. package/react/hoc/hoc.cjs.native.js +325 -0
  27. package/react/hooks/hooks.cjs +99 -31
  28. package/react/hooks/hooks.cjs.map +1 -1
  29. package/react/hooks/hooks.cjs.native.js +604 -0
  30. package/react/hooks/useQuery.js +1 -1
  31. package/react/hooks/useQuery.js.map +1 -1
  32. package/react/hooks/useSubscription.d.ts.map +1 -1
  33. package/react/hooks/useSubscription.js +17 -7
  34. package/react/hooks/useSubscription.js.map +1 -1
  35. package/react/hooks/useSyncExternalStore.d.ts +4 -0
  36. package/react/hooks/useSyncExternalStore.d.ts.map +1 -0
  37. package/react/hooks/useSyncExternalStore.js +48 -0
  38. package/react/hooks/useSyncExternalStore.js.map +1 -0
  39. package/react/parser/parser.cjs.native.js +103 -0
  40. package/react/react.cjs.native.js +22 -0
  41. package/react/ssr/ssr.cjs.native.js +150 -0
  42. package/testing/core/core.cjs.native.js +288 -0
  43. package/testing/testing.cjs.native.js +58 -0
  44. package/utilities/common/canUse.d.ts +2 -0
  45. package/utilities/common/canUse.d.ts.map +1 -1
  46. package/utilities/common/canUse.js +6 -2
  47. package/utilities/common/canUse.js.map +1 -1
  48. package/utilities/globals/globals.cjs.native.js +56 -0
  49. package/utilities/observables/Concast.d.ts.map +1 -1
  50. package/utilities/observables/Concast.js +5 -2
  51. package/utilities/observables/Concast.js.map +1 -1
  52. package/utilities/policies/pagination.d.ts.map +1 -1
  53. package/utilities/policies/pagination.js +9 -7
  54. package/utilities/policies/pagination.js.map +1 -1
  55. package/utilities/utilities.cjs +21 -11
  56. package/utilities/utilities.cjs.map +1 -1
  57. package/utilities/utilities.cjs.native.js +1284 -0
  58. package/version.js +1 -1
package/apollo-client.cjs CHANGED
@@ -13,7 +13,6 @@ var context = require('@wry/context');
13
13
  var trie = require('@wry/trie');
14
14
  var graphqlTag = require('graphql-tag');
15
15
  var React = require('react');
16
- var index_js = require('use-sync-external-store/shim/index.js');
17
16
 
18
17
  function _interopNamespace(e) {
19
18
  if (e && e.__esModule) return e;
@@ -899,11 +898,14 @@ function asyncMap(observable, mapFn, catchFn) {
899
898
  });
900
899
  }
901
900
 
902
- var canUseWeakMap = typeof WeakMap === 'function' && !(typeof navigator === 'object' &&
903
- navigator.product === 'ReactNative');
901
+ var canUseWeakMap = typeof WeakMap === 'function' &&
902
+ maybe(function () { return navigator.product; }) !== 'ReactNative';
904
903
  var canUseWeakSet = typeof WeakSet === 'function';
905
904
  var canUseSymbol = typeof Symbol === 'function' &&
906
905
  typeof Symbol.for === 'function';
906
+ var canUseDOM = typeof maybe(function () { return window.document.createElement; }) === "function";
907
+ var usingJSDOM = maybe(function () { return navigator.userAgent.indexOf("jsdom") >= 0; }) || false;
908
+ var canUseLayoutEffect = canUseDOM && !usingJSDOM;
907
909
 
908
910
  function fixObservableSubclass(subclass) {
909
911
  function set(key) {
@@ -951,9 +953,12 @@ var Concast = (function (_super) {
951
953
  }
952
954
  },
953
955
  complete: function () {
954
- if (_this.sub !== null) {
956
+ var sub = _this.sub;
957
+ if (sub !== null) {
955
958
  var value = _this.sources.shift();
956
959
  if (!value) {
960
+ if (sub)
961
+ setTimeout(function () { return sub.unsubscribe(); });
957
962
  _this.sub = null;
958
963
  if (_this.latest &&
959
964
  _this.latest[0] === "next") {
@@ -1021,7 +1026,7 @@ var Concast = (function (_super) {
1021
1026
  if (this.observers.delete(observer) &&
1022
1027
  --this.addCount < 1 &&
1023
1028
  !quietly) {
1024
- this.handlers.error(new Error("Observable cancelled prematurely"));
1029
+ this.handlers.complete();
1025
1030
  }
1026
1031
  };
1027
1032
  Concast.prototype.cleanup = function (callback) {
@@ -1298,7 +1303,7 @@ var concat = ApolloLink.concat;
1298
1303
 
1299
1304
  var execute = ApolloLink.execute;
1300
1305
 
1301
- var version = '3.6.3';
1306
+ var version = '3.6.4';
1302
1307
 
1303
1308
  var hasOwnProperty$3 = Object.prototype.hasOwnProperty;
1304
1309
  function parseAndCheckHttpResponse(operations) {
@@ -6036,6 +6041,51 @@ function useApolloClient(override) {
6036
6041
  return client;
6037
6042
  }
6038
6043
 
6044
+ var didWarnUncachedGetSnapshot = false;
6045
+ var uSESKey = "useSyncExternalStore";
6046
+ var realHook = React__namespace[uSESKey];
6047
+ var useSyncExternalStore = realHook || (function (subscribe, getSnapshot, getServerSnapshot) {
6048
+ var value = getSnapshot();
6049
+ if (__DEV__ &&
6050
+ !didWarnUncachedGetSnapshot &&
6051
+ value !== getSnapshot()) {
6052
+ didWarnUncachedGetSnapshot = true;
6053
+ __DEV__ && tsInvariant.invariant.error('The result of getSnapshot should be cached to avoid an infinite loop');
6054
+ }
6055
+ var _a = React__namespace.useState({ inst: { value: value, getSnapshot: getSnapshot } }), inst = _a[0].inst, forceUpdate = _a[1];
6056
+ if (canUseLayoutEffect) {
6057
+ React__namespace.useLayoutEffect(function () {
6058
+ Object.assign(inst, { value: value, getSnapshot: getSnapshot });
6059
+ if (checkIfSnapshotChanged(inst)) {
6060
+ forceUpdate({ inst: inst });
6061
+ }
6062
+ }, [subscribe, value, getSnapshot]);
6063
+ }
6064
+ else {
6065
+ Object.assign(inst, { value: value, getSnapshot: getSnapshot });
6066
+ }
6067
+ React__namespace.useEffect(function () {
6068
+ if (checkIfSnapshotChanged(inst)) {
6069
+ forceUpdate({ inst: inst });
6070
+ }
6071
+ return subscribe(function handleStoreChange() {
6072
+ if (checkIfSnapshotChanged(inst)) {
6073
+ forceUpdate({ inst: inst });
6074
+ }
6075
+ });
6076
+ }, [subscribe]);
6077
+ return value;
6078
+ });
6079
+ function checkIfSnapshotChanged(_a) {
6080
+ var value = _a.value, getSnapshot = _a.getSnapshot;
6081
+ try {
6082
+ return value !== getSnapshot();
6083
+ }
6084
+ catch (_b) {
6085
+ return true;
6086
+ }
6087
+ }
6088
+
6039
6089
  exports.DocumentType = void 0;
6040
6090
  (function (DocumentType) {
6041
6091
  DocumentType[DocumentType["Query"] = 0] = "Query";
@@ -6185,7 +6235,7 @@ var InternalState = (function () {
6185
6235
  this.renderPromises = React.useContext(getApolloContext()).renderPromises;
6186
6236
  this.useOptions(options);
6187
6237
  var obsQuery = this.useObservableQuery();
6188
- var result = index_js.useSyncExternalStore(React.useCallback(function () {
6238
+ var result = useSyncExternalStore(React.useCallback(function () {
6189
6239
  if (_this.renderPromises) {
6190
6240
  return function () { };
6191
6241
  }
@@ -6542,6 +6592,12 @@ function useSubscription(subscription, options) {
6542
6592
  context: options === null || options === void 0 ? void 0 : options.context,
6543
6593
  });
6544
6594
  }), observable = _b[0], setObservable = _b[1];
6595
+ var canResetObservableRef = React.useRef(false);
6596
+ React.useEffect(function () {
6597
+ return function () {
6598
+ canResetObservableRef.current = true;
6599
+ };
6600
+ }, []);
6545
6601
  var ref = React.useRef({ client: client, subscription: subscription, options: options });
6546
6602
  React.useEffect(function () {
6547
6603
  var _a, _b, _c, _d;
@@ -6550,7 +6606,7 @@ function useSubscription(subscription, options) {
6550
6606
  shouldResubscribe = !!shouldResubscribe(options);
6551
6607
  }
6552
6608
  if (options === null || options === void 0 ? void 0 : options.skip) {
6553
- if (!(options === null || options === void 0 ? void 0 : options.skip) !== !((_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.skip)) {
6609
+ if (!(options === null || options === void 0 ? void 0 : options.skip) !== !((_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.skip) || canResetObservableRef.current) {
6554
6610
  setResult({
6555
6611
  loading: false,
6556
6612
  data: void 0,
@@ -6558,13 +6614,16 @@ function useSubscription(subscription, options) {
6558
6614
  variables: options === null || options === void 0 ? void 0 : options.variables,
6559
6615
  });
6560
6616
  setObservable(null);
6617
+ canResetObservableRef.current = false;
6561
6618
  }
6562
6619
  }
6563
- else if (shouldResubscribe !== false && (client !== ref.current.client ||
6564
- subscription !== ref.current.subscription ||
6565
- (options === null || options === void 0 ? void 0 : options.fetchPolicy) !== ((_b = ref.current.options) === null || _b === void 0 ? void 0 : _b.fetchPolicy) ||
6566
- !(options === null || options === void 0 ? void 0 : options.skip) !== !((_c = ref.current.options) === null || _c === void 0 ? void 0 : _c.skip) ||
6567
- !equality.equal(options === null || options === void 0 ? void 0 : options.variables, (_d = ref.current.options) === null || _d === void 0 ? void 0 : _d.variables))) {
6620
+ else if ((shouldResubscribe !== false &&
6621
+ (client !== ref.current.client ||
6622
+ subscription !== ref.current.subscription ||
6623
+ (options === null || options === void 0 ? void 0 : options.fetchPolicy) !== ((_b = ref.current.options) === null || _b === void 0 ? void 0 : _b.fetchPolicy) ||
6624
+ !(options === null || options === void 0 ? void 0 : options.skip) !== !((_c = ref.current.options) === null || _c === void 0 ? void 0 : _c.skip) ||
6625
+ !equality.equal(options === null || options === void 0 ? void 0 : options.variables, (_d = ref.current.options) === null || _d === void 0 ? void 0 : _d.variables))) ||
6626
+ canResetObservableRef.current) {
6568
6627
  setResult({
6569
6628
  loading: true,
6570
6629
  data: void 0,
@@ -6577,9 +6636,10 @@ function useSubscription(subscription, options) {
6577
6636
  fetchPolicy: options === null || options === void 0 ? void 0 : options.fetchPolicy,
6578
6637
  context: options === null || options === void 0 ? void 0 : options.context,
6579
6638
  }));
6639
+ canResetObservableRef.current = false;
6580
6640
  }
6581
6641
  Object.assign(ref.current, { client: client, subscription: subscription, options: options });
6582
- }, [client, subscription, options]);
6642
+ }, [client, subscription, options, canResetObservableRef.current]);
6583
6643
  React.useEffect(function () {
6584
6644
  if (!observable) {
6585
6645
  return;