@apollo/client 3.9.0-beta.1 → 3.9.0-rc.1

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 (63) hide show
  1. package/.changeset/pink-apricots-yawn.md +5 -0
  2. package/.changeset/pre.json +3 -1
  3. package/.changeset/six-rocks-arrive.md +5 -0
  4. package/CHANGELOG.md +32 -0
  5. package/apollo-client.cjs +54 -47
  6. package/apollo-client.cjs.map +1 -1
  7. package/apollo-client.min.cjs +1 -1
  8. package/cache/cache.cjs +2 -2
  9. package/cache/cache.cjs.map +1 -1
  10. package/cache/cache.cjs.native.js +2 -2
  11. package/cache/inmemory/readFromStore.js +2 -2
  12. package/cache/inmemory/readFromStore.js.map +1 -1
  13. package/cache/inmemory/writeToStore.js.map +1 -1
  14. package/core/core.cjs +3 -3
  15. package/core/core.cjs.map +1 -1
  16. package/core/core.cjs.native.js +3 -3
  17. package/dev/dev.cjs +2 -2
  18. package/dev/dev.cjs.map +1 -1
  19. package/dev/dev.cjs.native.js +2 -2
  20. package/invariantErrorCodes.js +1 -1
  21. package/link/http/checkFetcher.d.ts +1 -1
  22. package/link/http/checkFetcher.js.map +1 -1
  23. package/link/http/http.cjs +0 -3
  24. package/link/http/http.cjs.map +1 -1
  25. package/link/http/http.cjs.native.js +0 -3
  26. package/link/http/parseAndCheckHttpResponse.js +0 -4
  27. package/link/http/parseAndCheckHttpResponse.js.map +1 -1
  28. package/link/http/selectHttpOptionsAndBody.d.ts +1 -1
  29. package/link/http/selectHttpOptionsAndBody.js.map +1 -1
  30. package/package.json +25 -25
  31. package/react/hooks/hooks.cjs +47 -38
  32. package/react/hooks/hooks.cjs.map +1 -1
  33. package/react/hooks/hooks.cjs.native.js +47 -38
  34. package/react/hooks/internal/index.d.ts +1 -0
  35. package/react/hooks/internal/index.js +1 -0
  36. package/react/hooks/internal/index.js.map +1 -1
  37. package/react/hooks/internal/useLazyRef.d.ts +3 -0
  38. package/react/hooks/internal/useLazyRef.js +10 -0
  39. package/react/hooks/internal/useLazyRef.js.map +1 -0
  40. package/react/hooks/useFragment.js +20 -17
  41. package/react/hooks/useFragment.js.map +1 -1
  42. package/react/internal/cache/QueryReference.js +2 -1
  43. package/react/internal/cache/QueryReference.js.map +1 -1
  44. package/react/internal/internal.cjs +2 -1
  45. package/react/internal/internal.cjs.map +1 -1
  46. package/react/internal/internal.cjs.native.js +2 -1
  47. package/react/parser/parser.cjs.map +1 -1
  48. package/testing/core/core.cjs +5 -3
  49. package/testing/core/core.cjs.map +1 -1
  50. package/testing/core/core.cjs.native.js +5 -3
  51. package/testing/core/mocking/mockLink.js +9 -3
  52. package/testing/core/mocking/mockLink.js.map +1 -1
  53. package/utilities/caching/getMemoryInternals.js +2 -2
  54. package/utilities/caching/getMemoryInternals.js.map +1 -1
  55. package/utilities/caching/sizes.d.ts +2 -2
  56. package/utilities/caching/sizes.js.map +1 -1
  57. package/utilities/globals/globals.cjs +1 -1
  58. package/utilities/globals/globals.cjs.map +1 -1
  59. package/utilities/globals/globals.cjs.native.js +1 -1
  60. package/utilities/subscriptions/relay/relay.cjs.map +1 -1
  61. package/utilities/subscriptions/urql/urql.cjs.map +1 -1
  62. package/utilities/utilities.cjs.map +1 -1
  63. package/version.js +1 -1
@@ -11,6 +11,7 @@ var equality = require('@wry/equality');
11
11
  var errors = require('../../errors');
12
12
  var core = require('../../core');
13
13
  var parser = require('../parser');
14
+ var React$1 = require('react');
14
15
  var internal = require('../internal');
15
16
  var cache = require('../../cache');
16
17
 
@@ -27,6 +28,7 @@ function _interopNamespace(e) {
27
28
  }
28
29
 
29
30
  var React__namespace = /*#__PURE__*/_interopNamespace(React);
31
+ var React__namespace$1 = /*#__PURE__*/_interopNamespace(React$1);
30
32
 
31
33
  function useApolloClient(override) {
32
34
  var context$1 = React__namespace.useContext(context.getApolloContext());
@@ -691,44 +693,6 @@ function useReactiveVar(rv) {
691
693
  }, [rv]), rv, rv);
692
694
  }
693
695
 
694
- function useFragment(options) {
695
- var cache = useApolloClient().cache;
696
- var fragment = options.fragment, fragmentName = options.fragmentName, from = options.from, _a = options.optimistic, optimistic = _a === void 0 ? true : _a, rest = tslib.__rest(options, ["fragment", "fragmentName", "from", "optimistic"]);
697
- var diffOptions = tslib.__assign(tslib.__assign({}, rest), { returnPartialData: true, id: typeof from === "string" ? from : cache.identify(from), query: cache["getFragmentDoc"](fragment, fragmentName), optimistic: optimistic });
698
- var resultRef = React__namespace.useRef();
699
- var latestDiff = cache.diff(diffOptions);
700
- var getSnapshot = function () {
701
- var latestDiffToResult = diffToResult(latestDiff);
702
- return (resultRef.current &&
703
- equality.equal(resultRef.current.data, latestDiffToResult.data)) ?
704
- resultRef.current
705
- : (resultRef.current = latestDiffToResult);
706
- };
707
- return useSyncExternalStore(function (forceUpdate) {
708
- var lastTimeout = 0;
709
- var unsubcribe = cache.watch(tslib.__assign(tslib.__assign({}, diffOptions), { immediate: true, callback: function (diff) {
710
- if (!equality.equal(diff, latestDiff)) {
711
- resultRef.current = diffToResult((latestDiff = diff));
712
- lastTimeout = setTimeout(forceUpdate);
713
- }
714
- } }));
715
- return function () {
716
- unsubcribe();
717
- clearTimeout(lastTimeout);
718
- };
719
- }, getSnapshot, getSnapshot);
720
- }
721
- function diffToResult(diff) {
722
- var result = {
723
- data: diff.result,
724
- complete: !!diff.complete,
725
- };
726
- if (diff.missing) {
727
- result.missing = utilities.mergeDeepArray(diff.missing.map(function (error) { return error.missing; }));
728
- }
729
- return result;
730
- }
731
-
732
696
  function useDeepMemo(memoFn, deps) {
733
697
  var ref = React__namespace.useRef();
734
698
  if (!ref.current || !equality.equal(ref.current.deps, deps)) {
@@ -749,6 +713,15 @@ function useRenderGuard() {
749
713
  }, []);
750
714
  }
751
715
 
716
+ var INIT = {};
717
+ function useLazyRef(getInitialValue) {
718
+ var ref = React__namespace$1.useRef(INIT);
719
+ if (ref.current === INIT) {
720
+ ref.current = getInitialValue();
721
+ }
722
+ return ref;
723
+ }
724
+
752
725
  var useKey = "use";
753
726
  var realHook = React__namespace[useKey];
754
727
  var __use = realHook ||
@@ -764,6 +737,42 @@ var __use = realHook ||
764
737
  }
765
738
  };
766
739
 
740
+ function useFragment(options) {
741
+ var cache = useApolloClient().cache;
742
+ var diffOptions = useDeepMemo(function () {
743
+ var fragment = options.fragment, fragmentName = options.fragmentName, from = options.from, _a = options.optimistic, optimistic = _a === void 0 ? true : _a, rest = tslib.__rest(options, ["fragment", "fragmentName", "from", "optimistic"]);
744
+ return tslib.__assign(tslib.__assign({}, rest), { returnPartialData: true, id: typeof from === "string" ? from : cache.identify(from), query: cache["getFragmentDoc"](fragment, fragmentName), optimistic: optimistic });
745
+ }, [options]);
746
+ var resultRef = useLazyRef(function () {
747
+ return diffToResult(cache.diff(diffOptions));
748
+ });
749
+ var getSnapshot = React__namespace.useCallback(function () { return resultRef.current; }, []);
750
+ return useSyncExternalStore(React__namespace.useCallback(function (forceUpdate) {
751
+ var lastTimeout = 0;
752
+ var unsubscribe = cache.watch(tslib.__assign(tslib.__assign({}, diffOptions), { immediate: true, callback: function (diff) {
753
+ if (!equality.equal(diff.result, resultRef.current.data)) {
754
+ resultRef.current = diffToResult(diff);
755
+ clearTimeout(lastTimeout);
756
+ lastTimeout = setTimeout(forceUpdate);
757
+ }
758
+ } }));
759
+ return function () {
760
+ unsubscribe();
761
+ clearTimeout(lastTimeout);
762
+ };
763
+ }, [cache, diffOptions]), getSnapshot, getSnapshot);
764
+ }
765
+ function diffToResult(diff) {
766
+ var result = {
767
+ data: diff.result,
768
+ complete: !!diff.complete,
769
+ };
770
+ if (diff.missing) {
771
+ result.missing = utilities.mergeDeepArray(diff.missing.map(function (error) { return error.missing; }));
772
+ }
773
+ return result;
774
+ }
775
+
767
776
  var skipToken = Symbol.for("apollo.skipToken");
768
777
 
769
778
  function useSuspenseQuery(query, options) {