@apollo/client 3.8.0-beta.2 → 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 +95 -31
- package/apollo-client.cjs.map +1 -1
- package/apollo-client.min.cjs +1 -1
- package/cache/cache.cjs.map +1 -1
- package/cache/core/cache.d.ts +1 -1
- package/cache/core/cache.d.ts.map +1 -1
- package/cache/core/cache.js.map +1 -1
- package/cache/core/types/Cache.d.ts +3 -3
- package/cache/core/types/Cache.d.ts.map +1 -1
- package/cache/core/types/Cache.js +1 -0
- package/cache/core/types/Cache.js.map +1 -1
- package/cache/core/types/common.d.ts +17 -6
- package/cache/core/types/common.d.ts.map +1 -1
- package/cache/core/types/common.js.map +1 -1
- package/cache/inmemory/entityStore.d.ts +1 -1
- package/cache/inmemory/entityStore.d.ts.map +1 -1
- package/cache/inmemory/entityStore.js.map +1 -1
- package/cache/inmemory/inMemoryCache.d.ts +1 -1
- package/cache/inmemory/inMemoryCache.d.ts.map +1 -1
- package/cache/inmemory/inMemoryCache.js.map +1 -1
- package/cache/inmemory/types.d.ts +2 -2
- package/cache/inmemory/types.d.ts.map +1 -1
- package/cache/inmemory/types.js.map +1 -1
- package/core/QueryManager.d.ts.map +1 -1
- package/core/QueryManager.js +5 -3
- package/core/QueryManager.js.map +1 -1
- package/core/core.cjs +5 -4
- package/core/core.cjs.map +1 -1
- package/core/core.cjs.native.js +5 -4
- 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/batch-http.cjs +5 -4
- package/link/batch-http/batch-http.cjs.map +1 -1
- package/link/batch-http/batch-http.cjs.native.js +5 -4
- 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 +1 -1
- package/link/batch-http/batchHttpLink.js.map +1 -1
- package/link/http/createHttpLink.js +1 -1
- package/link/http/createHttpLink.js.map +1 -1
- package/link/http/http.cjs +2 -3
- package/link/http/http.cjs.map +1 -1
- package/link/http/http.cjs.native.js +2 -3
- package/link/http/selectHttpOptionsAndBody.d.ts +1 -1
- package/link/http/selectHttpOptionsAndBody.d.ts.map +1 -1
- package/link/http/selectHttpOptionsAndBody.js +1 -1
- package/link/http/selectHttpOptionsAndBody.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 +26 -29
- package/link/persisted-queries/index.js.map +1 -1
- package/link/persisted-queries/persisted-queries.cjs +25 -29
- package/link/persisted-queries/persisted-queries.cjs.map +1 -1
- package/link/persisted-queries/persisted-queries.cjs.native.js +25 -29
- package/link/subscriptions/index.js +1 -1
- package/link/subscriptions/index.js.map +1 -1
- package/link/subscriptions/subscriptions.cjs +2 -3
- package/link/subscriptions/subscriptions.cjs.map +1 -1
- package/link/subscriptions/subscriptions.cjs.native.js +2 -3
- package/link/utils/filterOperationVariables.d.ts +2 -2
- package/link/utils/filterOperationVariables.d.ts.map +1 -1
- package/link/utils/filterOperationVariables.js +5 -4
- package/link/utils/filterOperationVariables.js.map +1 -1
- package/link/utils/utils.cjs +4 -3
- package/link/utils/utils.cjs.map +1 -1
- package/link/utils/utils.cjs.native.js +4 -3
- 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/cache/SuspenseCache.d.ts +0 -1
- package/react/cache/SuspenseCache.d.ts.map +1 -1
- package/react/cache/SuspenseCache.js +10 -10
- package/react/cache/SuspenseCache.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 +19 -6
- 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 -5
- 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 +22 -10
- package/react/react.cjs.map +1 -1
- package/react/react.cjs.native.js +22 -10
- package/react/types/types.d.ts +2 -1
- package/react/types/types.d.ts.map +1 -1
- package/react/types/types.js.map +1 -1
- package/testing/core/core.cjs +2 -3
- package/testing/core/core.cjs.map +1 -1
- package/testing/core/core.cjs.native.js +2 -3
- package/testing/core/mocking/mockLink.d.ts.map +1 -1
- package/testing/core/mocking/mockLink.js +1 -2
- package/testing/core/mocking/mockLink.js.map +1 -1
- package/testing/matchers/index.js +2 -0
- package/testing/matchers/index.js.map +1 -1
- package/testing/matchers/toHaveSuspenseCacheEntryUsing.d.ts +12 -0
- package/testing/matchers/toHaveSuspenseCacheEntryUsing.d.ts.map +1 -0
- package/testing/matchers/toHaveSuspenseCacheEntryUsing.js +18 -0
- package/testing/matchers/toHaveSuspenseCacheEntryUsing.js.map +1 -0
- package/testing/matchers/toMatchDocument.d.ts.map +1 -1
- package/testing/matchers/toMatchDocument.js +1 -2
- package/testing/matchers/toMatchDocument.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/graphql/print.d.ts +3 -0
- package/utilities/graphql/print.d.ts.map +1 -0
- package/utilities/graphql/print.js +13 -0
- package/utilities/graphql/print.js.map +1 -0
- package/utilities/index.d.ts +1 -0
- package/utilities/index.d.ts.map +1 -1
- package/utilities/index.js +1 -0
- package/utilities/index.js.map +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 +15 -0
- package/utilities/utilities.cjs.map +1 -1
- package/utilities/utilities.cjs.native.js +15 -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 {
|
|
@@ -614,6 +614,17 @@ var DocumentTransform = (function () {
|
|
|
614
614
|
return DocumentTransform;
|
|
615
615
|
}());
|
|
616
616
|
|
|
617
|
+
var printCache = canUseWeakMap ? new WeakMap() : undefined;
|
|
618
|
+
var print = function (ast) {
|
|
619
|
+
var result;
|
|
620
|
+
result = printCache === null || printCache === void 0 ? void 0 : printCache.get(ast);
|
|
621
|
+
if (!result) {
|
|
622
|
+
result = graphql.print(ast);
|
|
623
|
+
printCache === null || printCache === void 0 ? void 0 : printCache.set(ast, result);
|
|
624
|
+
}
|
|
625
|
+
return result;
|
|
626
|
+
};
|
|
627
|
+
|
|
617
628
|
var isArray = Array.isArray;
|
|
618
629
|
function isNonEmptyArray(value) {
|
|
619
630
|
return Array.isArray(value) && value.length > 0;
|
|
@@ -1453,12 +1464,13 @@ function transformOperation(operation) {
|
|
|
1453
1464
|
return transformedOperation;
|
|
1454
1465
|
}
|
|
1455
1466
|
|
|
1456
|
-
function filterOperationVariables(variables,
|
|
1467
|
+
function filterOperationVariables(variables, query) {
|
|
1457
1468
|
var result = tslib.__assign({}, variables);
|
|
1458
1469
|
var unusedNames = new Set(Object.keys(variables));
|
|
1459
|
-
graphql.visit(
|
|
1470
|
+
graphql.visit(query, {
|
|
1460
1471
|
Variable: function (node, _key, parent) {
|
|
1461
|
-
if (parent &&
|
|
1472
|
+
if (parent &&
|
|
1473
|
+
parent.kind !== 'VariableDefinition') {
|
|
1462
1474
|
unusedNames.delete(node.name.value);
|
|
1463
1475
|
}
|
|
1464
1476
|
},
|
|
@@ -1970,7 +1982,7 @@ function selectHttpOptionsAndBodyInternal(operation, printer) {
|
|
|
1970
1982
|
if (http.includeExtensions)
|
|
1971
1983
|
body.extensions = extensions;
|
|
1972
1984
|
if (http.includeQuery)
|
|
1973
|
-
body.query = printer(query,
|
|
1985
|
+
body.query = printer(query, print);
|
|
1974
1986
|
return {
|
|
1975
1987
|
options: options,
|
|
1976
1988
|
body: body,
|
|
@@ -2107,7 +2119,7 @@ var createHttpLink = function (linkOptions) {
|
|
|
2107
2119
|
}
|
|
2108
2120
|
var _b = selectHttpOptionsAndBodyInternal(operation, print, fallbackHttpConfig, linkConfig, contextConfig), options = _b.options, body = _b.body;
|
|
2109
2121
|
if (body.variables && !includeUnusedVariables) {
|
|
2110
|
-
body.variables = filterOperationVariables(body.variables, operation);
|
|
2122
|
+
body.variables = filterOperationVariables(body.variables, operation.query);
|
|
2111
2123
|
}
|
|
2112
2124
|
var controller;
|
|
2113
2125
|
if (!options.signal) {
|
|
@@ -6263,8 +6275,9 @@ var QueryManager = (function () {
|
|
|
6263
6275
|
};
|
|
6264
6276
|
context = operation.context;
|
|
6265
6277
|
if (deduplication) {
|
|
6266
|
-
var
|
|
6267
|
-
inFlightLinkObservables_1.
|
|
6278
|
+
var printedServerQuery_1 = print(serverQuery);
|
|
6279
|
+
var byVariables_1 = inFlightLinkObservables_1.get(printedServerQuery_1) || new Map();
|
|
6280
|
+
inFlightLinkObservables_1.set(printedServerQuery_1, byVariables_1);
|
|
6268
6281
|
var varJson_1 = canonicalStringify(variables);
|
|
6269
6282
|
observable = byVariables_1.get(varJson_1);
|
|
6270
6283
|
if (!observable) {
|
|
@@ -6275,7 +6288,7 @@ var QueryManager = (function () {
|
|
|
6275
6288
|
concast.beforeNext(function () {
|
|
6276
6289
|
if (byVariables_1.delete(varJson_1) &&
|
|
6277
6290
|
byVariables_1.size < 1) {
|
|
6278
|
-
inFlightLinkObservables_1.delete(
|
|
6291
|
+
inFlightLinkObservables_1.delete(printedServerQuery_1);
|
|
6279
6292
|
}
|
|
6280
6293
|
});
|
|
6281
6294
|
}
|
|
@@ -7654,15 +7667,20 @@ function useSuspenseQuery(query, options) {
|
|
|
7654
7667
|
if (options === void 0) { options = Object.create(null); }
|
|
7655
7668
|
var client = useApolloClient(options.client);
|
|
7656
7669
|
var suspenseCache = useSuspenseCache(options.suspenseCache);
|
|
7657
|
-
var watchQueryOptions = useWatchQueryOptions({ query: query, options: options });
|
|
7658
|
-
var variables = watchQueryOptions.variables;
|
|
7670
|
+
var watchQueryOptions = useWatchQueryOptions({ client: client, query: query, options: options });
|
|
7671
|
+
var fetchPolicy = watchQueryOptions.fetchPolicy, variables = watchQueryOptions.variables;
|
|
7659
7672
|
var _a = options.queryKey, queryKey = _a === void 0 ? [] : _a;
|
|
7660
7673
|
var cacheKey = [client, query, canonicalStringify(variables)].concat(queryKey);
|
|
7661
7674
|
var queryRef = suspenseCache.getQueryRef(cacheKey, function () {
|
|
7662
7675
|
return client.watchQuery(watchQueryOptions);
|
|
7663
7676
|
});
|
|
7677
|
+
var currentFetchPolicy = queryRef.watchQueryOptions.fetchPolicy;
|
|
7664
7678
|
var _b = React.useState(function () { return new Map([[queryRef.key, queryRef.promise]]); }), promiseCache = _b[0], setPromiseCache = _b[1];
|
|
7665
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
|
+
}
|
|
7666
7684
|
if (!promise) {
|
|
7667
7685
|
promise = queryRef.promise;
|
|
7668
7686
|
promiseCache.set(queryRef.key, promise);
|
|
@@ -7675,7 +7693,16 @@ function useSuspenseQuery(query, options) {
|
|
|
7675
7693
|
});
|
|
7676
7694
|
});
|
|
7677
7695
|
}, [queryRef]);
|
|
7678
|
-
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);
|
|
7679
7706
|
var fetchMore = React.useCallback(function (options) {
|
|
7680
7707
|
var promise = queryRef.fetchMore(options);
|
|
7681
7708
|
setPromiseCache(function (previousPromiseCache) {
|
|
@@ -7737,26 +7764,40 @@ function useTrackedQueryRefs(queryRef) {
|
|
|
7737
7764
|
});
|
|
7738
7765
|
}
|
|
7739
7766
|
function useWatchQueryOptions(_a) {
|
|
7740
|
-
var query = _a.query, options = _a.options;
|
|
7741
|
-
|
|
7742
|
-
|
|
7743
|
-
|
|
7744
|
-
|
|
7745
|
-
|
|
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]);
|
|
7746
7782
|
}
|
|
7747
7783
|
|
|
7748
7784
|
function useBackgroundQuery(query, options) {
|
|
7749
7785
|
if (options === void 0) { options = Object.create(null); }
|
|
7750
7786
|
var suspenseCache = useSuspenseCache(options.suspenseCache);
|
|
7751
7787
|
var client = useApolloClient(options.client);
|
|
7752
|
-
var watchQueryOptions = useWatchQueryOptions({ query: query, options: options });
|
|
7753
|
-
var variables = watchQueryOptions.variables;
|
|
7788
|
+
var watchQueryOptions = useWatchQueryOptions({ client: client, query: query, options: options });
|
|
7789
|
+
var fetchPolicy = watchQueryOptions.fetchPolicy, variables = watchQueryOptions.variables;
|
|
7754
7790
|
var _a = options.queryKey, queryKey = _a === void 0 ? [] : _a;
|
|
7755
7791
|
var cacheKey = [client, query, canonicalStringify(variables)].concat(queryKey);
|
|
7756
7792
|
var queryRef = suspenseCache.getQueryRef(cacheKey, function () {
|
|
7757
7793
|
return client.watchQuery(watchQueryOptions);
|
|
7758
7794
|
});
|
|
7795
|
+
var currentFetchPolicy = queryRef.watchQueryOptions.fetchPolicy;
|
|
7759
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
|
+
}
|
|
7760
7801
|
useTrackedQueryRefs(queryRef);
|
|
7761
7802
|
var fetchMore = React.useCallback(function (options) {
|
|
7762
7803
|
var promise = queryRef.fetchMore(options);
|
|
@@ -7786,6 +7827,15 @@ function useBackgroundQuery(query, options) {
|
|
|
7786
7827
|
function useReadQuery(queryRef) {
|
|
7787
7828
|
var _a = React.useState(0), forceUpdate = _a[1];
|
|
7788
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]);
|
|
7789
7839
|
var promise = queryRef.promiseCache.get(queryRef.key);
|
|
7790
7840
|
if (!promise) {
|
|
7791
7841
|
promise = queryRef.promise;
|
|
@@ -7797,7 +7847,9 @@ function useReadQuery(queryRef) {
|
|
|
7797
7847
|
forceUpdate(function (prevState) { return prevState + 1; });
|
|
7798
7848
|
});
|
|
7799
7849
|
}, [queryRef]);
|
|
7800
|
-
var result =
|
|
7850
|
+
var result = queryRef.watchQueryOptions.fetchPolicy === 'standby'
|
|
7851
|
+
? skipResult
|
|
7852
|
+
: __use(promise);
|
|
7801
7853
|
return React.useMemo(function () {
|
|
7802
7854
|
return {
|
|
7803
7855
|
data: result.data,
|
|
@@ -7843,6 +7895,13 @@ var QueryReference = (function () {
|
|
|
7843
7895
|
}
|
|
7844
7896
|
this.autoDisposeTimeoutId = setTimeout(this.dispose, (_a = options.autoDisposeTimeoutMs) !== null && _a !== void 0 ? _a : 30000);
|
|
7845
7897
|
}
|
|
7898
|
+
Object.defineProperty(QueryReference.prototype, "watchQueryOptions", {
|
|
7899
|
+
get: function () {
|
|
7900
|
+
return this.observable.options;
|
|
7901
|
+
},
|
|
7902
|
+
enumerable: false,
|
|
7903
|
+
configurable: true
|
|
7904
|
+
});
|
|
7846
7905
|
QueryReference.prototype.listen = function (listener) {
|
|
7847
7906
|
var _this = this;
|
|
7848
7907
|
clearTimeout(this.autoDisposeTimeoutId);
|
|
@@ -7862,6 +7921,11 @@ var QueryReference = (function () {
|
|
|
7862
7921
|
this.promise = promise;
|
|
7863
7922
|
return promise;
|
|
7864
7923
|
};
|
|
7924
|
+
QueryReference.prototype.reobserve = function (watchQueryOptions) {
|
|
7925
|
+
var promise = this.observable.reobserve(watchQueryOptions);
|
|
7926
|
+
this.promise = promise;
|
|
7927
|
+
return promise;
|
|
7928
|
+
};
|
|
7865
7929
|
QueryReference.prototype.dispose = function () {
|
|
7866
7930
|
this.subscription.unsubscribe();
|
|
7867
7931
|
this.onDispose();
|
|
@@ -7913,21 +7977,21 @@ var QueryReference = (function () {
|
|
|
7913
7977
|
var SuspenseCache = (function () {
|
|
7914
7978
|
function SuspenseCache(options) {
|
|
7915
7979
|
if (options === void 0) { options = Object.create(null); }
|
|
7916
|
-
this.
|
|
7917
|
-
this.queryRefs = new Map();
|
|
7980
|
+
this.queryRefs = new trie.Trie(canUseWeakMap);
|
|
7918
7981
|
this.options = options;
|
|
7919
7982
|
}
|
|
7920
7983
|
SuspenseCache.prototype.getQueryRef = function (cacheKey, createObservable) {
|
|
7921
|
-
var
|
|
7922
|
-
|
|
7923
|
-
|
|
7924
|
-
|
|
7925
|
-
key: stableCacheKey,
|
|
7984
|
+
var ref = this.queryRefs.lookupArray(cacheKey);
|
|
7985
|
+
if (!ref.current) {
|
|
7986
|
+
ref.current = new QueryReference(createObservable(), {
|
|
7987
|
+
key: cacheKey,
|
|
7926
7988
|
autoDisposeTimeoutMs: this.options.autoDisposeTimeoutMs,
|
|
7927
|
-
onDispose: function () {
|
|
7928
|
-
|
|
7989
|
+
onDispose: function () {
|
|
7990
|
+
delete ref.current;
|
|
7991
|
+
},
|
|
7992
|
+
});
|
|
7929
7993
|
}
|
|
7930
|
-
return
|
|
7994
|
+
return ref.current;
|
|
7931
7995
|
};
|
|
7932
7996
|
return SuspenseCache;
|
|
7933
7997
|
}());
|