@apollo/client 3.8.0-beta.3 → 3.8.0-beta.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.
- package/apollo-client.cjs +64 -13
- package/apollo-client.cjs.map +1 -1
- package/apollo-client.min.cjs +1 -1
- package/core/core.cjs +1 -1
- package/core/core.cjs.map +1 -1
- package/core/core.cjs.native.js +1 -1
- package/dev/dev.cjs +1 -1
- package/dev/dev.cjs.map +1 -1
- package/dev/dev.cjs.native.js +1 -1
- package/link/batch-http/batchHttpLink.d.ts +1 -1
- package/link/batch-http/batchHttpLink.d.ts.map +1 -1
- package/link/batch-http/batchHttpLink.js.map +1 -1
- package/link/persisted-queries/index.d.ts +10 -4
- package/link/persisted-queries/index.d.ts.map +1 -1
- package/link/persisted-queries/index.js +25 -28
- package/link/persisted-queries/index.js.map +1 -1
- package/link/persisted-queries/persisted-queries.cjs +24 -27
- package/link/persisted-queries/persisted-queries.cjs.map +1 -1
- package/link/persisted-queries/persisted-queries.cjs.native.js +24 -27
- package/package.json +1 -1
- package/react/cache/QueryReference.d.ts +3 -1
- package/react/cache/QueryReference.d.ts.map +1 -1
- package/react/cache/QueryReference.js +12 -0
- package/react/cache/QueryReference.js.map +1 -1
- package/react/hooks/hooks.cjs +51 -12
- package/react/hooks/hooks.cjs.map +1 -1
- package/react/hooks/hooks.cjs.native.js +51 -12
- package/react/hooks/useBackgroundQuery.d.ts +6 -2
- package/react/hooks/useBackgroundQuery.d.ts.map +1 -1
- package/react/hooks/useBackgroundQuery.js +20 -3
- package/react/hooks/useBackgroundQuery.js.map +1 -1
- package/react/hooks/useSuspenseQuery.d.ts +12 -4
- package/react/hooks/useSuspenseQuery.d.ts.map +1 -1
- package/react/hooks/useSuspenseQuery.js +33 -10
- package/react/hooks/useSuspenseQuery.js.map +1 -1
- package/react/react.cjs +12 -0
- package/react/react.cjs.map +1 -1
- package/react/react.cjs.native.js +12 -0
- package/react/types/types.d.ts +1 -1
- package/react/types/types.d.ts.map +1 -1
- package/react/types/types.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/policies/pagination.d.ts.map +1 -1
- package/utilities/policies/pagination.js +3 -0
- package/utilities/policies/pagination.js.map +1 -1
- package/utilities/utilities.cjs +3 -0
- package/utilities/utilities.cjs.map +1 -1
- package/utilities/utilities.cjs.native.js +3 -0
- package/version.js +1 -1
package/apollo-client.cjs
CHANGED
|
@@ -33,7 +33,7 @@ var equal__default = /*#__PURE__*/_interopDefaultLegacy(equal);
|
|
|
33
33
|
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
34
34
|
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
35
35
|
|
|
36
|
-
var version = '3.8.0-beta.
|
|
36
|
+
var version = '3.8.0-beta.4';
|
|
37
37
|
|
|
38
38
|
function maybe(thunk) {
|
|
39
39
|
try {
|
|
@@ -7667,15 +7667,20 @@ function useSuspenseQuery(query, options) {
|
|
|
7667
7667
|
if (options === void 0) { options = Object.create(null); }
|
|
7668
7668
|
var client = useApolloClient(options.client);
|
|
7669
7669
|
var suspenseCache = useSuspenseCache(options.suspenseCache);
|
|
7670
|
-
var watchQueryOptions = useWatchQueryOptions({ query: query, options: options });
|
|
7671
|
-
var variables = watchQueryOptions.variables;
|
|
7670
|
+
var watchQueryOptions = useWatchQueryOptions({ client: client, query: query, options: options });
|
|
7671
|
+
var fetchPolicy = watchQueryOptions.fetchPolicy, variables = watchQueryOptions.variables;
|
|
7672
7672
|
var _a = options.queryKey, queryKey = _a === void 0 ? [] : _a;
|
|
7673
7673
|
var cacheKey = [client, query, canonicalStringify(variables)].concat(queryKey);
|
|
7674
7674
|
var queryRef = suspenseCache.getQueryRef(cacheKey, function () {
|
|
7675
7675
|
return client.watchQuery(watchQueryOptions);
|
|
7676
7676
|
});
|
|
7677
|
+
var currentFetchPolicy = queryRef.watchQueryOptions.fetchPolicy;
|
|
7677
7678
|
var _b = React.useState(function () { return new Map([[queryRef.key, queryRef.promise]]); }), promiseCache = _b[0], setPromiseCache = _b[1];
|
|
7678
7679
|
var promise = promiseCache.get(queryRef.key);
|
|
7680
|
+
if (currentFetchPolicy === 'standby' && fetchPolicy !== currentFetchPolicy) {
|
|
7681
|
+
promise = queryRef.reobserve({ fetchPolicy: fetchPolicy });
|
|
7682
|
+
promiseCache.set(queryRef.key, promise);
|
|
7683
|
+
}
|
|
7679
7684
|
if (!promise) {
|
|
7680
7685
|
promise = queryRef.promise;
|
|
7681
7686
|
promiseCache.set(queryRef.key, promise);
|
|
@@ -7688,7 +7693,16 @@ function useSuspenseQuery(query, options) {
|
|
|
7688
7693
|
});
|
|
7689
7694
|
});
|
|
7690
7695
|
}, [queryRef]);
|
|
7691
|
-
var
|
|
7696
|
+
var skipResult = React.useMemo(function () {
|
|
7697
|
+
var error = toApolloError(queryRef.result);
|
|
7698
|
+
return {
|
|
7699
|
+
loading: false,
|
|
7700
|
+
data: queryRef.result.data,
|
|
7701
|
+
networkStatus: error ? exports.NetworkStatus.error : exports.NetworkStatus.ready,
|
|
7702
|
+
error: error,
|
|
7703
|
+
};
|
|
7704
|
+
}, [queryRef.result]);
|
|
7705
|
+
var result = watchQueryOptions.fetchPolicy === 'standby' ? skipResult : __use(promise);
|
|
7692
7706
|
var fetchMore = React.useCallback(function (options) {
|
|
7693
7707
|
var promise = queryRef.fetchMore(options);
|
|
7694
7708
|
setPromiseCache(function (previousPromiseCache) {
|
|
@@ -7750,26 +7764,40 @@ function useTrackedQueryRefs(queryRef) {
|
|
|
7750
7764
|
});
|
|
7751
7765
|
}
|
|
7752
7766
|
function useWatchQueryOptions(_a) {
|
|
7753
|
-
var query = _a.query, options = _a.options;
|
|
7754
|
-
|
|
7755
|
-
|
|
7756
|
-
|
|
7757
|
-
|
|
7758
|
-
|
|
7767
|
+
var client = _a.client, query = _a.query, options = _a.options;
|
|
7768
|
+
return useDeepMemo(function () {
|
|
7769
|
+
var _a;
|
|
7770
|
+
var fetchPolicy = options.fetchPolicy ||
|
|
7771
|
+
((_a = client.defaultOptions.watchQuery) === null || _a === void 0 ? void 0 : _a.fetchPolicy) ||
|
|
7772
|
+
'cache-first';
|
|
7773
|
+
var watchQueryOptions = tslib.__assign(tslib.__assign({}, options), { fetchPolicy: fetchPolicy, query: query, notifyOnNetworkStatusChange: false, nextFetchPolicy: void 0 });
|
|
7774
|
+
if (__DEV__) {
|
|
7775
|
+
validateOptions(watchQueryOptions);
|
|
7776
|
+
}
|
|
7777
|
+
if (options.skip) {
|
|
7778
|
+
watchQueryOptions.fetchPolicy = 'standby';
|
|
7779
|
+
}
|
|
7780
|
+
return watchQueryOptions;
|
|
7781
|
+
}, [client, options, query]);
|
|
7759
7782
|
}
|
|
7760
7783
|
|
|
7761
7784
|
function useBackgroundQuery(query, options) {
|
|
7762
7785
|
if (options === void 0) { options = Object.create(null); }
|
|
7763
7786
|
var suspenseCache = useSuspenseCache(options.suspenseCache);
|
|
7764
7787
|
var client = useApolloClient(options.client);
|
|
7765
|
-
var watchQueryOptions = useWatchQueryOptions({ query: query, options: options });
|
|
7766
|
-
var variables = watchQueryOptions.variables;
|
|
7788
|
+
var watchQueryOptions = useWatchQueryOptions({ client: client, query: query, options: options });
|
|
7789
|
+
var fetchPolicy = watchQueryOptions.fetchPolicy, variables = watchQueryOptions.variables;
|
|
7767
7790
|
var _a = options.queryKey, queryKey = _a === void 0 ? [] : _a;
|
|
7768
7791
|
var cacheKey = [client, query, canonicalStringify(variables)].concat(queryKey);
|
|
7769
7792
|
var queryRef = suspenseCache.getQueryRef(cacheKey, function () {
|
|
7770
7793
|
return client.watchQuery(watchQueryOptions);
|
|
7771
7794
|
});
|
|
7795
|
+
var currentFetchPolicy = queryRef.watchQueryOptions.fetchPolicy;
|
|
7772
7796
|
var _b = React.useState(function () { return new Map([[queryRef.key, queryRef.promise]]); }), promiseCache = _b[0], setPromiseCache = _b[1];
|
|
7797
|
+
if (currentFetchPolicy === 'standby' && fetchPolicy !== currentFetchPolicy) {
|
|
7798
|
+
var promise = queryRef.reobserve({ fetchPolicy: fetchPolicy });
|
|
7799
|
+
promiseCache.set(queryRef.key, promise);
|
|
7800
|
+
}
|
|
7773
7801
|
useTrackedQueryRefs(queryRef);
|
|
7774
7802
|
var fetchMore = React.useCallback(function (options) {
|
|
7775
7803
|
var promise = queryRef.fetchMore(options);
|
|
@@ -7799,6 +7827,15 @@ function useBackgroundQuery(query, options) {
|
|
|
7799
7827
|
function useReadQuery(queryRef) {
|
|
7800
7828
|
var _a = React.useState(0), forceUpdate = _a[1];
|
|
7801
7829
|
invariant(queryRef.promiseCache, 49);
|
|
7830
|
+
var skipResult = React.useMemo(function () {
|
|
7831
|
+
var error = toApolloError(queryRef.result);
|
|
7832
|
+
return {
|
|
7833
|
+
loading: false,
|
|
7834
|
+
data: queryRef.result.data,
|
|
7835
|
+
networkStatus: error ? exports.NetworkStatus.error : exports.NetworkStatus.ready,
|
|
7836
|
+
error: error,
|
|
7837
|
+
};
|
|
7838
|
+
}, [queryRef.result]);
|
|
7802
7839
|
var promise = queryRef.promiseCache.get(queryRef.key);
|
|
7803
7840
|
if (!promise) {
|
|
7804
7841
|
promise = queryRef.promise;
|
|
@@ -7810,7 +7847,9 @@ function useReadQuery(queryRef) {
|
|
|
7810
7847
|
forceUpdate(function (prevState) { return prevState + 1; });
|
|
7811
7848
|
});
|
|
7812
7849
|
}, [queryRef]);
|
|
7813
|
-
var result =
|
|
7850
|
+
var result = queryRef.watchQueryOptions.fetchPolicy === 'standby'
|
|
7851
|
+
? skipResult
|
|
7852
|
+
: __use(promise);
|
|
7814
7853
|
return React.useMemo(function () {
|
|
7815
7854
|
return {
|
|
7816
7855
|
data: result.data,
|
|
@@ -7856,6 +7895,13 @@ var QueryReference = (function () {
|
|
|
7856
7895
|
}
|
|
7857
7896
|
this.autoDisposeTimeoutId = setTimeout(this.dispose, (_a = options.autoDisposeTimeoutMs) !== null && _a !== void 0 ? _a : 30000);
|
|
7858
7897
|
}
|
|
7898
|
+
Object.defineProperty(QueryReference.prototype, "watchQueryOptions", {
|
|
7899
|
+
get: function () {
|
|
7900
|
+
return this.observable.options;
|
|
7901
|
+
},
|
|
7902
|
+
enumerable: false,
|
|
7903
|
+
configurable: true
|
|
7904
|
+
});
|
|
7859
7905
|
QueryReference.prototype.listen = function (listener) {
|
|
7860
7906
|
var _this = this;
|
|
7861
7907
|
clearTimeout(this.autoDisposeTimeoutId);
|
|
@@ -7875,6 +7921,11 @@ var QueryReference = (function () {
|
|
|
7875
7921
|
this.promise = promise;
|
|
7876
7922
|
return promise;
|
|
7877
7923
|
};
|
|
7924
|
+
QueryReference.prototype.reobserve = function (watchQueryOptions) {
|
|
7925
|
+
var promise = this.observable.reobserve(watchQueryOptions);
|
|
7926
|
+
this.promise = promise;
|
|
7927
|
+
return promise;
|
|
7928
|
+
};
|
|
7878
7929
|
QueryReference.prototype.dispose = function () {
|
|
7879
7930
|
this.subscription.unsubscribe();
|
|
7880
7931
|
this.onDispose();
|