@apollo/client 3.4.0-rc.7 → 3.4.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/apollo-client.cjs.js +300 -263
- package/apollo-client.cjs.js.map +1 -1
- package/apollo-client.cjs.min.js +1 -1
- package/cache/cache.cjs.js +105 -41
- package/cache/cache.cjs.js.map +1 -1
- package/cache/core/types/DataProxy.js +1 -0
- package/cache/index.d.ts +0 -1
- package/cache/index.d.ts.map +1 -1
- package/cache/index.js +3 -1
- package/cache/index.js.map +1 -1
- package/cache/inmemory/entityStore.d.ts +3 -2
- package/cache/inmemory/entityStore.d.ts.map +1 -1
- package/cache/inmemory/entityStore.js +22 -10
- package/cache/inmemory/entityStore.js.map +1 -1
- package/cache/inmemory/fixPolyfills.native.js +1 -0
- package/cache/inmemory/helpers.d.ts +1 -1
- package/cache/inmemory/helpers.d.ts.map +1 -1
- package/cache/inmemory/inMemoryCache.d.ts +5 -1
- package/cache/inmemory/inMemoryCache.d.ts.map +1 -1
- package/cache/inmemory/inMemoryCache.js +24 -3
- package/cache/inmemory/inMemoryCache.js.map +1 -1
- package/cache/inmemory/object-canon.d.ts +3 -1
- package/cache/inmemory/object-canon.d.ts.map +1 -1
- package/cache/inmemory/object-canon.js +12 -7
- package/cache/inmemory/object-canon.js.map +1 -1
- package/cache/inmemory/policies.d.ts.map +1 -1
- package/cache/inmemory/policies.js +23 -10
- package/cache/inmemory/policies.js.map +1 -1
- package/cache/inmemory/readFromStore.d.ts +5 -2
- package/cache/inmemory/readFromStore.d.ts.map +1 -1
- package/cache/inmemory/readFromStore.js +9 -6
- package/cache/inmemory/readFromStore.js.map +1 -1
- package/cache/inmemory/types.js +1 -0
- package/cache/inmemory/writeToStore.d.ts +1 -0
- package/cache/inmemory/writeToStore.d.ts.map +1 -1
- package/cache/inmemory/writeToStore.js +16 -7
- package/cache/inmemory/writeToStore.js.map +1 -1
- package/core/ApolloClient.d.ts.map +1 -1
- package/core/ApolloClient.js +3 -0
- package/core/ApolloClient.js.map +1 -1
- package/core/LocalState.js +2 -4
- package/core/LocalState.js.map +1 -1
- package/core/ObservableQuery.d.ts +7 -6
- package/core/ObservableQuery.d.ts.map +1 -1
- package/core/ObservableQuery.js +116 -78
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryInfo.d.ts +0 -1
- package/core/QueryInfo.d.ts.map +1 -1
- package/core/QueryInfo.js +3 -6
- package/core/QueryInfo.js.map +1 -1
- package/core/QueryManager.d.ts +3 -3
- package/core/QueryManager.d.ts.map +1 -1
- package/core/QueryManager.js +13 -10
- package/core/QueryManager.js.map +1 -1
- package/core/core.cjs.js +137 -181
- package/core/core.cjs.js.map +1 -1
- package/core/index.d.ts +0 -1
- package/core/index.d.ts.map +1 -1
- package/core/index.js +2 -2
- package/core/index.js.map +1 -1
- package/core/types.d.ts +4 -1
- package/core/types.d.ts.map +1 -1
- package/core/types.js +1 -0
- package/core/types.js.map +1 -1
- package/core/watchQueryOptions.js +1 -0
- package/errors/errors.cjs.js +2 -0
- package/errors/errors.cjs.js.map +1 -1
- package/errors/index.d.ts.map +1 -1
- package/errors/index.js +3 -0
- package/errors/index.js.map +1 -1
- package/invariantErrorCodes.js +82 -57
- package/link/context/context.cjs.js +4 -0
- package/link/context/context.cjs.js.map +1 -1
- package/link/context/index.d.ts.map +1 -1
- package/link/context/index.js +4 -0
- package/link/context/index.js.map +1 -1
- package/link/core/ApolloLink.js +1 -1
- package/link/core/core.cjs.js +4 -2
- package/link/core/core.cjs.js.map +1 -1
- package/link/core/index.d.ts.map +1 -1
- package/link/core/index.js +3 -0
- package/link/core/index.js.map +1 -1
- package/link/core/types.js +1 -0
- package/link/http/checkFetcher.js +1 -1
- package/link/http/http.cjs.js +13 -3
- package/link/http/http.cjs.js.map +1 -1
- package/link/http/selectHttpOptionsAndBody.d.ts.map +1 -1
- package/link/http/selectHttpOptionsAndBody.js +11 -1
- package/link/http/selectHttpOptionsAndBody.js.map +1 -1
- package/link/http/serializeFetchParameter.js +1 -1
- package/link/persisted-queries/index.d.ts.map +1 -1
- package/link/persisted-queries/index.js +2 -2
- package/link/persisted-queries/persisted-queries.cjs.js +2 -2
- package/link/persisted-queries/persisted-queries.cjs.js.map +1 -1
- package/link/utils/utils.cjs.js +1 -1
- package/link/utils/utils.cjs.js.map +1 -1
- package/link/utils/validateOperation.js +1 -1
- package/package.json +20 -20
- package/react/components/Mutation.d.ts +1 -1
- package/react/components/Query.js +1 -1
- package/react/components/Query.js.map +1 -1
- package/react/components/components.cjs.js +45 -31
- package/react/components/components.cjs.js.map +1 -1
- package/react/components/types.js +1 -0
- package/react/context/ApolloConsumer.js +1 -1
- package/react/context/ApolloProvider.js +1 -1
- package/react/context/context.cjs.js +22 -8
- package/react/context/context.cjs.js.map +1 -1
- package/react/data/OperationData.js +2 -2
- package/react/data/QueryData.d.ts +1 -2
- package/react/data/QueryData.d.ts.map +1 -1
- package/react/data/QueryData.js +65 -72
- package/react/data/QueryData.js.map +1 -1
- package/react/data/data.cjs.js +65 -71
- package/react/data/data.cjs.js.map +1 -1
- package/react/hoc/hoc-utils.d.ts +2 -1
- package/react/hoc/hoc-utils.d.ts.map +1 -1
- package/react/hoc/hoc-utils.js +1 -1
- package/react/hoc/hoc.cjs.js +35 -18
- package/react/hoc/hoc.cjs.js.map +1 -1
- package/react/hoc/mutation-hoc.d.ts.map +1 -1
- package/react/hoc/query-hoc.d.ts.map +1 -1
- package/react/hoc/subscription-hoc.d.ts.map +1 -1
- package/react/hoc/types.js +1 -0
- package/react/hoc/withApollo.js +1 -1
- package/react/hooks/hooks.cjs.js +56 -10
- package/react/hooks/hooks.cjs.js.map +1 -1
- package/react/hooks/useApolloClient.js +1 -1
- package/react/hooks/useSubscription.d.ts.map +1 -1
- package/react/hooks/useSubscription.js +16 -6
- package/react/hooks/useSubscription.js.map +1 -1
- package/react/hooks/utils/useAfterFastRefresh.d.ts +2 -0
- package/react/hooks/utils/useAfterFastRefresh.d.ts.map +1 -0
- package/react/hooks/utils/useAfterFastRefresh.js +18 -0
- package/react/hooks/utils/useAfterFastRefresh.js.map +1 -0
- package/react/hooks/utils/useBaseQuery.d.ts.map +1 -1
- package/react/hooks/utils/useBaseQuery.js +10 -3
- package/react/hooks/utils/useBaseQuery.js.map +1 -1
- package/react/index.d.ts +0 -1
- package/react/index.d.ts.map +1 -1
- package/react/index.js +3 -1
- package/react/index.js.map +1 -1
- package/react/parser/index.js +4 -4
- package/react/parser/parser.cjs.js +4 -4
- package/react/parser/parser.cjs.js.map +1 -1
- package/react/react.cjs.js +2 -2
- package/react/react.cjs.js.map +1 -1
- package/react/ssr/ssr.cjs.js +15 -1
- package/react/ssr/ssr.cjs.js.map +1 -1
- package/react/types/types.d.ts +9 -3
- package/react/types/types.d.ts.map +1 -1
- package/react/types/types.js +1 -0
- package/react/types/types.js.map +1 -1
- package/testing/index.d.ts.map +1 -1
- package/testing/index.js +3 -0
- package/testing/index.js.map +1 -1
- package/testing/testing.cjs.js +68 -17
- package/testing/testing.cjs.js.map +1 -1
- package/utilities/common/canUse.d.ts +1 -0
- package/utilities/common/canUse.d.ts.map +1 -1
- package/utilities/common/canUse.js +1 -0
- package/utilities/common/canUse.js.map +1 -1
- package/utilities/common/global.d.ts.map +1 -1
- package/utilities/common/mergeDeep.js +2 -2
- package/utilities/common/mergeDeep.js.map +1 -1
- package/utilities/common/stringifyForDisplay.d.ts +2 -0
- package/utilities/common/stringifyForDisplay.d.ts.map +1 -0
- package/utilities/common/stringifyForDisplay.js +8 -0
- package/utilities/common/stringifyForDisplay.js.map +1 -0
- package/utilities/globals/DEV.d.ts +3 -0
- package/utilities/globals/DEV.d.ts.map +1 -0
- package/utilities/globals/DEV.js +20 -0
- package/utilities/globals/DEV.js.map +1 -0
- package/utilities/globals/graphql.d.ts +1 -1
- package/utilities/globals/graphql.d.ts.map +1 -1
- package/utilities/globals/graphql.js +3 -3
- package/utilities/globals/graphql.js.map +1 -1
- package/utilities/globals/index.d.ts +4 -2
- package/utilities/globals/index.d.ts.map +1 -1
- package/utilities/globals/index.js +5 -4
- package/utilities/globals/index.js.map +1 -1
- package/utilities/graphql/directives.js +4 -4
- package/utilities/graphql/fragments.js +5 -5
- package/utilities/graphql/getFromAST.js +8 -8
- package/utilities/graphql/storeUtils.d.ts.map +1 -1
- package/utilities/graphql/storeUtils.js +1 -1
- package/utilities/graphql/transform.js +2 -2
- package/utilities/graphql/transform.js.map +1 -1
- package/utilities/index.d.ts +3 -1
- package/utilities/index.d.ts.map +1 -1
- package/utilities/index.js +5 -1
- package/utilities/index.js.map +1 -1
- package/utilities/package.json +3 -1
- package/utilities/policies/pagination.d.ts.map +1 -1
- package/utilities/policies/pagination.js +10 -11
- package/utilities/policies/pagination.js.map +1 -1
- package/utilities/testing/index.d.ts +1 -0
- package/utilities/testing/index.d.ts.map +1 -1
- package/utilities/testing/index.js +1 -0
- package/utilities/testing/index.js.map +1 -1
- package/utilities/testing/itAsync.d.ts +5 -8
- package/utilities/testing/itAsync.d.ts.map +1 -1
- package/utilities/testing/itAsync.js +6 -7
- package/utilities/testing/itAsync.js.map +1 -1
- package/utilities/testing/mocking/mockFetch.js +2 -2
- package/utilities/testing/mocking/mockFetch.js.map +1 -1
- package/utilities/testing/mocking/mockLink.d.ts.map +1 -1
- package/utilities/testing/mocking/mockLink.js +2 -8
- package/utilities/testing/mocking/mockLink.js.map +1 -1
- package/utilities/testing/mocking/mockWatchQuery.d.ts.map +1 -1
- package/utilities/testing/mocking/mockWatchQuery.js +2 -2
- package/utilities/testing/mocking/mockWatchQuery.js.map +1 -1
- package/utilities/testing/observableToPromise.js +2 -2
- package/utilities/testing/observableToPromise.js.map +1 -1
- package/utilities/testing/withConsoleSpy.d.ts +4 -0
- package/utilities/testing/withConsoleSpy.d.ts.map +1 -0
- package/utilities/testing/withConsoleSpy.js +39 -0
- package/utilities/testing/withConsoleSpy.js.map +1 -0
- package/utilities/types/IsStrictlyAny.js +1 -0
- package/utilities/utilities.cjs.js +56 -48
- package/utilities/utilities.cjs.js.map +1 -1
- package/version.js +1 -1
- package/core/Reobserver.d.ts +0 -18
- package/core/Reobserver.d.ts.map +0 -1
- package/core/Reobserver.js +0 -87
- package/core/Reobserver.js.map +0 -1
- package/utilities/globals/__DEV__.d.ts +0 -3
- package/utilities/globals/__DEV__.d.ts.map +0 -1
- package/utilities/globals/__DEV__.js +0 -32
- package/utilities/globals/__DEV__.js.map +0 -1
- package/utilities/globals/process.d.ts +0 -2
- package/utilities/globals/process.d.ts.map +0 -1
- package/utilities/globals/process.js +0 -31
- package/utilities/globals/process.js.map +0 -1
package/core/core.cjs.js
CHANGED
|
@@ -14,7 +14,7 @@ var graphql = require('graphql');
|
|
|
14
14
|
var utils = require('../link/utils');
|
|
15
15
|
var graphqlTag = require('graphql-tag');
|
|
16
16
|
|
|
17
|
-
var version = '3.4.
|
|
17
|
+
var version = '3.4.1';
|
|
18
18
|
|
|
19
19
|
exports.NetworkStatus = void 0;
|
|
20
20
|
(function (NetworkStatus) {
|
|
@@ -30,95 +30,35 @@ function isNetworkRequestInFlight(networkStatus) {
|
|
|
30
30
|
return networkStatus ? networkStatus < 7 : false;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
var Reobserver = (function () {
|
|
34
|
-
function Reobserver(observer, options, fetch, shouldFetch) {
|
|
35
|
-
this.observer = observer;
|
|
36
|
-
this.options = options;
|
|
37
|
-
this.fetch = fetch;
|
|
38
|
-
this.shouldFetch = shouldFetch;
|
|
39
|
-
}
|
|
40
|
-
Reobserver.prototype.reobserve = function (newOptions, newNetworkStatus) {
|
|
41
|
-
if (newOptions) {
|
|
42
|
-
this.updateOptions(newOptions);
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
this.updatePolling();
|
|
46
|
-
}
|
|
47
|
-
var concast = this.fetch(this.options, newNetworkStatus);
|
|
48
|
-
if (this.concast) {
|
|
49
|
-
this.concast.removeObserver(this.observer, true);
|
|
50
|
-
}
|
|
51
|
-
concast.addObserver(this.observer);
|
|
52
|
-
return (this.concast = concast).promise;
|
|
53
|
-
};
|
|
54
|
-
Reobserver.prototype.updateOptions = function (newOptions) {
|
|
55
|
-
Object.assign(this.options, utilities.compact(newOptions));
|
|
56
|
-
this.updatePolling();
|
|
57
|
-
return this;
|
|
58
|
-
};
|
|
59
|
-
Reobserver.prototype.stop = function () {
|
|
60
|
-
if (this.concast) {
|
|
61
|
-
this.concast.removeObserver(this.observer);
|
|
62
|
-
delete this.concast;
|
|
63
|
-
}
|
|
64
|
-
if (this.pollingInfo) {
|
|
65
|
-
clearTimeout(this.pollingInfo.timeout);
|
|
66
|
-
this.options.pollInterval = 0;
|
|
67
|
-
this.updatePolling();
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
Reobserver.prototype.updatePolling = function () {
|
|
71
|
-
var _this = this;
|
|
72
|
-
var _a = this, pollingInfo = _a.pollingInfo, pollInterval = _a.options.pollInterval;
|
|
73
|
-
if (!pollInterval) {
|
|
74
|
-
if (pollingInfo) {
|
|
75
|
-
clearTimeout(pollingInfo.timeout);
|
|
76
|
-
delete this.pollingInfo;
|
|
77
|
-
}
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
if (pollingInfo &&
|
|
81
|
-
pollingInfo.interval === pollInterval) {
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
__DEV__ ? tsInvariant.invariant(pollInterval, 'Attempted to start a polling query without a polling interval.') : tsInvariant.invariant(pollInterval, 21);
|
|
85
|
-
if (this.shouldFetch === false) {
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
var info = pollingInfo || (this.pollingInfo = {});
|
|
89
|
-
info.interval = pollInterval;
|
|
90
|
-
var maybeFetch = function () {
|
|
91
|
-
if (_this.pollingInfo) {
|
|
92
|
-
if (_this.shouldFetch && _this.shouldFetch()) {
|
|
93
|
-
_this.reobserve({
|
|
94
|
-
fetchPolicy: "network-only",
|
|
95
|
-
nextFetchPolicy: _this.options.fetchPolicy || "cache-first",
|
|
96
|
-
}, exports.NetworkStatus.poll).then(poll, poll);
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
poll();
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
var poll = function () {
|
|
104
|
-
var info = _this.pollingInfo;
|
|
105
|
-
if (info) {
|
|
106
|
-
clearTimeout(info.timeout);
|
|
107
|
-
info.timeout = setTimeout(maybeFetch, info.interval);
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
poll();
|
|
111
|
-
};
|
|
112
|
-
return Reobserver;
|
|
113
|
-
}());
|
|
114
|
-
|
|
115
33
|
var warnedAboutUpdateQuery = false;
|
|
116
34
|
var ObservableQuery = (function (_super) {
|
|
117
35
|
tslib.__extends(ObservableQuery, _super);
|
|
118
36
|
function ObservableQuery(_a) {
|
|
119
37
|
var queryManager = _a.queryManager, queryInfo = _a.queryInfo, options = _a.options;
|
|
120
38
|
var _this = _super.call(this, function (observer) {
|
|
121
|
-
|
|
39
|
+
try {
|
|
40
|
+
var subObserver = observer._subscription._observer;
|
|
41
|
+
if (subObserver && !subObserver.error) {
|
|
42
|
+
subObserver.error = defaultSubscriptionObserverErrorCallback;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
catch (_a) { }
|
|
46
|
+
var first = !_this.observers.size;
|
|
47
|
+
_this.observers.add(observer);
|
|
48
|
+
if (_this.lastError) {
|
|
49
|
+
observer.error && observer.error(_this.lastError);
|
|
50
|
+
}
|
|
51
|
+
else if (_this.lastResult) {
|
|
52
|
+
observer.next && observer.next(_this.lastResult);
|
|
53
|
+
}
|
|
54
|
+
if (first) {
|
|
55
|
+
_this.reobserve().catch(function () { });
|
|
56
|
+
}
|
|
57
|
+
return function () {
|
|
58
|
+
if (_this.observers.delete(observer) && !_this.observers.size) {
|
|
59
|
+
_this.tearDownQuery();
|
|
60
|
+
}
|
|
61
|
+
};
|
|
122
62
|
}) || this;
|
|
123
63
|
_this.observers = new Set();
|
|
124
64
|
_this.subscriptions = new Set();
|
|
@@ -139,6 +79,7 @@ var ObservableQuery = (function (_super) {
|
|
|
139
79
|
_this.queryId = queryManager.generateQueryId();
|
|
140
80
|
var opDef = utilities.getOperationDefinition(options.query);
|
|
141
81
|
_this.queryName = opDef && opDef.name && opDef.name.value;
|
|
82
|
+
_this.initialFetchPolicy = options.fetchPolicy || "cache-first";
|
|
142
83
|
_this.queryManager = queryManager;
|
|
143
84
|
_this.queryInfo = queryInfo;
|
|
144
85
|
return _this;
|
|
@@ -171,21 +112,12 @@ var ObservableQuery = (function (_super) {
|
|
|
171
112
|
};
|
|
172
113
|
ObservableQuery.prototype.getCurrentResult = function (saveAsLastResult) {
|
|
173
114
|
if (saveAsLastResult === void 0) { saveAsLastResult = true; }
|
|
174
|
-
var lastResult =
|
|
115
|
+
var _a = this, lastResult = _a.lastResult, _b = _a.options.fetchPolicy, fetchPolicy = _b === void 0 ? "cache-first" : _b;
|
|
175
116
|
var networkStatus = this.queryInfo.networkStatus ||
|
|
176
117
|
(lastResult && lastResult.networkStatus) ||
|
|
177
118
|
exports.NetworkStatus.ready;
|
|
178
119
|
var result = tslib.__assign(tslib.__assign({}, lastResult), { loading: isNetworkRequestInFlight(networkStatus), networkStatus: networkStatus });
|
|
179
|
-
if (this.
|
|
180
|
-
return result;
|
|
181
|
-
}
|
|
182
|
-
var _a = this.options.fetchPolicy, fetchPolicy = _a === void 0 ? 'cache-first' : _a;
|
|
183
|
-
if (fetchPolicy === 'no-cache' ||
|
|
184
|
-
fetchPolicy === 'network-only') {
|
|
185
|
-
delete result.partial;
|
|
186
|
-
}
|
|
187
|
-
else if (!result.data ||
|
|
188
|
-
!this.queryManager.transform(this.options.query).hasForcedResolvers) {
|
|
120
|
+
if (!this.queryManager.transform(this.options.query).hasForcedResolvers) {
|
|
189
121
|
var diff = this.queryInfo.getDiff();
|
|
190
122
|
result.data = (diff.complete ||
|
|
191
123
|
this.options.returnPartialData) ? diff.result : void 0;
|
|
@@ -198,7 +130,7 @@ var ObservableQuery = (function (_super) {
|
|
|
198
130
|
}
|
|
199
131
|
delete result.partial;
|
|
200
132
|
}
|
|
201
|
-
else {
|
|
133
|
+
else if (fetchPolicy !== "no-cache") {
|
|
202
134
|
result.partial = true;
|
|
203
135
|
}
|
|
204
136
|
if (!diff.complete &&
|
|
@@ -237,16 +169,17 @@ var ObservableQuery = (function (_super) {
|
|
|
237
169
|
pollInterval: 0,
|
|
238
170
|
};
|
|
239
171
|
var fetchPolicy = this.options.fetchPolicy;
|
|
240
|
-
if (fetchPolicy
|
|
241
|
-
fetchPolicy
|
|
172
|
+
if (fetchPolicy === 'no-cache') {
|
|
173
|
+
reobserveOptions.fetchPolicy = 'no-cache';
|
|
174
|
+
}
|
|
175
|
+
else if (fetchPolicy !== 'cache-and-network') {
|
|
242
176
|
reobserveOptions.fetchPolicy = 'network-only';
|
|
243
|
-
reobserveOptions.nextFetchPolicy = fetchPolicy || "cache-first";
|
|
244
177
|
}
|
|
245
178
|
if (variables && !equality.equal(this.options.variables, variables)) {
|
|
246
179
|
reobserveOptions.variables = this.options.variables = tslib.__assign(tslib.__assign({}, this.options.variables), variables);
|
|
247
180
|
}
|
|
248
181
|
this.queryInfo.resetLastWrite();
|
|
249
|
-
return this.
|
|
182
|
+
return this.reobserve(reobserveOptions, exports.NetworkStatus.refetch);
|
|
250
183
|
};
|
|
251
184
|
ObservableQuery.prototype.fetchMore = function (fetchMoreOptions) {
|
|
252
185
|
var _this = this;
|
|
@@ -332,18 +265,10 @@ var ObservableQuery = (function (_super) {
|
|
|
332
265
|
if (!this.observers.size) {
|
|
333
266
|
return Promise.resolve();
|
|
334
267
|
}
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
fetchPolicy: fetchPolicy,
|
|
268
|
+
return this.reobserve({
|
|
269
|
+
fetchPolicy: this.initialFetchPolicy,
|
|
338
270
|
variables: variables,
|
|
339
|
-
};
|
|
340
|
-
if (fetchPolicy !== 'cache-first' &&
|
|
341
|
-
fetchPolicy !== 'no-cache' &&
|
|
342
|
-
fetchPolicy !== 'network-only') {
|
|
343
|
-
reobserveOptions.fetchPolicy = 'cache-and-network';
|
|
344
|
-
reobserveOptions.nextFetchPolicy = fetchPolicy;
|
|
345
|
-
}
|
|
346
|
-
return this.reobserve(reobserveOptions, exports.NetworkStatus.setVariables);
|
|
271
|
+
}, exports.NetworkStatus.setVariables);
|
|
347
272
|
};
|
|
348
273
|
ObservableQuery.prototype.updateQuery = function (mapFn) {
|
|
349
274
|
var _a;
|
|
@@ -368,12 +293,57 @@ var ObservableQuery = (function (_super) {
|
|
|
368
293
|
}
|
|
369
294
|
};
|
|
370
295
|
ObservableQuery.prototype.startPolling = function (pollInterval) {
|
|
371
|
-
this.
|
|
296
|
+
this.options.pollInterval = pollInterval;
|
|
297
|
+
this.updatePolling();
|
|
372
298
|
};
|
|
373
299
|
ObservableQuery.prototype.stopPolling = function () {
|
|
374
|
-
|
|
375
|
-
|
|
300
|
+
this.options.pollInterval = 0;
|
|
301
|
+
this.updatePolling();
|
|
302
|
+
};
|
|
303
|
+
ObservableQuery.prototype.fetch = function (options, newNetworkStatus) {
|
|
304
|
+
this.queryManager.setObservableQuery(this);
|
|
305
|
+
return this.queryManager.fetchQueryObservable(this.queryId, options, newNetworkStatus);
|
|
306
|
+
};
|
|
307
|
+
ObservableQuery.prototype.updatePolling = function () {
|
|
308
|
+
var _this = this;
|
|
309
|
+
if (this.queryManager.ssrMode) {
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
var _a = this, pollingInfo = _a.pollingInfo, pollInterval = _a.options.pollInterval;
|
|
313
|
+
if (!pollInterval) {
|
|
314
|
+
if (pollingInfo) {
|
|
315
|
+
clearTimeout(pollingInfo.timeout);
|
|
316
|
+
delete this.pollingInfo;
|
|
317
|
+
}
|
|
318
|
+
return;
|
|
376
319
|
}
|
|
320
|
+
if (pollingInfo &&
|
|
321
|
+
pollingInfo.interval === pollInterval) {
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
__DEV__ ? tsInvariant.invariant(pollInterval, 'Attempted to start a polling query without a polling interval.') : tsInvariant.invariant(pollInterval, 13);
|
|
325
|
+
var info = pollingInfo || (this.pollingInfo = {});
|
|
326
|
+
info.interval = pollInterval;
|
|
327
|
+
var maybeFetch = function () {
|
|
328
|
+
if (_this.pollingInfo) {
|
|
329
|
+
if (!isNetworkRequestInFlight(_this.queryInfo.networkStatus)) {
|
|
330
|
+
_this.reobserve({
|
|
331
|
+
fetchPolicy: "network-only",
|
|
332
|
+
}, exports.NetworkStatus.poll).then(poll, poll);
|
|
333
|
+
}
|
|
334
|
+
else {
|
|
335
|
+
poll();
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
var poll = function () {
|
|
340
|
+
var info = _this.pollingInfo;
|
|
341
|
+
if (info) {
|
|
342
|
+
clearTimeout(info.timeout);
|
|
343
|
+
info.timeout = setTimeout(maybeFetch, info.interval);
|
|
344
|
+
}
|
|
345
|
+
};
|
|
346
|
+
poll();
|
|
377
347
|
};
|
|
378
348
|
ObservableQuery.prototype.updateLastResult = function (newResult) {
|
|
379
349
|
var previousResult = this.lastResult;
|
|
@@ -386,50 +356,36 @@ var ObservableQuery = (function (_super) {
|
|
|
386
356
|
}
|
|
387
357
|
return previousResult;
|
|
388
358
|
};
|
|
389
|
-
ObservableQuery.prototype.
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
359
|
+
ObservableQuery.prototype.reobserve = function (newOptions, newNetworkStatus) {
|
|
360
|
+
this.isTornDown = false;
|
|
361
|
+
var useDisposableConcast = newNetworkStatus === exports.NetworkStatus.refetch ||
|
|
362
|
+
newNetworkStatus === exports.NetworkStatus.fetchMore ||
|
|
363
|
+
newNetworkStatus === exports.NetworkStatus.poll;
|
|
364
|
+
var oldVariables = this.options.variables;
|
|
365
|
+
var options = useDisposableConcast
|
|
366
|
+
? utilities.compact(this.options, newOptions)
|
|
367
|
+
: Object.assign(this.options, utilities.compact(newOptions));
|
|
368
|
+
if (!useDisposableConcast) {
|
|
369
|
+
this.updatePolling();
|
|
370
|
+
if (newOptions &&
|
|
371
|
+
newOptions.variables &&
|
|
372
|
+
!newOptions.fetchPolicy &&
|
|
373
|
+
!equality.equal(newOptions.variables, oldVariables)) {
|
|
374
|
+
options.fetchPolicy = this.initialFetchPolicy;
|
|
375
|
+
if (newNetworkStatus === void 0) {
|
|
376
|
+
newNetworkStatus = exports.NetworkStatus.setVariables;
|
|
377
|
+
}
|
|
398
378
|
}
|
|
399
379
|
}
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
observer.error && observer.error(this.lastError);
|
|
405
|
-
}
|
|
406
|
-
else if (this.lastResult) {
|
|
407
|
-
observer.next && observer.next(this.lastResult);
|
|
408
|
-
}
|
|
409
|
-
if (first) {
|
|
410
|
-
this.reobserve().catch(function () { });
|
|
411
|
-
}
|
|
412
|
-
return function () {
|
|
413
|
-
if (_this.observers.delete(observer) && !_this.observers.size) {
|
|
414
|
-
_this.tearDownQuery();
|
|
380
|
+
var concast = this.fetch(options, newNetworkStatus);
|
|
381
|
+
if (!useDisposableConcast) {
|
|
382
|
+
if (this.concast) {
|
|
383
|
+
this.concast.removeObserver(this.observer, true);
|
|
415
384
|
}
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
return
|
|
420
|
-
};
|
|
421
|
-
ObservableQuery.prototype.newReobserver = function (shareOptions) {
|
|
422
|
-
var _this = this;
|
|
423
|
-
var _a = this, queryManager = _a.queryManager, queryId = _a.queryId;
|
|
424
|
-
queryManager.setObservableQuery(this);
|
|
425
|
-
return new Reobserver(this.observer, shareOptions ? this.options : tslib.__assign({}, this.options), function (currentOptions, newNetworkStatus) {
|
|
426
|
-
queryManager.setObservableQuery(_this);
|
|
427
|
-
return queryManager.fetchQueryObservable(queryId, currentOptions, newNetworkStatus);
|
|
428
|
-
}, !queryManager.ssrMode && (function () { return !isNetworkRequestInFlight(_this.queryInfo.networkStatus); }));
|
|
429
|
-
};
|
|
430
|
-
ObservableQuery.prototype.reobserve = function (newOptions, newNetworkStatus) {
|
|
431
|
-
this.isTornDown = false;
|
|
432
|
-
return this.getReobserver().reobserve(newOptions, newNetworkStatus);
|
|
385
|
+
this.concast = concast;
|
|
386
|
+
}
|
|
387
|
+
concast.addObserver(this.observer);
|
|
388
|
+
return concast.promise;
|
|
433
389
|
};
|
|
434
390
|
ObservableQuery.prototype.observe = function () {
|
|
435
391
|
this.observer.next(this.getCurrentResult(false));
|
|
@@ -440,10 +396,11 @@ var ObservableQuery = (function (_super) {
|
|
|
440
396
|
ObservableQuery.prototype.tearDownQuery = function () {
|
|
441
397
|
if (this.isTornDown)
|
|
442
398
|
return;
|
|
443
|
-
if (this.
|
|
444
|
-
this.
|
|
445
|
-
delete this.
|
|
399
|
+
if (this.concast) {
|
|
400
|
+
this.concast.removeObserver(this.observer);
|
|
401
|
+
delete this.concast;
|
|
446
402
|
}
|
|
403
|
+
this.stopPolling();
|
|
447
404
|
this.subscriptions.forEach(function (sub) { return sub.unsubscribe(); });
|
|
448
405
|
this.subscriptions.clear();
|
|
449
406
|
this.queryManager.stopQuery(this.queryId);
|
|
@@ -459,7 +416,6 @@ function defaultSubscriptionObserverErrorCallback(error) {
|
|
|
459
416
|
function applyNextFetchPolicy(options) {
|
|
460
417
|
var _a = options.fetchPolicy, fetchPolicy = _a === void 0 ? "cache-first" : _a, nextFetchPolicy = options.nextFetchPolicy;
|
|
461
418
|
if (nextFetchPolicy) {
|
|
462
|
-
options.nextFetchPolicy = void 0;
|
|
463
419
|
options.fetchPolicy = typeof nextFetchPolicy === "function"
|
|
464
420
|
? nextFetchPolicy.call(options, fetchPolicy)
|
|
465
421
|
: nextFetchPolicy;
|
|
@@ -529,8 +485,7 @@ var LocalState = (function () {
|
|
|
529
485
|
};
|
|
530
486
|
LocalState.prototype.prepareContext = function (context) {
|
|
531
487
|
var cache = this.cache;
|
|
532
|
-
return tslib.__assign(tslib.__assign({}, context), { cache: cache,
|
|
533
|
-
getCacheKey: function (obj) {
|
|
488
|
+
return tslib.__assign(tslib.__assign({}, context), { cache: cache, getCacheKey: function (obj) {
|
|
534
489
|
return cache.identify(obj);
|
|
535
490
|
} });
|
|
536
491
|
};
|
|
@@ -594,8 +549,7 @@ var LocalState = (function () {
|
|
|
594
549
|
_a = this, cache = _a.cache, client = _a.client;
|
|
595
550
|
execContext = {
|
|
596
551
|
fragmentMap: fragmentMap,
|
|
597
|
-
context: tslib.__assign(tslib.__assign({}, context), { cache: cache,
|
|
598
|
-
client: client }),
|
|
552
|
+
context: tslib.__assign(tslib.__assign({}, context), { cache: cache, client: client }),
|
|
599
553
|
variables: variables,
|
|
600
554
|
fragmentMatcher: fragmentMatcher,
|
|
601
555
|
defaultOperationType: defaultOperationType,
|
|
@@ -815,12 +769,13 @@ var QueryInfo = (function () {
|
|
|
815
769
|
};
|
|
816
770
|
QueryInfo.prototype.getDiffOptions = function (variables) {
|
|
817
771
|
if (variables === void 0) { variables = this.variables; }
|
|
772
|
+
var oq = this.observableQuery;
|
|
818
773
|
return {
|
|
819
774
|
query: this.document,
|
|
820
775
|
variables: variables,
|
|
821
776
|
returnPartialData: true,
|
|
822
777
|
optimistic: true,
|
|
823
|
-
canonizeResults:
|
|
778
|
+
canonizeResults: !oq || oq.options.canonizeResults !== false,
|
|
824
779
|
};
|
|
825
780
|
};
|
|
826
781
|
QueryInfo.prototype.setDiff = function (diff) {
|
|
@@ -907,10 +862,6 @@ var QueryInfo = (function () {
|
|
|
907
862
|
this.cancel = this.cache.watch(this.lastWatch = watchOptions);
|
|
908
863
|
}
|
|
909
864
|
};
|
|
910
|
-
QueryInfo.prototype.canonize = function () {
|
|
911
|
-
var oq = this.observableQuery;
|
|
912
|
-
return !oq || oq.options.canonizeResults !== false;
|
|
913
|
-
};
|
|
914
865
|
QueryInfo.prototype.resetLastWrite = function () {
|
|
915
866
|
this.lastWrite = void 0;
|
|
916
867
|
};
|
|
@@ -928,7 +879,7 @@ var QueryInfo = (function () {
|
|
|
928
879
|
if (options.fetchPolicy === 'no-cache') {
|
|
929
880
|
this.updateLastDiff({ result: result.data, complete: true }, this.getDiffOptions(options.variables));
|
|
930
881
|
}
|
|
931
|
-
else if (
|
|
882
|
+
else if (cacheWriteBehavior !== 0) {
|
|
932
883
|
if (shouldWriteResult(result, options.errorPolicy)) {
|
|
933
884
|
this.cache.performTransaction(function (cache) {
|
|
934
885
|
if (_this.shouldWrite(result, options.variables)) {
|
|
@@ -1024,7 +975,7 @@ var QueryManager = (function () {
|
|
|
1024
975
|
this.queries.forEach(function (_info, queryId) {
|
|
1025
976
|
_this.stopQueryNoBroadcast(queryId);
|
|
1026
977
|
});
|
|
1027
|
-
this.cancelPendingFetches(__DEV__ ? new tsInvariant.InvariantError('QueryManager stopped while query was in flight') : new tsInvariant.InvariantError(
|
|
978
|
+
this.cancelPendingFetches(__DEV__ ? new tsInvariant.InvariantError('QueryManager stopped while query was in flight') : new tsInvariant.InvariantError(14));
|
|
1028
979
|
};
|
|
1029
980
|
QueryManager.prototype.cancelPendingFetches = function (error) {
|
|
1030
981
|
this.fetchCancelFns.forEach(function (cancel) { return cancel(error); });
|
|
@@ -1037,8 +988,8 @@ var QueryManager = (function () {
|
|
|
1037
988
|
return tslib.__generator(this, function (_e) {
|
|
1038
989
|
switch (_e.label) {
|
|
1039
990
|
case 0:
|
|
1040
|
-
__DEV__ ? tsInvariant.invariant(mutation, 'mutation option is required. You must specify your GraphQL document in the mutation option.') : tsInvariant.invariant(mutation,
|
|
1041
|
-
__DEV__ ? tsInvariant.invariant(!fetchPolicy || fetchPolicy === 'no-cache', "Mutations only support a 'no-cache' fetchPolicy. If you don't want to disable the cache, remove your fetchPolicy setting to proceed with the default mutation behavior.") : tsInvariant.invariant(!fetchPolicy || fetchPolicy === 'no-cache',
|
|
991
|
+
__DEV__ ? tsInvariant.invariant(mutation, 'mutation option is required. You must specify your GraphQL document in the mutation option.') : tsInvariant.invariant(mutation, 15);
|
|
992
|
+
__DEV__ ? tsInvariant.invariant(!fetchPolicy || fetchPolicy === 'no-cache', "Mutations only support a 'no-cache' fetchPolicy. If you don't want to disable the cache, remove your fetchPolicy setting to proceed with the default mutation behavior.") : tsInvariant.invariant(!fetchPolicy || fetchPolicy === 'no-cache', 16);
|
|
1042
993
|
mutationId = this.generateMutationId();
|
|
1043
994
|
mutation = this.transform(mutation).document;
|
|
1044
995
|
variables = this.getVariables(mutation, variables);
|
|
@@ -1323,10 +1274,10 @@ var QueryManager = (function () {
|
|
|
1323
1274
|
var _this = this;
|
|
1324
1275
|
if (queryId === void 0) { queryId = this.generateQueryId(); }
|
|
1325
1276
|
__DEV__ ? tsInvariant.invariant(options.query, 'query option is required. You must specify your GraphQL document ' +
|
|
1326
|
-
'in the query option.') : tsInvariant.invariant(options.query,
|
|
1327
|
-
__DEV__ ? tsInvariant.invariant(options.query.kind === 'Document', 'You must wrap the query string in a "gql" tag.') : tsInvariant.invariant(options.query.kind === 'Document',
|
|
1328
|
-
__DEV__ ? tsInvariant.invariant(!options.returnPartialData, 'returnPartialData option only supported on watchQuery.') : tsInvariant.invariant(!options.returnPartialData,
|
|
1329
|
-
__DEV__ ? tsInvariant.invariant(!options.pollInterval, 'pollInterval option only supported on watchQuery.') : tsInvariant.invariant(!options.pollInterval,
|
|
1277
|
+
'in the query option.') : tsInvariant.invariant(options.query, 17);
|
|
1278
|
+
__DEV__ ? tsInvariant.invariant(options.query.kind === 'Document', 'You must wrap the query string in a "gql" tag.') : tsInvariant.invariant(options.query.kind === 'Document', 18);
|
|
1279
|
+
__DEV__ ? tsInvariant.invariant(!options.returnPartialData, 'returnPartialData option only supported on watchQuery.') : tsInvariant.invariant(!options.returnPartialData, 19);
|
|
1280
|
+
__DEV__ ? tsInvariant.invariant(!options.pollInterval, 'pollInterval option only supported on watchQuery.') : tsInvariant.invariant(!options.pollInterval, 20);
|
|
1330
1281
|
return this.fetchQuery(queryId, options).finally(function () { return _this.stopQuery(queryId); });
|
|
1331
1282
|
};
|
|
1332
1283
|
QueryManager.prototype.generateQueryId = function () {
|
|
@@ -1348,7 +1299,7 @@ var QueryManager = (function () {
|
|
|
1348
1299
|
queryInfo.stop();
|
|
1349
1300
|
};
|
|
1350
1301
|
QueryManager.prototype.clearStore = function () {
|
|
1351
|
-
this.cancelPendingFetches(__DEV__ ? new tsInvariant.InvariantError('Store reset while query was in flight (not completed in link chain)') : new tsInvariant.InvariantError(
|
|
1302
|
+
this.cancelPendingFetches(__DEV__ ? new tsInvariant.InvariantError('Store reset while query was in flight (not completed in link chain)') : new tsInvariant.InvariantError(21));
|
|
1352
1303
|
this.queries.forEach(function (queryInfo) {
|
|
1353
1304
|
if (queryInfo.observableQuery) {
|
|
1354
1305
|
queryInfo.networkStatus = exports.NetworkStatus.loading;
|
|
@@ -1376,9 +1327,12 @@ var QueryManager = (function () {
|
|
|
1376
1327
|
var legacyQueryOptions = new Set();
|
|
1377
1328
|
if (Array.isArray(include)) {
|
|
1378
1329
|
include.forEach(function (desc) {
|
|
1379
|
-
if (typeof desc === "string"
|
|
1330
|
+
if (typeof desc === "string") {
|
|
1380
1331
|
queryNamesAndDocs.set(desc, false);
|
|
1381
1332
|
}
|
|
1333
|
+
else if (utilities.isDocumentNode(desc)) {
|
|
1334
|
+
queryNamesAndDocs.set(_this.transform(desc).document, false);
|
|
1335
|
+
}
|
|
1382
1336
|
else if (utilities.isNonNullObject(desc) && desc.query) {
|
|
1383
1337
|
legacyQueryOptions.add(desc);
|
|
1384
1338
|
}
|
|
@@ -1715,7 +1669,7 @@ var QueryManager = (function () {
|
|
|
1715
1669
|
utilities.isNonEmptyArray(diff.missing) &&
|
|
1716
1670
|
!equality.equal(data, {}) &&
|
|
1717
1671
|
!returnPartialData) {
|
|
1718
|
-
__DEV__ && tsInvariant.invariant.
|
|
1672
|
+
__DEV__ && tsInvariant.invariant.debug("Missing cache result fields: " + diff.missing.map(function (m) { return m.path.join('.'); }).join(', '), diff.missing);
|
|
1719
1673
|
}
|
|
1720
1674
|
var fromData = function (data) { return utilities.Observable.of(tslib.__assign({ data: data, loading: isNetworkRequestInFlight(networkStatus), networkStatus: networkStatus }, (diff.complete ? null : { partial: true }))); };
|
|
1721
1675
|
if (data && _this.transform(query).hasForcedResolvers) {
|
|
@@ -2012,6 +1966,9 @@ var ApolloClient = (function () {
|
|
|
2012
1966
|
var result = Promise.all(results);
|
|
2013
1967
|
result.queries = queries;
|
|
2014
1968
|
result.results = results;
|
|
1969
|
+
result.catch(function (error) {
|
|
1970
|
+
__DEV__ && tsInvariant.invariant.debug("In client.refetchQueries, Promise.all promise rejected with error " + error);
|
|
1971
|
+
});
|
|
2015
1972
|
return result;
|
|
2016
1973
|
};
|
|
2017
1974
|
ApolloClient.prototype.getObservableQueries = function (include) {
|
|
@@ -2042,10 +1999,9 @@ var ApolloClient = (function () {
|
|
|
2042
1999
|
return ApolloClient;
|
|
2043
2000
|
}());
|
|
2044
2001
|
|
|
2045
|
-
tsInvariant.setVerbosity("log");
|
|
2002
|
+
tsInvariant.setVerbosity(utilities.DEV ? "log" : "silent");
|
|
2046
2003
|
|
|
2047
2004
|
exports.Observable = utilities.Observable;
|
|
2048
|
-
exports.__DEV__ = utilities.__DEV__;
|
|
2049
2005
|
exports.isReference = utilities.isReference;
|
|
2050
2006
|
exports.makeReference = utilities.makeReference;
|
|
2051
2007
|
exports.setLogVerbosity = tsInvariant.setVerbosity;
|