@apollo/client 3.1.0-pre.1 → 3.1.0
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.js +123 -157
- package/apollo-client.cjs.js.map +1 -1
- package/apollo-client.cjs.min.js +1 -1
- package/cache/cache.cjs.js +11 -2
- package/cache/cache.cjs.js.map +1 -1
- package/cache/core/cache.js +2 -18
- package/cache/core/cache.js.map +1 -1
- package/cache/core/types/Cache.js +2 -4
- package/cache/core/types/Cache.js.map +1 -1
- package/cache/core/types/common.js +1 -2
- package/cache/core/types/common.js.map +1 -1
- package/cache/index.js +8 -8
- package/cache/inmemory/entityStore.js +7 -23
- package/cache/inmemory/entityStore.js.map +1 -1
- package/cache/inmemory/helpers.js +8 -25
- package/cache/inmemory/helpers.js.map +1 -1
- package/cache/inmemory/inMemoryCache.js +12 -27
- package/cache/inmemory/inMemoryCache.js.map +1 -1
- package/cache/inmemory/policies.d.ts +2 -1
- package/cache/inmemory/policies.d.ts.map +1 -1
- package/cache/inmemory/policies.js +19 -26
- package/cache/inmemory/policies.js.map +1 -1
- package/cache/inmemory/reactiveVars.js +5 -8
- package/cache/inmemory/reactiveVars.js.map +1 -1
- package/cache/inmemory/readFromStore.js +9 -24
- package/cache/inmemory/readFromStore.js.map +1 -1
- package/cache/inmemory/writeToStore.js +7 -22
- package/cache/inmemory/writeToStore.js.map +1 -1
- package/core/ApolloClient.d.ts.map +1 -1
- package/core/ApolloClient.js +11 -25
- package/core/ApolloClient.js.map +1 -1
- package/core/LocalState.js +5 -26
- package/core/LocalState.js.map +1 -1
- package/core/MutationStore.js +1 -2
- package/core/MutationStore.js.map +1 -1
- package/core/ObservableQuery.d.ts +6 -10
- package/core/ObservableQuery.d.ts.map +1 -1
- package/core/ObservableQuery.js +49 -121
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryInfo.d.ts +2 -2
- package/core/QueryInfo.d.ts.map +1 -1
- package/core/QueryInfo.js +31 -38
- package/core/QueryInfo.js.map +1 -1
- package/core/QueryManager.d.ts +3 -5
- package/core/QueryManager.d.ts.map +1 -1
- package/core/QueryManager.js +32 -63
- package/core/QueryManager.js.map +1 -1
- package/core/Reobserver.d.ts.map +1 -1
- package/core/Reobserver.js +5 -11
- package/core/Reobserver.js.map +1 -1
- package/core/core.cjs.js +93 -155
- package/core/core.cjs.js.map +1 -1
- package/core/index.d.ts +1 -1
- package/core/index.d.ts.map +1 -1
- package/core/index.js +13 -53
- package/core/index.js.map +1 -1
- package/core/networkStatus.js +3 -5
- package/core/networkStatus.js.map +1 -1
- package/core/types.d.ts +3 -0
- package/core/types.d.ts.map +1 -1
- package/core/watchQueryOptions.d.ts +1 -0
- package/core/watchQueryOptions.d.ts.map +1 -1
- package/errors/index.js +5 -21
- package/errors/index.js.map +1 -1
- package/index.js +3 -43
- package/index.js.map +1 -1
- package/invariantErrorCodes.js +1 -1
- package/link/batch/batchLink.js +3 -3
- package/link/batch/batching.js +1 -1
- package/link/batch/index.js +1 -1
- package/link/batch-http/batchHttpLink.js +5 -5
- package/link/batch-http/index.js +1 -1
- package/link/context/index.js +2 -2
- package/link/core/ApolloLink.js +4 -26
- package/link/core/ApolloLink.js.map +1 -1
- package/link/core/concat.js +3 -6
- package/link/core/concat.js.map +1 -1
- package/link/core/empty.js +3 -6
- package/link/core/empty.js.map +1 -1
- package/link/core/execute.js +3 -6
- package/link/core/execute.js.map +1 -1
- package/link/core/from.js +3 -6
- package/link/core/from.js.map +1 -1
- package/link/core/index.js +7 -7
- package/link/core/split.js +3 -6
- package/link/core/split.js.map +1 -1
- package/link/error/index.js +2 -2
- package/link/http/HttpLink.js +4 -11
- package/link/http/HttpLink.js.map +1 -1
- package/link/http/checkFetcher.js +2 -5
- package/link/http/checkFetcher.js.map +1 -1
- package/link/http/createHttpLink.js +13 -41
- package/link/http/createHttpLink.js.map +1 -1
- package/link/http/createSignalIfSupported.js +2 -4
- package/link/http/createSignalIfSupported.js.map +1 -1
- package/link/http/index.js +9 -9
- package/link/http/parseAndCheckHttpResponse.js +3 -12
- package/link/http/parseAndCheckHttpResponse.js.map +1 -1
- package/link/http/rewriteURIForGET.js +3 -6
- package/link/http/rewriteURIForGET.js.map +1 -1
- package/link/http/selectHttpOptionsAndBody.js +4 -7
- package/link/http/selectHttpOptionsAndBody.js.map +1 -1
- package/link/http/selectURI.js +2 -4
- package/link/http/selectURI.js.map +1 -1
- package/link/http/serializeFetchParameter.js +2 -5
- package/link/http/serializeFetchParameter.js.map +1 -1
- package/link/retry/index.js +1 -1
- package/link/retry/retryLink.js +4 -4
- package/link/schema/index.js +2 -2
- package/link/utils/createOperation.js +3 -6
- package/link/utils/createOperation.js.map +1 -1
- package/link/utils/fromError.js +3 -20
- package/link/utils/fromError.js.map +1 -1
- package/link/utils/fromPromise.js +3 -20
- package/link/utils/fromPromise.js.map +1 -1
- package/link/utils/index.js +7 -7
- package/link/utils/throwServerError.js +2 -4
- package/link/utils/throwServerError.js.map +1 -1
- package/link/utils/toPromise.js +2 -5
- package/link/utils/toPromise.js.map +1 -1
- package/link/utils/transformOperation.js +3 -20
- package/link/utils/transformOperation.js.map +1 -1
- package/link/utils/validateOperation.js +2 -5
- package/link/utils/validateOperation.js.map +1 -1
- package/link/ws/index.js +1 -1
- package/package.json +3 -2
- package/react/components/Mutation.js +1 -1
- package/react/components/Query.js +1 -1
- package/react/components/Subscription.js +1 -1
- package/react/components/index.js +4 -4
- package/react/context/ApolloConsumer.js +4 -7
- package/react/context/ApolloConsumer.js.map +1 -1
- package/react/context/ApolloContext.js +3 -6
- package/react/context/ApolloContext.js.map +1 -1
- package/react/context/ApolloProvider.js +4 -7
- package/react/context/ApolloProvider.js.map +1 -1
- package/react/context/index.js +3 -3
- package/react/data/MutationData.d.ts.map +1 -1
- package/react/data/MutationData.js +7 -8
- package/react/data/MutationData.js.map +1 -1
- package/react/data/OperationData.js +3 -5
- package/react/data/OperationData.js.map +1 -1
- package/react/data/QueryData.js +9 -10
- package/react/data/QueryData.js.map +1 -1
- package/react/data/SubscriptionData.js +3 -5
- package/react/data/SubscriptionData.js.map +1 -1
- package/react/data/data.cjs.js +2 -1
- package/react/data/data.cjs.js.map +1 -1
- package/react/data/index.js +4 -4
- package/react/hoc/graphql.js +4 -4
- package/react/hoc/index.js +6 -6
- package/react/hoc/mutation-hoc.js +3 -3
- package/react/hoc/query-hoc.js +3 -3
- package/react/hoc/subscription-hoc.js +3 -3
- package/react/hoc/withApollo.js +1 -1
- package/react/hooks/index.js +5 -5
- package/react/hooks/useApolloClient.js +4 -9
- package/react/hooks/useApolloClient.js.map +1 -1
- package/react/hooks/useLazyQuery.js +3 -6
- package/react/hooks/useLazyQuery.js.map +1 -1
- package/react/hooks/useMutation.js +5 -13
- package/react/hooks/useMutation.js.map +1 -1
- package/react/hooks/useQuery.js +3 -6
- package/react/hooks/useQuery.js.map +1 -1
- package/react/hooks/useSubscription.js +5 -13
- package/react/hooks/useSubscription.js.map +1 -1
- package/react/hooks/utils/useBaseQuery.js +7 -15
- package/react/hooks/utils/useBaseQuery.js.map +1 -1
- package/react/hooks/utils/useDeepMemo.js +3 -6
- package/react/hooks/utils/useDeepMemo.js.map +1 -1
- package/react/index.js +4 -4
- package/react/parser/index.js +4 -7
- package/react/parser/index.js.map +1 -1
- package/react/ssr/getDataFromTree.js +2 -2
- package/react/ssr/index.js +3 -3
- package/react/ssr/renderToStringWithData.js +1 -1
- package/react/types/types.d.ts +1 -0
- package/react/types/types.d.ts.map +1 -1
- package/testing/index.js +1 -1
- package/testing/testing.cjs.js +6 -6
- package/testing/testing.cjs.js.map +1 -1
- package/utilities/common/arrays.js +2 -4
- package/utilities/common/arrays.js.map +1 -1
- package/utilities/common/canUse.js +2 -4
- package/utilities/common/canUse.js.map +1 -1
- package/utilities/common/cloneDeep.js +2 -4
- package/utilities/common/cloneDeep.js.map +1 -1
- package/utilities/common/compact.d.ts +3 -0
- package/utilities/common/compact.d.ts.map +1 -0
- package/utilities/common/compact.js +19 -0
- package/utilities/common/compact.js.map +1 -0
- package/utilities/common/environment.js +5 -7
- package/utilities/common/environment.js.map +1 -1
- package/utilities/common/errorHandling.js +2 -4
- package/utilities/common/errorHandling.js.map +1 -1
- package/utilities/common/filterInPlace.js +2 -4
- package/utilities/common/filterInPlace.js.map +1 -1
- package/utilities/common/maybeDeepFreeze.js +3 -6
- package/utilities/common/maybeDeepFreeze.js.map +1 -1
- package/utilities/common/mergeDeep.js +5 -7
- package/utilities/common/mergeDeep.js.map +1 -1
- package/utilities/graphql/directives.js +7 -10
- package/utilities/graphql/directives.js.map +1 -1
- package/utilities/graphql/fragments.js +6 -9
- package/utilities/graphql/fragments.js.map +1 -1
- package/utilities/graphql/getFromAST.js +10 -13
- package/utilities/graphql/getFromAST.js.map +1 -1
- package/utilities/graphql/storeUtils.js +13 -16
- package/utilities/graphql/storeUtils.js.map +1 -1
- package/utilities/graphql/transform.js +34 -17
- package/utilities/graphql/transform.js.map +1 -1
- package/utilities/index.d.ts +1 -0
- package/utilities/index.d.ts.map +1 -1
- package/utilities/index.js +17 -16
- package/utilities/index.js.map +1 -1
- package/utilities/observables/Concast.js +5 -8
- package/utilities/observables/Concast.js.map +1 -1
- package/utilities/observables/asyncMap.js +3 -7
- package/utilities/observables/asyncMap.js.map +1 -1
- package/utilities/observables/iteration.js +2 -4
- package/utilities/observables/iteration.js.map +1 -1
- package/utilities/testing/index.js +7 -7
- package/utilities/testing/itAsync.d.ts.map +1 -1
- package/utilities/testing/itAsync.js +6 -6
- package/utilities/testing/itAsync.js.map +1 -1
- package/utilities/testing/mocking/MockedProvider.js +4 -4
- package/utilities/testing/mocking/mockClient.js +3 -3
- package/utilities/testing/mocking/mockLink.js +2 -2
- package/utilities/testing/mocking/mockQueryManager.js +3 -3
- package/utilities/testing/mocking/mockSubscriptionLink.js +2 -2
- package/utilities/testing/mocking/mockWatchQuery.js +1 -1
- package/utilities/testing/subscribeAndCount.js +1 -1
- package/utilities/utilities.cjs.js +20 -0
- package/utilities/utilities.cjs.js.map +1 -1
- package/version.js +2 -4
- package/version.js.map +1 -1
package/apollo-client.cjs.js
CHANGED
|
@@ -991,6 +991,25 @@ function graphQLResultHasError(result) {
|
|
|
991
991
|
var canUseWeakMap = typeof WeakMap === 'function' && !(typeof navigator === 'object' &&
|
|
992
992
|
navigator.product === 'ReactNative');
|
|
993
993
|
|
|
994
|
+
function compact() {
|
|
995
|
+
var objects = [];
|
|
996
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
997
|
+
objects[_i] = arguments[_i];
|
|
998
|
+
}
|
|
999
|
+
var result = Object.create(null);
|
|
1000
|
+
objects.forEach(function (obj) {
|
|
1001
|
+
if (!obj)
|
|
1002
|
+
return;
|
|
1003
|
+
Object.keys(obj).forEach(function (key) {
|
|
1004
|
+
var value = obj[key];
|
|
1005
|
+
if (value !== void 0) {
|
|
1006
|
+
result[key] = value;
|
|
1007
|
+
}
|
|
1008
|
+
});
|
|
1009
|
+
});
|
|
1010
|
+
return result;
|
|
1011
|
+
}
|
|
1012
|
+
|
|
994
1013
|
function fromError(errorValue) {
|
|
995
1014
|
return new Observable(function (observer) {
|
|
996
1015
|
observer.error(errorValue);
|
|
@@ -1558,13 +1577,7 @@ var Reobserver = (function () {
|
|
|
1558
1577
|
return (this.concast = concast).promise;
|
|
1559
1578
|
};
|
|
1560
1579
|
Reobserver.prototype.updateOptions = function (newOptions) {
|
|
1561
|
-
|
|
1562
|
-
Object.keys(newOptions).forEach(function (key) {
|
|
1563
|
-
var value = newOptions[key];
|
|
1564
|
-
if (value !== void 0) {
|
|
1565
|
-
_this.options[key] = value;
|
|
1566
|
-
}
|
|
1567
|
-
});
|
|
1580
|
+
Object.assign(this.options, compact(newOptions));
|
|
1568
1581
|
this.updatePolling();
|
|
1569
1582
|
return this;
|
|
1570
1583
|
};
|
|
@@ -1623,16 +1636,11 @@ var Reobserver = (function () {
|
|
|
1623
1636
|
return Reobserver;
|
|
1624
1637
|
}());
|
|
1625
1638
|
|
|
1626
|
-
var hasError = function (storeValue, policy) {
|
|
1627
|
-
if (policy === void 0) { policy = 'none'; }
|
|
1628
|
-
return storeValue && (storeValue.networkError ||
|
|
1629
|
-
(policy === 'none' && isNonEmptyArray(storeValue.graphQLErrors)));
|
|
1630
|
-
};
|
|
1631
1639
|
var warnedAboutUpdateQuery = false;
|
|
1632
1640
|
var ObservableQuery = (function (_super) {
|
|
1633
1641
|
tslib.__extends(ObservableQuery, _super);
|
|
1634
1642
|
function ObservableQuery(_a) {
|
|
1635
|
-
var queryManager = _a.queryManager, options = _a.options;
|
|
1643
|
+
var queryManager = _a.queryManager, queryInfo = _a.queryInfo, options = _a.options;
|
|
1636
1644
|
var _this = _super.call(this, function (observer) {
|
|
1637
1645
|
return _this.onSubscribe(observer);
|
|
1638
1646
|
}) || this;
|
|
@@ -1656,6 +1664,7 @@ var ObservableQuery = (function (_super) {
|
|
|
1656
1664
|
var opDef = getOperationDefinition(options.query);
|
|
1657
1665
|
_this.queryName = opDef && opDef.name && opDef.name.value;
|
|
1658
1666
|
_this.queryManager = queryManager;
|
|
1667
|
+
_this.queryInfo = queryInfo;
|
|
1659
1668
|
return _this;
|
|
1660
1669
|
}
|
|
1661
1670
|
Object.defineProperty(ObservableQuery.prototype, "variables", {
|
|
@@ -1685,54 +1694,32 @@ var ObservableQuery = (function (_super) {
|
|
|
1685
1694
|
});
|
|
1686
1695
|
};
|
|
1687
1696
|
ObservableQuery.prototype.getCurrentResult = function () {
|
|
1688
|
-
var _a = this, lastResult = _a.lastResult, lastError = _a.lastError
|
|
1689
|
-
var
|
|
1690
|
-
|
|
1691
|
-
var networkStatus = lastError ? exports.NetworkStatus.error :
|
|
1692
|
-
lastResult ? lastResult.networkStatus :
|
|
1693
|
-
isNetworkFetchPolicy ? exports.NetworkStatus.loading :
|
|
1694
|
-
exports.NetworkStatus.ready;
|
|
1695
|
-
var result = {
|
|
1696
|
-
data: !lastError && lastResult && lastResult.data || void 0,
|
|
1697
|
-
error: lastError,
|
|
1698
|
-
loading: isNetworkRequestInFlight(networkStatus),
|
|
1699
|
-
networkStatus: networkStatus,
|
|
1700
|
-
};
|
|
1697
|
+
var _a = this, lastResult = _a.lastResult, lastError = _a.lastError;
|
|
1698
|
+
var networkStatus = this.queryInfo.networkStatus || exports.NetworkStatus.ready;
|
|
1699
|
+
var result = tslib.__assign(tslib.__assign({}, (lastError ? { error: lastError } : lastResult)), { loading: isNetworkRequestInFlight(networkStatus), networkStatus: networkStatus });
|
|
1701
1700
|
if (this.isTornDown) {
|
|
1702
1701
|
return result;
|
|
1703
1702
|
}
|
|
1704
|
-
var _b = this.
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
}
|
|
1722
|
-
Object.assign(result, {
|
|
1723
|
-
loading: isNetworkRequestInFlight(networkStatus_1),
|
|
1724
|
-
networkStatus: networkStatus_1,
|
|
1725
|
-
});
|
|
1726
|
-
if (queryStoreValue.graphQLErrors && this.options.errorPolicy === 'all') {
|
|
1727
|
-
result.errors = queryStoreValue.graphQLErrors;
|
|
1703
|
+
var _b = this.options.fetchPolicy, fetchPolicy = _b === void 0 ? 'cache-first' : _b;
|
|
1704
|
+
if (fetchPolicy === 'no-cache' ||
|
|
1705
|
+
fetchPolicy === 'network-only') {
|
|
1706
|
+
result.partial = false;
|
|
1707
|
+
}
|
|
1708
|
+
else if (!result.data ||
|
|
1709
|
+
!this.queryManager.transform(this.options.query).hasForcedResolvers) {
|
|
1710
|
+
var diff = this.queryInfo.getDiff();
|
|
1711
|
+
result.partial = !diff.complete;
|
|
1712
|
+
result.data = (diff.complete ||
|
|
1713
|
+
this.options.returnPartialData) ? diff.result : void 0;
|
|
1714
|
+
if (diff.complete &&
|
|
1715
|
+
result.networkStatus === exports.NetworkStatus.loading &&
|
|
1716
|
+
(fetchPolicy === 'cache-first' ||
|
|
1717
|
+
fetchPolicy === 'cache-only')) {
|
|
1718
|
+
result.networkStatus = exports.NetworkStatus.ready;
|
|
1719
|
+
result.loading = false;
|
|
1728
1720
|
}
|
|
1729
1721
|
}
|
|
1730
|
-
|
|
1731
|
-
this.resetLastResults();
|
|
1732
|
-
}
|
|
1733
|
-
else {
|
|
1734
|
-
this.updateLastResult(result);
|
|
1735
|
-
}
|
|
1722
|
+
this.updateLastResult(result);
|
|
1736
1723
|
return result;
|
|
1737
1724
|
};
|
|
1738
1725
|
ObservableQuery.prototype.isDifferentFromLastResult = function (newResult) {
|
|
@@ -1751,29 +1738,25 @@ var ObservableQuery = (function (_super) {
|
|
|
1751
1738
|
this.isTornDown = false;
|
|
1752
1739
|
};
|
|
1753
1740
|
ObservableQuery.prototype.resetQueryStoreErrors = function () {
|
|
1754
|
-
|
|
1755
|
-
if (queryStore) {
|
|
1756
|
-
queryStore.networkError = undefined;
|
|
1757
|
-
queryStore.graphQLErrors = [];
|
|
1758
|
-
}
|
|
1741
|
+
this.queryManager.resetErrors(this.queryId);
|
|
1759
1742
|
};
|
|
1760
1743
|
ObservableQuery.prototype.refetch = function (variables) {
|
|
1761
1744
|
var fetchPolicy = this.options.fetchPolicy;
|
|
1762
1745
|
if (fetchPolicy === 'cache-only') {
|
|
1763
1746
|
return Promise.reject(process.env.NODE_ENV === "production" ? new tsInvariant.InvariantError(12) : new tsInvariant.InvariantError('cache-only fetchPolicy option should not be used together with query refetch.'));
|
|
1764
1747
|
}
|
|
1748
|
+
var reobserveOptions = {
|
|
1749
|
+
pollInterval: 0,
|
|
1750
|
+
};
|
|
1765
1751
|
if (fetchPolicy !== 'no-cache' &&
|
|
1766
1752
|
fetchPolicy !== 'cache-and-network') {
|
|
1767
|
-
fetchPolicy = 'network-only';
|
|
1753
|
+
reobserveOptions.fetchPolicy = 'network-only';
|
|
1754
|
+
reobserveOptions.nextFetchPolicy = fetchPolicy;
|
|
1768
1755
|
}
|
|
1769
1756
|
if (variables && !equality.equal(this.options.variables, variables)) {
|
|
1770
|
-
this.options.variables = tslib.__assign(tslib.__assign({}, this.options.variables), variables);
|
|
1757
|
+
reobserveOptions.variables = this.options.variables = tslib.__assign(tslib.__assign({}, this.options.variables), variables);
|
|
1771
1758
|
}
|
|
1772
|
-
return this.newReobserver(false).reobserve(
|
|
1773
|
-
fetchPolicy: fetchPolicy,
|
|
1774
|
-
variables: this.options.variables,
|
|
1775
|
-
pollInterval: 0,
|
|
1776
|
-
}, exports.NetworkStatus.refetch);
|
|
1759
|
+
return this.newReobserver(false).reobserve(reobserveOptions, exports.NetworkStatus.refetch);
|
|
1777
1760
|
};
|
|
1778
1761
|
ObservableQuery.prototype.fetchMore = function (fetchMoreOptions) {
|
|
1779
1762
|
var _this = this;
|
|
@@ -1781,10 +1764,7 @@ var ObservableQuery = (function (_super) {
|
|
|
1781
1764
|
var qid = this.queryManager.generateQueryId();
|
|
1782
1765
|
if (combinedOptions.notifyOnNetworkStatusChange) {
|
|
1783
1766
|
var currentResult = this.getCurrentResult();
|
|
1784
|
-
|
|
1785
|
-
if (queryInfo) {
|
|
1786
|
-
queryInfo.networkStatus = exports.NetworkStatus.fetchMore;
|
|
1787
|
-
}
|
|
1767
|
+
this.queryInfo.networkStatus = exports.NetworkStatus.fetchMore;
|
|
1788
1768
|
this.observer.next(tslib.__assign(tslib.__assign({}, currentResult), { loading: true, networkStatus: exports.NetworkStatus.fetchMore }));
|
|
1789
1769
|
}
|
|
1790
1770
|
return this.queryManager.fetchQuery(qid, combinedOptions, exports.NetworkStatus.fetchMore).then(function (fetchMoreResult) {
|
|
@@ -1875,9 +1855,16 @@ var ObservableQuery = (function (_super) {
|
|
|
1875
1855
|
}, exports.NetworkStatus.setVariables);
|
|
1876
1856
|
};
|
|
1877
1857
|
ObservableQuery.prototype.updateQuery = function (mapFn) {
|
|
1858
|
+
var _a;
|
|
1878
1859
|
var queryManager = this.queryManager;
|
|
1879
|
-
var
|
|
1880
|
-
|
|
1860
|
+
var result = queryManager.cache.diff({
|
|
1861
|
+
query: this.options.query,
|
|
1862
|
+
variables: this.variables,
|
|
1863
|
+
previousResult: (_a = this.lastResult) === null || _a === void 0 ? void 0 : _a.data,
|
|
1864
|
+
returnPartialData: true,
|
|
1865
|
+
optimistic: false,
|
|
1866
|
+
}).result;
|
|
1867
|
+
var newResult = mapFn(result, {
|
|
1881
1868
|
variables: this.variables,
|
|
1882
1869
|
});
|
|
1883
1870
|
if (newResult) {
|
|
@@ -1889,35 +1876,6 @@ var ObservableQuery = (function (_super) {
|
|
|
1889
1876
|
queryManager.broadcastQueries();
|
|
1890
1877
|
}
|
|
1891
1878
|
};
|
|
1892
|
-
ObservableQuery.prototype.getCurrentQueryResult = function (optimistic) {
|
|
1893
|
-
var _a, _b;
|
|
1894
|
-
if (optimistic === void 0) { optimistic = true; }
|
|
1895
|
-
var fetchPolicy = this.options.fetchPolicy;
|
|
1896
|
-
var lastData = (_a = this.lastResult) === null || _a === void 0 ? void 0 : _a.data;
|
|
1897
|
-
if (fetchPolicy === 'no-cache' ||
|
|
1898
|
-
fetchPolicy === 'network-only') {
|
|
1899
|
-
return {
|
|
1900
|
-
data: lastData,
|
|
1901
|
-
partial: false,
|
|
1902
|
-
};
|
|
1903
|
-
}
|
|
1904
|
-
var _c = this.queryManager.cache.diff({
|
|
1905
|
-
query: this.options.query,
|
|
1906
|
-
variables: this.variables,
|
|
1907
|
-
previousResult: (_b = this.lastResult) === null || _b === void 0 ? void 0 : _b.data,
|
|
1908
|
-
returnPartialData: true,
|
|
1909
|
-
optimistic: optimistic,
|
|
1910
|
-
}), result = _c.result, complete = _c.complete;
|
|
1911
|
-
if (lastData &&
|
|
1912
|
-
!this.lastError &&
|
|
1913
|
-
this.queryManager.transform(this.options.query).hasForcedResolvers) {
|
|
1914
|
-
result = lastData;
|
|
1915
|
-
}
|
|
1916
|
-
return {
|
|
1917
|
-
data: (complete || this.options.returnPartialData) ? result : void 0,
|
|
1918
|
-
partial: !complete,
|
|
1919
|
-
};
|
|
1920
|
-
};
|
|
1921
1879
|
ObservableQuery.prototype.startPolling = function (pollInterval) {
|
|
1922
1880
|
this.getReobserver().updateOptions({ pollInterval: pollInterval });
|
|
1923
1881
|
};
|
|
@@ -1977,7 +1935,7 @@ var ObservableQuery = (function (_super) {
|
|
|
1977
1935
|
return new Reobserver(this.observer, shareOptions ? this.options : tslib.__assign({}, this.options), function (currentOptions, newNetworkStatus) {
|
|
1978
1936
|
queryManager.setObservableQuery(_this);
|
|
1979
1937
|
return queryManager.fetchQueryObservable(queryId, currentOptions, newNetworkStatus);
|
|
1980
|
-
}, !queryManager.ssrMode && (function () { return !
|
|
1938
|
+
}, !queryManager.ssrMode && (function () { return !isNetworkRequestInFlight(_this.queryInfo.networkStatus); }));
|
|
1981
1939
|
};
|
|
1982
1940
|
ObservableQuery.prototype.reobserve = function (newOptions, newNetworkStatus) {
|
|
1983
1941
|
this.isTornDown = false;
|
|
@@ -2918,6 +2876,11 @@ var defaultDataIdFromObject = function (_a, context) {
|
|
|
2918
2876
|
};
|
|
2919
2877
|
var nullKeyFieldsFn = function () { return void 0; };
|
|
2920
2878
|
var simpleKeyArgsFn = function (_args, context) { return context.fieldName; };
|
|
2879
|
+
var mergeTrueFn = function (existing, incoming, _a) {
|
|
2880
|
+
var mergeObjects = _a.mergeObjects;
|
|
2881
|
+
return mergeObjects(existing, incoming);
|
|
2882
|
+
};
|
|
2883
|
+
var mergeFalseFn = function (_, incoming) { return incoming; };
|
|
2921
2884
|
var Policies = (function () {
|
|
2922
2885
|
function Policies(config) {
|
|
2923
2886
|
this.config = config;
|
|
@@ -3001,8 +2964,11 @@ var Policies = (function () {
|
|
|
3001
2964
|
existing.keyFn;
|
|
3002
2965
|
if (typeof read === "function")
|
|
3003
2966
|
existing.read = read;
|
|
3004
|
-
|
|
3005
|
-
|
|
2967
|
+
existing.merge =
|
|
2968
|
+
typeof merge === "function" ? merge :
|
|
2969
|
+
merge === true ? mergeTrueFn :
|
|
2970
|
+
merge === false ? mergeFalseFn :
|
|
2971
|
+
existing.merge;
|
|
3006
2972
|
}
|
|
3007
2973
|
if (existing.read && existing.merge) {
|
|
3008
2974
|
existing.keyFn = existing.keyFn || simpleKeyArgsFn;
|
|
@@ -3088,6 +3054,7 @@ var Policies = (function () {
|
|
|
3088
3054
|
typename: typename,
|
|
3089
3055
|
fieldName: fieldName,
|
|
3090
3056
|
field: fieldSpec.field || null,
|
|
3057
|
+
variables: fieldSpec.variables,
|
|
3091
3058
|
};
|
|
3092
3059
|
var args = argsFromFieldSpecifier(fieldSpec);
|
|
3093
3060
|
while (keyFn) {
|
|
@@ -3803,6 +3770,9 @@ var QueryInfo = (function () {
|
|
|
3803
3770
|
!equality.equal(this.variables, query.variables)) {
|
|
3804
3771
|
networkStatus = exports.NetworkStatus.setVariables;
|
|
3805
3772
|
}
|
|
3773
|
+
if (!equality.equal(query.variables, this.variables)) {
|
|
3774
|
+
this.diff = null;
|
|
3775
|
+
}
|
|
3806
3776
|
Object.assign(this, {
|
|
3807
3777
|
document: query.document,
|
|
3808
3778
|
variables: query.variables,
|
|
@@ -3818,21 +3788,28 @@ var QueryInfo = (function () {
|
|
|
3818
3788
|
}
|
|
3819
3789
|
return this;
|
|
3820
3790
|
};
|
|
3821
|
-
QueryInfo.prototype.
|
|
3822
|
-
|
|
3823
|
-
if (
|
|
3824
|
-
this.
|
|
3825
|
-
if (!this.notifyTimeout) {
|
|
3826
|
-
this.notifyTimeout = setTimeout(function () { return _this.notify(); }, 0);
|
|
3827
|
-
}
|
|
3791
|
+
QueryInfo.prototype.getDiff = function (variables) {
|
|
3792
|
+
if (variables === void 0) { variables = this.variables; }
|
|
3793
|
+
if (this.diff && equality.equal(variables, this.variables)) {
|
|
3794
|
+
return this.diff;
|
|
3828
3795
|
}
|
|
3829
|
-
|
|
3796
|
+
this.updateWatch(this.variables = variables);
|
|
3797
|
+
return this.diff = this.cache.diff({
|
|
3798
|
+
query: this.document,
|
|
3799
|
+
variables: variables,
|
|
3800
|
+
returnPartialData: true,
|
|
3801
|
+
optimistic: true,
|
|
3802
|
+
});
|
|
3830
3803
|
};
|
|
3831
3804
|
QueryInfo.prototype.setDiff = function (diff) {
|
|
3805
|
+
var _this = this;
|
|
3832
3806
|
var oldDiff = this.diff;
|
|
3833
3807
|
this.diff = diff;
|
|
3834
3808
|
if (!this.dirty && (diff === null || diff === void 0 ? void 0 : diff.result) !== (oldDiff === null || oldDiff === void 0 ? void 0 : oldDiff.result)) {
|
|
3835
|
-
this.
|
|
3809
|
+
this.dirty = true;
|
|
3810
|
+
if (!this.notifyTimeout) {
|
|
3811
|
+
this.notifyTimeout = setTimeout(function () { return _this.notify(); }, 0);
|
|
3812
|
+
}
|
|
3836
3813
|
}
|
|
3837
3814
|
};
|
|
3838
3815
|
QueryInfo.prototype.setObservableQuery = function (oq) {
|
|
@@ -3843,6 +3820,7 @@ var QueryInfo = (function () {
|
|
|
3843
3820
|
}
|
|
3844
3821
|
this.observableQuery = oq;
|
|
3845
3822
|
if (oq) {
|
|
3823
|
+
oq["queryInfo"] = this;
|
|
3846
3824
|
this.listeners.add(this.oqListener = function () { return oq.reobserve(); });
|
|
3847
3825
|
}
|
|
3848
3826
|
else {
|
|
@@ -3877,13 +3855,6 @@ var QueryInfo = (function () {
|
|
|
3877
3855
|
QueryInfo.prototype.stop = function () {
|
|
3878
3856
|
this.cancel();
|
|
3879
3857
|
delete this.cancel;
|
|
3880
|
-
this.variables =
|
|
3881
|
-
this.networkStatus =
|
|
3882
|
-
this.networkError =
|
|
3883
|
-
this.graphQLErrors =
|
|
3884
|
-
this.lastWatch =
|
|
3885
|
-
this.lastWrittenResult =
|
|
3886
|
-
this.lastWrittenVars = void 0;
|
|
3887
3858
|
var oq = this.observableQuery;
|
|
3888
3859
|
if (oq)
|
|
3889
3860
|
oq.stopPolling();
|
|
@@ -3891,6 +3862,11 @@ var QueryInfo = (function () {
|
|
|
3891
3862
|
QueryInfo.prototype.cancel = function () { };
|
|
3892
3863
|
QueryInfo.prototype.updateWatch = function (variables) {
|
|
3893
3864
|
var _this = this;
|
|
3865
|
+
if (variables === void 0) { variables = this.variables; }
|
|
3866
|
+
var oq = this.observableQuery;
|
|
3867
|
+
if (oq && oq.options.fetchPolicy === "no-cache") {
|
|
3868
|
+
return;
|
|
3869
|
+
}
|
|
3894
3870
|
if (!this.lastWatch ||
|
|
3895
3871
|
this.lastWatch.query !== this.document ||
|
|
3896
3872
|
!equality.equal(variables, this.lastWatch.variables)) {
|
|
@@ -3902,7 +3878,6 @@ var QueryInfo = (function () {
|
|
|
3902
3878
|
callback: function (diff) { return _this.setDiff(diff); },
|
|
3903
3879
|
});
|
|
3904
3880
|
}
|
|
3905
|
-
return this;
|
|
3906
3881
|
};
|
|
3907
3882
|
QueryInfo.prototype.markResult = function (result, options, allowCacheWrite) {
|
|
3908
3883
|
var _this = this;
|
|
@@ -3941,6 +3916,7 @@ var QueryInfo = (function () {
|
|
|
3941
3916
|
returnPartialData: true,
|
|
3942
3917
|
optimistic: true,
|
|
3943
3918
|
});
|
|
3919
|
+
_this.updateWatch(options.variables);
|
|
3944
3920
|
_this.diff = diff;
|
|
3945
3921
|
if (diff.complete) {
|
|
3946
3922
|
result.data = diff.result;
|
|
@@ -4176,8 +4152,12 @@ var QueryManager = (function () {
|
|
|
4176
4152
|
});
|
|
4177
4153
|
return store;
|
|
4178
4154
|
};
|
|
4179
|
-
QueryManager.prototype.
|
|
4180
|
-
|
|
4155
|
+
QueryManager.prototype.resetErrors = function (queryId) {
|
|
4156
|
+
var queryInfo = this.queries.get(queryId);
|
|
4157
|
+
if (queryInfo) {
|
|
4158
|
+
queryInfo.networkError = undefined;
|
|
4159
|
+
queryInfo.graphQLErrors = [];
|
|
4160
|
+
}
|
|
4181
4161
|
};
|
|
4182
4162
|
QueryManager.prototype.transform = function (document) {
|
|
4183
4163
|
var transformCache = this.transformCache;
|
|
@@ -4214,11 +4194,14 @@ var QueryManager = (function () {
|
|
|
4214
4194
|
if (typeof options.notifyOnNetworkStatusChange === 'undefined') {
|
|
4215
4195
|
options.notifyOnNetworkStatusChange = false;
|
|
4216
4196
|
}
|
|
4197
|
+
var queryInfo = new QueryInfo(this.cache);
|
|
4217
4198
|
var observable = new ObservableQuery({
|
|
4218
4199
|
queryManager: this,
|
|
4200
|
+
queryInfo: queryInfo,
|
|
4219
4201
|
options: options,
|
|
4220
4202
|
});
|
|
4221
|
-
this.
|
|
4203
|
+
this.queries.set(observable.queryId, queryInfo);
|
|
4204
|
+
queryInfo.init({
|
|
4222
4205
|
document: options.query,
|
|
4223
4206
|
observableQuery: observable,
|
|
4224
4207
|
variables: options.variables,
|
|
@@ -4253,9 +4236,6 @@ var QueryManager = (function () {
|
|
|
4253
4236
|
if (queryInfo)
|
|
4254
4237
|
queryInfo.stop();
|
|
4255
4238
|
};
|
|
4256
|
-
QueryManager.prototype.addQueryListener = function (queryId, listener) {
|
|
4257
|
-
this.getQuery(queryId).listeners.add(listener);
|
|
4258
|
-
};
|
|
4259
4239
|
QueryManager.prototype.clearStore = function () {
|
|
4260
4240
|
this.cancelPendingFetches(process.env.NODE_ENV === "production" ? new tsInvariant.InvariantError(20) : new tsInvariant.InvariantError('Store reset while query was in flight (not completed in link chain)'));
|
|
4261
4241
|
this.queries.forEach(function (queryInfo) {
|
|
@@ -4451,10 +4431,6 @@ var QueryManager = (function () {
|
|
|
4451
4431
|
var queryInfo = this.getQuery(queryId);
|
|
4452
4432
|
var oldNetworkStatus = queryInfo.networkStatus;
|
|
4453
4433
|
var _a = options.fetchPolicy, fetchPolicy = _a === void 0 ? "cache-first" : _a, _b = options.errorPolicy, errorPolicy = _b === void 0 ? "none" : _b, _c = options.returnPartialData, returnPartialData = _c === void 0 ? false : _c, _d = options.notifyOnNetworkStatusChange, notifyOnNetworkStatusChange = _d === void 0 ? false : _d, _e = options.context, context = _e === void 0 ? {} : _e;
|
|
4454
|
-
if (fetchPolicy === "cache-and-network" ||
|
|
4455
|
-
fetchPolicy === "network-only") {
|
|
4456
|
-
options.fetchPolicy = "cache-first";
|
|
4457
|
-
}
|
|
4458
4434
|
var mightUseNetwork = fetchPolicy === "cache-first" ||
|
|
4459
4435
|
fetchPolicy === "cache-and-network" ||
|
|
4460
4436
|
fetchPolicy === "network-only" ||
|
|
@@ -4488,7 +4464,13 @@ var QueryManager = (function () {
|
|
|
4488
4464
|
var concast = new Concast(this.transform(normalized.query).hasClientExports
|
|
4489
4465
|
? this.localState.addExportedVariables(normalized.query, normalized.variables, normalized.context).then(fromVariables)
|
|
4490
4466
|
: fromVariables(normalized.variables));
|
|
4491
|
-
concast.cleanup(function () {
|
|
4467
|
+
concast.cleanup(function () {
|
|
4468
|
+
_this.fetchCancelFns.delete(queryId);
|
|
4469
|
+
if (options.nextFetchPolicy) {
|
|
4470
|
+
options.fetchPolicy = options.nextFetchPolicy;
|
|
4471
|
+
options.nextFetchPolicy = void 0;
|
|
4472
|
+
}
|
|
4473
|
+
});
|
|
4492
4474
|
return concast;
|
|
4493
4475
|
};
|
|
4494
4476
|
QueryManager.prototype.fetchQueryByPolicy = function (queryInfo, options, networkStatus) {
|
|
@@ -4499,13 +4481,8 @@ var QueryManager = (function () {
|
|
|
4499
4481
|
variables: variables,
|
|
4500
4482
|
lastRequestId: this.generateRequestId(),
|
|
4501
4483
|
networkStatus: networkStatus,
|
|
4502
|
-
})
|
|
4503
|
-
var readCache = function () { return
|
|
4504
|
-
query: query,
|
|
4505
|
-
variables: variables,
|
|
4506
|
-
returnPartialData: true,
|
|
4507
|
-
optimistic: true,
|
|
4508
|
-
}); };
|
|
4484
|
+
});
|
|
4485
|
+
var readCache = function () { return queryInfo.getDiff(variables); };
|
|
4509
4486
|
var resultsFromCache = function (diff, networkStatus) {
|
|
4510
4487
|
if (networkStatus === void 0) { networkStatus = queryInfo.networkStatus || exports.NetworkStatus.loading; }
|
|
4511
4488
|
var data = diff.result;
|
|
@@ -4514,11 +4491,7 @@ var QueryManager = (function () {
|
|
|
4514
4491
|
!equality.equal(data, {})) {
|
|
4515
4492
|
process.env.NODE_ENV === "production" || tsInvariant.invariant.warn("Missing cache result fields: " + diff.missing.map(function (m) { return m.path.join('.'); }).join(', '), diff.missing);
|
|
4516
4493
|
}
|
|
4517
|
-
var fromData = function (data) { return Observable.of({
|
|
4518
|
-
data: data,
|
|
4519
|
-
loading: isNetworkRequestInFlight(networkStatus),
|
|
4520
|
-
networkStatus: networkStatus,
|
|
4521
|
-
}); };
|
|
4494
|
+
var fromData = function (data) { return Observable.of(tslib.__assign({ data: data, loading: isNetworkRequestInFlight(networkStatus), networkStatus: networkStatus }, (diff.complete ? null : { partial: true }))); };
|
|
4522
4495
|
if (_this.transform(query).hasForcedResolvers) {
|
|
4523
4496
|
return _this.localState.runResolvers({
|
|
4524
4497
|
document: query,
|
|
@@ -4592,13 +4565,6 @@ var QueryManager = (function () {
|
|
|
4592
4565
|
var newContext = this.localState.prepareContext(context);
|
|
4593
4566
|
return tslib.__assign(tslib.__assign({}, newContext), { clientAwareness: this.clientAwareness });
|
|
4594
4567
|
};
|
|
4595
|
-
QueryManager.prototype.checkInFlight = function (queryId) {
|
|
4596
|
-
var query = this.getQueryStoreValue(queryId);
|
|
4597
|
-
return (!!query &&
|
|
4598
|
-
!!query.networkStatus &&
|
|
4599
|
-
query.networkStatus !== exports.NetworkStatus.ready &&
|
|
4600
|
-
query.networkStatus !== exports.NetworkStatus.error);
|
|
4601
|
-
};
|
|
4602
4568
|
return QueryManager;
|
|
4603
4569
|
}());
|
|
4604
4570
|
function markMutationResult(mutation, cache) {
|
|
@@ -4740,7 +4706,7 @@ var ApolloClient = (function () {
|
|
|
4740
4706
|
};
|
|
4741
4707
|
ApolloClient.prototype.watchQuery = function (options) {
|
|
4742
4708
|
if (this.defaultOptions.watchQuery) {
|
|
4743
|
-
options =
|
|
4709
|
+
options = compact(this.defaultOptions.watchQuery, options);
|
|
4744
4710
|
}
|
|
4745
4711
|
if (this.disableNetworkFetches &&
|
|
4746
4712
|
(options.fetchPolicy === 'network-only' ||
|
|
@@ -4751,7 +4717,7 @@ var ApolloClient = (function () {
|
|
|
4751
4717
|
};
|
|
4752
4718
|
ApolloClient.prototype.query = function (options) {
|
|
4753
4719
|
if (this.defaultOptions.query) {
|
|
4754
|
-
options =
|
|
4720
|
+
options = compact(this.defaultOptions.query, options);
|
|
4755
4721
|
}
|
|
4756
4722
|
process.env.NODE_ENV === "production" ? tsInvariant.invariant(options.fetchPolicy !== 'cache-and-network', 10) : tsInvariant.invariant(options.fetchPolicy !== 'cache-and-network', 'The cache-and-network fetchPolicy does not work with client.query, because ' +
|
|
4757
4723
|
'client.query can only return a single result. Please use client.watchQuery ' +
|
|
@@ -4764,7 +4730,7 @@ var ApolloClient = (function () {
|
|
|
4764
4730
|
};
|
|
4765
4731
|
ApolloClient.prototype.mutate = function (options) {
|
|
4766
4732
|
if (this.defaultOptions.mutate) {
|
|
4767
|
-
options =
|
|
4733
|
+
options = compact(this.defaultOptions.mutate, options);
|
|
4768
4734
|
}
|
|
4769
4735
|
return this.queryManager.mutate(options);
|
|
4770
4736
|
};
|
|
@@ -5172,7 +5138,7 @@ var MutationData = (function (_super) {
|
|
|
5172
5138
|
MutationData.prototype.cleanup = function () {
|
|
5173
5139
|
};
|
|
5174
5140
|
MutationData.prototype.mutate = function (mutationFunctionOptions) {
|
|
5175
|
-
return this.refreshClient().client.mutate(
|
|
5141
|
+
return this.refreshClient().client.mutate(compact(this.getOptions(), mutationFunctionOptions));
|
|
5176
5142
|
};
|
|
5177
5143
|
MutationData.prototype.onMutationStart = function () {
|
|
5178
5144
|
if (!this.result.loading && !this.getOptions().ignoreResults) {
|