@apollo/client 3.9.6 → 3.10.0-alpha.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.
- package/.changeset/flat-singers-kiss.md +5 -0
- package/.changeset/pre.json +11 -0
- package/.changeset/tasty-pillows-ring.md +5 -0
- package/CHANGELOG.md +20 -0
- package/apollo-client.cjs +78 -39
- package/apollo-client.cjs.map +1 -1
- package/apollo-client.min.cjs +1 -1
- package/cache/cache.cjs +27 -0
- package/cache/cache.cjs.map +1 -1
- package/cache/cache.cjs.native.js +27 -0
- package/cache/core/cache.d.ts +83 -1
- package/cache/core/cache.js +30 -1
- package/cache/core/cache.js.map +1 -1
- package/core/ApolloClient.d.ts +26 -8
- package/core/ApolloClient.js +26 -7
- package/core/ApolloClient.js.map +1 -1
- package/core/LocalState.js +13 -13
- package/core/LocalState.js.map +1 -1
- package/core/QueryManager.js +7 -7
- package/core/QueryManager.js.map +1 -1
- package/core/core.cjs +24 -21
- package/core/core.cjs.map +1 -1
- package/core/core.cjs.native.js +24 -21
- package/core/watchQueryOptions.d.ts +3 -3
- package/dev/dev.cjs +1 -1
- package/dev/dev.cjs.map +1 -1
- package/dev/dev.cjs.native.js +1 -1
- package/link/http/http.cjs +11 -8
- package/link/http/http.cjs.map +1 -1
- package/link/http/http.cjs.native.js +11 -8
- package/link/http/parseAndCheckHttpResponse.js +11 -8
- package/link/http/parseAndCheckHttpResponse.js.map +1 -1
- package/package.json +24 -24
- package/react/hooks/hooks.cjs +27 -18
- package/react/hooks/hooks.cjs.map +1 -1
- package/react/hooks/hooks.cjs.native.js +27 -18
- package/react/hooks/internal/useRenderGuard.js +1 -1
- package/react/hooks/internal/useRenderGuard.js.map +1 -1
- package/react/hooks/useFragment.d.ts +1 -1
- package/react/hooks/useFragment.js +22 -14
- package/react/hooks/useFragment.js.map +1 -1
- package/react/internal/cache/QueryReference.d.ts +2 -2
- package/react/internal/cache/QueryReference.js.map +1 -1
- package/react/query-preloader/createQueryPreloader.d.ts +6 -6
- package/react/query-preloader/createQueryPreloader.js.map +1 -1
- package/react/types/types.d.ts +3 -3
- package/react/types/types.documentation.d.ts +4 -4
- package/react/types/types.documentation.js.map +1 -1
- package/testing/internal/ObservableStream.js +3 -3
- package/testing/internal/ObservableStream.js.map +1 -1
- package/testing/internal/profile/profile.js +6 -6
- package/testing/internal/profile/profile.js.map +1 -1
- package/utilities/globals/globals.cjs +1 -1
- package/utilities/globals/globals.cjs.map +1 -1
- package/utilities/globals/globals.cjs.native.js +1 -1
- package/utilities/subscriptions/relay/relay.cjs +11 -8
- package/utilities/subscriptions/relay/relay.cjs.map +1 -1
- package/utilities/subscriptions/relay/relay.cjs.native.js +11 -8
- package/utilities/subscriptions/urql/urql.cjs +11 -8
- package/utilities/subscriptions/urql/urql.cjs.map +1 -1
- package/utilities/subscriptions/urql/urql.cjs.native.js +11 -8
- package/version.js +1 -1
package/react/hooks/hooks.cjs
CHANGED
|
@@ -7,13 +7,15 @@ var React = require('rehackt');
|
|
|
7
7
|
var context = require('../context');
|
|
8
8
|
var tslib = require('tslib');
|
|
9
9
|
var utilities = require('../../utilities');
|
|
10
|
-
var
|
|
10
|
+
var equal = require('@wry/equality');
|
|
11
11
|
var errors = require('../../errors');
|
|
12
12
|
var core = require('../../core');
|
|
13
13
|
var parser = require('../parser');
|
|
14
14
|
var internal = require('../internal');
|
|
15
15
|
var cache = require('../../cache');
|
|
16
16
|
|
|
17
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
|
|
18
|
+
|
|
17
19
|
function _interopNamespace(e) {
|
|
18
20
|
if (e && e.__esModule) return e;
|
|
19
21
|
var n = Object.create(null);
|
|
@@ -27,6 +29,7 @@ function _interopNamespace(e) {
|
|
|
27
29
|
}
|
|
28
30
|
|
|
29
31
|
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
32
|
+
var equal__default = /*#__PURE__*/_interopDefaultLegacy(equal);
|
|
30
33
|
|
|
31
34
|
function useApolloClient(override) {
|
|
32
35
|
var context$1 = React__namespace.useContext(context.getApolloContext());
|
|
@@ -86,7 +89,7 @@ function checkIfSnapshotChanged(_a) {
|
|
|
86
89
|
|
|
87
90
|
function useDeepMemo(memoFn, deps) {
|
|
88
91
|
var ref = React__namespace.useRef();
|
|
89
|
-
if (!ref.current || !
|
|
92
|
+
if (!ref.current || !equal.equal(ref.current.deps, deps)) {
|
|
90
93
|
ref.current = { value: memoFn(), deps: deps };
|
|
91
94
|
}
|
|
92
95
|
return ref.current.value;
|
|
@@ -100,7 +103,7 @@ var RenderDispatcher = null;
|
|
|
100
103
|
function useRenderGuard() {
|
|
101
104
|
RenderDispatcher = getRenderDispatcher();
|
|
102
105
|
return React__namespace.useCallback(function () {
|
|
103
|
-
return (RenderDispatcher
|
|
106
|
+
return (RenderDispatcher != null && RenderDispatcher === getRenderDispatcher());
|
|
104
107
|
}, []);
|
|
105
108
|
}
|
|
106
109
|
|
|
@@ -226,7 +229,7 @@ var InternalState = (function () {
|
|
|
226
229
|
if (previousResult &&
|
|
227
230
|
previousResult.loading === result.loading &&
|
|
228
231
|
previousResult.networkStatus === result.networkStatus &&
|
|
229
|
-
|
|
232
|
+
equal.equal(previousResult.data, result.data)) {
|
|
230
233
|
return;
|
|
231
234
|
}
|
|
232
235
|
_this.setResult(result);
|
|
@@ -240,7 +243,7 @@ var InternalState = (function () {
|
|
|
240
243
|
var previousResult = _this.result;
|
|
241
244
|
if (!previousResult ||
|
|
242
245
|
(previousResult && previousResult.loading) ||
|
|
243
|
-
!
|
|
246
|
+
!equal.equal(error, previousResult.error)) {
|
|
244
247
|
_this.setResult({
|
|
245
248
|
data: (previousResult && previousResult.data),
|
|
246
249
|
error: error,
|
|
@@ -266,7 +269,7 @@ var InternalState = (function () {
|
|
|
266
269
|
var _a;
|
|
267
270
|
var watchQueryOptions = this.createWatchQueryOptions((this.queryHookOptions = options));
|
|
268
271
|
var currentWatchQueryOptions = this.watchQueryOptions;
|
|
269
|
-
if (!
|
|
272
|
+
if (!equal.equal(watchQueryOptions, currentWatchQueryOptions)) {
|
|
270
273
|
this.watchQueryOptions = watchQueryOptions;
|
|
271
274
|
if (currentWatchQueryOptions && this.observable) {
|
|
272
275
|
this.observable.reobserve(this.getObsQueryOptions());
|
|
@@ -545,7 +548,7 @@ function useMutation(mutation, options) {
|
|
|
545
548
|
error: error,
|
|
546
549
|
client: client,
|
|
547
550
|
};
|
|
548
|
-
if (ref.current.isMounted && !
|
|
551
|
+
if (ref.current.isMounted && !equal.equal(ref.current.result, result_1)) {
|
|
549
552
|
setResult((ref.current.result = result_1));
|
|
550
553
|
}
|
|
551
554
|
}
|
|
@@ -565,7 +568,7 @@ function useMutation(mutation, options) {
|
|
|
565
568
|
called: true,
|
|
566
569
|
client: client,
|
|
567
570
|
};
|
|
568
|
-
if (!
|
|
571
|
+
if (!equal.equal(ref.current.result, result_2)) {
|
|
569
572
|
setResult((ref.current.result = result_2));
|
|
570
573
|
}
|
|
571
574
|
}
|
|
@@ -654,7 +657,7 @@ function useSubscription(subscription, options) {
|
|
|
654
657
|
subscription !== ref.current.subscription ||
|
|
655
658
|
(options === null || options === void 0 ? void 0 : options.fetchPolicy) !== ((_b = ref.current.options) === null || _b === void 0 ? void 0 : _b.fetchPolicy) ||
|
|
656
659
|
!(options === null || options === void 0 ? void 0 : options.skip) !== !((_c = ref.current.options) === null || _c === void 0 ? void 0 : _c.skip) ||
|
|
657
|
-
!
|
|
660
|
+
!equal.equal(options === null || options === void 0 ? void 0 : options.variables, (_d = ref.current.options) === null || _d === void 0 ? void 0 : _d.variables))) ||
|
|
658
661
|
canResetObservableRef.current) {
|
|
659
662
|
setResult({
|
|
660
663
|
loading: true,
|
|
@@ -758,21 +761,27 @@ function _useFragment(options) {
|
|
|
758
761
|
var resultRef = useLazyRef(function () {
|
|
759
762
|
return diffToResult(cache.diff(diffOptions));
|
|
760
763
|
});
|
|
764
|
+
var stableOptions = useDeepMemo(function () { return options; }, [options]);
|
|
765
|
+
React__namespace.useMemo(function () {
|
|
766
|
+
resultRef.current = diffToResult(cache.diff(diffOptions));
|
|
767
|
+
}, [diffOptions, cache]);
|
|
761
768
|
var getSnapshot = React__namespace.useCallback(function () { return resultRef.current; }, []);
|
|
762
769
|
return useSyncExternalStore(React__namespace.useCallback(function (forceUpdate) {
|
|
763
770
|
var lastTimeout = 0;
|
|
764
|
-
var
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
+
var subscription = cache.watchFragment(stableOptions).subscribe({
|
|
772
|
+
next: function (result) {
|
|
773
|
+
if (equal__default(result, resultRef.current))
|
|
774
|
+
return;
|
|
775
|
+
resultRef.current = result;
|
|
776
|
+
clearTimeout(lastTimeout);
|
|
777
|
+
lastTimeout = setTimeout(forceUpdate);
|
|
778
|
+
},
|
|
779
|
+
});
|
|
771
780
|
return function () {
|
|
772
|
-
unsubscribe();
|
|
781
|
+
subscription.unsubscribe();
|
|
773
782
|
clearTimeout(lastTimeout);
|
|
774
783
|
};
|
|
775
|
-
}, [cache,
|
|
784
|
+
}, [cache, stableOptions]), getSnapshot, getSnapshot);
|
|
776
785
|
}
|
|
777
786
|
function diffToResult(diff) {
|
|
778
787
|
var result = {
|