@apollo/client 3.4.7 → 3.4.11
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/README.md +2 -2
- package/apollo-client.cjs.js +155 -156
- package/apollo-client.cjs.js.map +1 -1
- package/apollo-core.cjs.js +140 -103
- package/apollo-core.cjs.js.map +1 -1
- package/apollo-core.cjs.min.js +1 -1
- package/cache/cache.cjs.js +29 -28
- package/cache/cache.cjs.js.map +1 -1
- package/cache/index.d.ts +1 -0
- package/cache/index.d.ts.map +1 -1
- package/cache/index.js +1 -3
- package/cache/index.js.map +1 -1
- package/cache/inmemory/entityStore.js +2 -2
- package/cache/inmemory/entityStore.js.map +1 -1
- package/cache/inmemory/object-canon.d.ts +1 -0
- package/cache/inmemory/object-canon.d.ts.map +1 -1
- package/cache/inmemory/object-canon.js +1 -0
- package/cache/inmemory/object-canon.js.map +1 -1
- package/cache/inmemory/policies.d.ts.map +1 -1
- package/cache/inmemory/policies.js +13 -10
- package/cache/inmemory/policies.js.map +1 -1
- package/cache/inmemory/readFromStore.d.ts.map +1 -1
- package/cache/inmemory/readFromStore.js +4 -4
- package/cache/inmemory/readFromStore.js.map +1 -1
- package/cache/inmemory/writeToStore.d.ts.map +1 -1
- package/cache/inmemory/writeToStore.js +2 -2
- package/cache/inmemory/writeToStore.js.map +1 -1
- package/core/ApolloClient.d.ts.map +1 -1
- package/core/ApolloClient.js +3 -3
- package/core/ApolloClient.js.map +1 -1
- package/core/LocalState.d.ts.map +1 -1
- package/core/LocalState.js +2 -2
- 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 +79 -46
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryManager.d.ts.map +1 -1
- package/core/QueryManager.js +10 -10
- package/core/QueryManager.js.map +1 -1
- package/core/core.cjs.js +109 -75
- package/core/core.cjs.js.map +1 -1
- package/core/index.js +1 -1
- package/core/index.js.map +1 -1
- package/errors/errors.cjs.js +1 -2
- package/errors/errors.cjs.js.map +1 -1
- package/errors/index.d.ts +1 -0
- package/errors/index.d.ts.map +1 -1
- package/errors/index.js +1 -3
- package/errors/index.js.map +1 -1
- package/invariantErrorCodes.js +56 -81
- package/link/core/ApolloLink.js +2 -2
- package/link/core/ApolloLink.js.map +1 -1
- package/link/core/core.cjs.js +4 -6
- package/link/core/core.cjs.js.map +1 -1
- package/link/core/index.d.ts +1 -0
- package/link/core/index.d.ts.map +1 -1
- package/link/core/index.js +1 -3
- package/link/core/index.js.map +1 -1
- package/link/http/checkFetcher.js +2 -2
- package/link/http/checkFetcher.js.map +1 -1
- package/link/http/createHttpLink.d.ts +1 -0
- package/link/http/createHttpLink.d.ts.map +1 -1
- package/link/http/createHttpLink.js +1 -0
- package/link/http/createHttpLink.js.map +1 -1
- package/link/http/http.cjs.js +3 -3
- package/link/http/http.cjs.js.map +1 -1
- package/link/http/index.d.ts +1 -0
- package/link/http/index.d.ts.map +1 -1
- package/link/http/index.js +1 -0
- package/link/http/index.js.map +1 -1
- package/link/http/serializeFetchParameter.d.ts +1 -1
- package/link/http/serializeFetchParameter.d.ts.map +1 -1
- package/link/http/serializeFetchParameter.js +2 -2
- package/link/http/serializeFetchParameter.js.map +1 -1
- package/link/persisted-queries/index.d.ts +1 -1
- package/link/persisted-queries/index.d.ts.map +1 -1
- package/link/persisted-queries/index.js +4 -4
- package/link/persisted-queries/index.js.map +1 -1
- package/link/persisted-queries/persisted-queries.cjs.js +8 -5
- package/link/persisted-queries/persisted-queries.cjs.js.map +1 -1
- package/link/utils/index.d.ts +1 -0
- package/link/utils/index.d.ts.map +1 -1
- package/link/utils/index.js +1 -0
- package/link/utils/index.js.map +1 -1
- package/link/utils/toPromise.d.ts.map +1 -1
- package/link/utils/toPromise.js +1 -1
- package/link/utils/toPromise.js.map +1 -1
- package/link/utils/utils.cjs.js +3 -3
- package/link/utils/utils.cjs.js.map +1 -1
- package/link/utils/validateOperation.d.ts.map +1 -1
- package/link/utils/validateOperation.js +2 -2
- package/link/utils/validateOperation.js.map +1 -1
- package/package.json +11 -11
- package/react/context/ApolloConsumer.d.ts.map +1 -1
- package/react/context/ApolloConsumer.js +2 -2
- package/react/context/ApolloConsumer.js.map +1 -1
- package/react/context/ApolloProvider.d.ts.map +1 -1
- package/react/context/ApolloProvider.js +2 -2
- package/react/context/ApolloProvider.js.map +1 -1
- package/react/context/context.cjs.js +5 -5
- package/react/context/context.cjs.js.map +1 -1
- package/react/context/index.d.ts +1 -0
- package/react/context/index.d.ts.map +1 -1
- package/react/context/index.js +1 -0
- package/react/context/index.js.map +1 -1
- package/react/data/OperationData.d.ts.map +1 -1
- package/react/data/OperationData.js +3 -3
- package/react/data/OperationData.js.map +1 -1
- package/react/data/QueryData.d.ts.map +1 -1
- package/react/data/QueryData.js +9 -11
- package/react/data/QueryData.js.map +1 -1
- package/react/data/data.cjs.js +14 -16
- package/react/data/data.cjs.js.map +1 -1
- package/react/data/index.d.ts +1 -0
- package/react/data/index.d.ts.map +1 -1
- package/react/data/index.js +1 -0
- package/react/data/index.js.map +1 -1
- package/react/hoc/hoc-utils.d.ts.map +1 -1
- package/react/hoc/hoc-utils.js +2 -2
- package/react/hoc/hoc-utils.js.map +1 -1
- package/react/hoc/hoc.cjs.js +5 -5
- package/react/hoc/hoc.cjs.js.map +1 -1
- package/react/hoc/index.d.ts +1 -0
- package/react/hoc/index.d.ts.map +1 -1
- package/react/hoc/index.js +1 -0
- package/react/hoc/index.js.map +1 -1
- package/react/hoc/withApollo.d.ts.map +1 -1
- package/react/hoc/withApollo.js +2 -2
- package/react/hoc/withApollo.js.map +1 -1
- package/react/hooks/hooks.cjs.js +3 -3
- package/react/hooks/hooks.cjs.js.map +1 -1
- package/react/hooks/index.d.ts +1 -0
- package/react/hooks/index.d.ts.map +1 -1
- package/react/hooks/index.js +1 -0
- package/react/hooks/index.js.map +1 -1
- package/react/hooks/useApolloClient.d.ts.map +1 -1
- package/react/hooks/useApolloClient.js +2 -2
- package/react/hooks/useApolloClient.js.map +1 -1
- package/react/hooks/useSubscription.d.ts +1 -0
- package/react/hooks/useSubscription.d.ts.map +1 -1
- package/react/hooks/useSubscription.js +1 -0
- package/react/hooks/useSubscription.js.map +1 -1
- package/react/hooks/utils/useAfterFastRefresh.d.ts +1 -0
- package/react/hooks/utils/useAfterFastRefresh.d.ts.map +1 -1
- package/react/hooks/utils/useAfterFastRefresh.js +1 -0
- package/react/hooks/utils/useAfterFastRefresh.js.map +1 -1
- package/react/hooks/utils/useBaseQuery.d.ts +1 -0
- package/react/hooks/utils/useBaseQuery.d.ts.map +1 -1
- package/react/hooks/utils/useBaseQuery.js +1 -0
- package/react/hooks/utils/useBaseQuery.js.map +1 -1
- package/react/index.d.ts +1 -0
- package/react/index.d.ts.map +1 -1
- package/react/index.js +1 -3
- package/react/index.js.map +1 -1
- package/react/parser/index.d.ts.map +1 -1
- package/react/parser/index.js +5 -5
- package/react/parser/index.js.map +1 -1
- package/react/parser/parser.cjs.js +10 -10
- package/react/parser/parser.cjs.js.map +1 -1
- package/react/react.cjs.js +2 -3
- package/react/react.cjs.js.map +1 -1
- package/testing/index.d.ts +1 -0
- package/testing/index.d.ts.map +1 -1
- package/testing/index.js +1 -3
- package/testing/index.js.map +1 -1
- package/testing/testing.cjs.js +3 -5
- package/testing/testing.cjs.js.map +1 -1
- package/utilities/common/mergeDeep.js +1 -1
- package/utilities/common/mergeDeep.js.map +1 -1
- package/utilities/globals/DEV.js +2 -2
- package/utilities/globals/DEV.js.map +1 -1
- package/utilities/{common → globals}/global.d.ts +0 -0
- package/utilities/globals/global.d.ts.map +1 -0
- package/utilities/{common → globals}/global.js +0 -0
- package/utilities/globals/global.js.map +1 -0
- package/utilities/globals/globals.cjs.js +57 -0
- package/utilities/globals/globals.cjs.js.map +1 -0
- package/utilities/globals/index.d.ts +5 -2
- package/utilities/globals/index.d.ts.map +1 -1
- package/utilities/globals/index.js +8 -1
- package/utilities/globals/index.js.map +1 -1
- package/utilities/{common → globals}/maybe.d.ts +0 -0
- package/utilities/globals/maybe.d.ts.map +1 -0
- package/utilities/{common → globals}/maybe.js +0 -0
- package/utilities/globals/maybe.js.map +1 -0
- package/utilities/globals/package.json +7 -0
- package/utilities/graphql/directives.d.ts.map +1 -1
- package/utilities/graphql/directives.js +5 -5
- package/utilities/graphql/directives.js.map +1 -1
- package/utilities/graphql/fragments.d.ts.map +1 -1
- package/utilities/graphql/fragments.js +5 -5
- package/utilities/graphql/fragments.js.map +1 -1
- package/utilities/graphql/getFromAST.d.ts.map +1 -1
- package/utilities/graphql/getFromAST.js +9 -9
- package/utilities/graphql/getFromAST.js.map +1 -1
- package/utilities/graphql/storeUtils.d.ts.map +1 -1
- package/utilities/graphql/storeUtils.js +2 -2
- package/utilities/graphql/storeUtils.js.map +1 -1
- package/utilities/graphql/transform.d.ts.map +1 -1
- package/utilities/graphql/transform.js +2 -2
- package/utilities/graphql/transform.js.map +1 -1
- package/utilities/index.d.ts +1 -3
- package/utilities/index.d.ts.map +1 -1
- package/utilities/index.js +1 -5
- package/utilities/index.js.map +1 -1
- package/utilities/observables/Concast.js +1 -1
- package/utilities/observables/Concast.js.map +1 -1
- package/utilities/package.json +1 -3
- package/utilities/policies/pagination.js +2 -2
- package/utilities/policies/pagination.js.map +1 -1
- package/utilities/testing/mocking/mockFetch.js +1 -1
- 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 -2
- package/utilities/testing/mocking/mockLink.js.map +1 -1
- package/utilities/testing/mocking/mockWatchQuery.js +1 -1
- package/utilities/testing/mocking/mockWatchQuery.js.map +1 -1
- package/utilities/testing/observableToPromise.js +1 -1
- package/utilities/testing/observableToPromise.js.map +1 -1
- package/utilities/utilities.cjs.js +30 -71
- package/utilities/utilities.cjs.js.map +1 -1
- package/version.js +1 -1
- package/utilities/common/global.d.ts.map +0 -1
- package/utilities/common/global.js.map +0 -1
- package/utilities/common/maybe.d.ts.map +0 -1
- package/utilities/common/maybe.js.map +0 -1
package/core/core.cjs.js
CHANGED
|
@@ -2,19 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var globals = require('../utilities/globals');
|
|
6
6
|
var tslib = require('tslib');
|
|
7
|
-
var tsInvariant = require('ts-invariant');
|
|
8
7
|
var core = require('../link/core');
|
|
8
|
+
var utilities = require('../utilities');
|
|
9
9
|
var http = require('../link/http');
|
|
10
10
|
var equality = require('@wry/equality');
|
|
11
11
|
var cache = require('../cache');
|
|
12
12
|
var errors = require('../errors');
|
|
13
13
|
var graphql = require('graphql');
|
|
14
14
|
var utils = require('../link/utils');
|
|
15
|
+
var tsInvariant = require('ts-invariant');
|
|
15
16
|
var graphqlTag = require('graphql-tag');
|
|
16
17
|
|
|
17
|
-
var version = '3.4.
|
|
18
|
+
var version = '3.4.11';
|
|
18
19
|
|
|
19
20
|
exports.NetworkStatus = void 0;
|
|
20
21
|
(function (NetworkStatus) {
|
|
@@ -30,6 +31,7 @@ function isNetworkRequestInFlight(networkStatus) {
|
|
|
30
31
|
return networkStatus ? networkStatus < 7 : false;
|
|
31
32
|
}
|
|
32
33
|
|
|
34
|
+
var assign = Object.assign, hasOwnProperty$1 = Object.hasOwnProperty;
|
|
33
35
|
var warnedAboutUpdateQuery = false;
|
|
34
36
|
var ObservableQuery = (function (_super) {
|
|
35
37
|
tslib.__extends(ObservableQuery, _super);
|
|
@@ -45,11 +47,12 @@ var ObservableQuery = (function (_super) {
|
|
|
45
47
|
catch (_a) { }
|
|
46
48
|
var first = !_this.observers.size;
|
|
47
49
|
_this.observers.add(observer);
|
|
48
|
-
|
|
49
|
-
|
|
50
|
+
var last = _this.last;
|
|
51
|
+
if (last && last.error) {
|
|
52
|
+
observer.error && observer.error(last.error);
|
|
50
53
|
}
|
|
51
|
-
else if (
|
|
52
|
-
observer.next && observer.next(
|
|
54
|
+
else if (last && last.result) {
|
|
55
|
+
observer.next && observer.next(last.result);
|
|
53
56
|
}
|
|
54
57
|
if (first) {
|
|
55
58
|
_this.reobserve().catch(function () { });
|
|
@@ -62,18 +65,6 @@ var ObservableQuery = (function (_super) {
|
|
|
62
65
|
}) || this;
|
|
63
66
|
_this.observers = new Set();
|
|
64
67
|
_this.subscriptions = new Set();
|
|
65
|
-
_this.observer = {
|
|
66
|
-
next: function (result) {
|
|
67
|
-
if (_this.lastError || _this.isDifferentFromLastResult(result)) {
|
|
68
|
-
_this.updateLastResult(result);
|
|
69
|
-
utilities.iterateObserversSafely(_this.observers, 'next', result);
|
|
70
|
-
}
|
|
71
|
-
},
|
|
72
|
-
error: function (error) {
|
|
73
|
-
_this.updateLastResult(tslib.__assign(tslib.__assign({}, _this.lastResult), { error: error, errors: error.graphQLErrors, networkStatus: exports.NetworkStatus.error, loading: false }));
|
|
74
|
-
utilities.iterateObserversSafely(_this.observers, 'error', _this.lastError = error);
|
|
75
|
-
},
|
|
76
|
-
};
|
|
77
68
|
_this.isTornDown = false;
|
|
78
69
|
_this.options = options;
|
|
79
70
|
_this.queryId = queryInfo.queryId || queryManager.generateQueryId();
|
|
@@ -112,15 +103,24 @@ var ObservableQuery = (function (_super) {
|
|
|
112
103
|
};
|
|
113
104
|
ObservableQuery.prototype.getCurrentResult = function (saveAsLastResult) {
|
|
114
105
|
if (saveAsLastResult === void 0) { saveAsLastResult = true; }
|
|
115
|
-
var
|
|
106
|
+
var lastResult = this.getLastResult(true);
|
|
116
107
|
var networkStatus = this.queryInfo.networkStatus ||
|
|
117
108
|
(lastResult && lastResult.networkStatus) ||
|
|
118
109
|
exports.NetworkStatus.ready;
|
|
119
110
|
var result = tslib.__assign(tslib.__assign({}, lastResult), { loading: isNetworkRequestInFlight(networkStatus), networkStatus: networkStatus });
|
|
120
|
-
|
|
111
|
+
var _a = this.options.fetchPolicy, fetchPolicy = _a === void 0 ? "cache-first" : _a;
|
|
112
|
+
var shouldReturnCachedData = lastResult || (fetchPolicy !== 'network-only' &&
|
|
113
|
+
fetchPolicy !== 'no-cache' &&
|
|
114
|
+
fetchPolicy !== 'standby');
|
|
115
|
+
if (shouldReturnCachedData &&
|
|
116
|
+
!this.queryManager.transform(this.options.query).hasForcedResolvers) {
|
|
121
117
|
var diff = this.queryInfo.getDiff();
|
|
122
|
-
|
|
123
|
-
|
|
118
|
+
if (diff.complete || this.options.returnPartialData) {
|
|
119
|
+
result.data = diff.result;
|
|
120
|
+
}
|
|
121
|
+
if (equality.equal(result.data, {})) {
|
|
122
|
+
result.data = void 0;
|
|
123
|
+
}
|
|
124
124
|
if (diff.complete) {
|
|
125
125
|
if (result.networkStatus === exports.NetworkStatus.loading &&
|
|
126
126
|
(fetchPolicy === 'cache-first' ||
|
|
@@ -148,24 +148,31 @@ var ObservableQuery = (function (_super) {
|
|
|
148
148
|
return result;
|
|
149
149
|
};
|
|
150
150
|
ObservableQuery.prototype.isDifferentFromLastResult = function (newResult) {
|
|
151
|
-
return !equality.equal(this.
|
|
151
|
+
return !this.last || !equality.equal(this.last.result, newResult);
|
|
152
152
|
};
|
|
153
|
-
ObservableQuery.prototype.
|
|
154
|
-
|
|
153
|
+
ObservableQuery.prototype.getLast = function (key, variablesMustMatch) {
|
|
154
|
+
var last = this.last;
|
|
155
|
+
if (last &&
|
|
156
|
+
last[key] &&
|
|
157
|
+
(!variablesMustMatch || equality.equal(last.variables, this.variables))) {
|
|
158
|
+
return last[key];
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
ObservableQuery.prototype.getLastResult = function (variablesMustMatch) {
|
|
162
|
+
return this.getLast("result", variablesMustMatch);
|
|
155
163
|
};
|
|
156
|
-
ObservableQuery.prototype.getLastError = function () {
|
|
157
|
-
return this.
|
|
164
|
+
ObservableQuery.prototype.getLastError = function (variablesMustMatch) {
|
|
165
|
+
return this.getLast("error", variablesMustMatch);
|
|
158
166
|
};
|
|
159
167
|
ObservableQuery.prototype.resetLastResults = function () {
|
|
160
|
-
delete this.
|
|
161
|
-
delete this.lastResultSnapshot;
|
|
162
|
-
delete this.lastError;
|
|
168
|
+
delete this.last;
|
|
163
169
|
this.isTornDown = false;
|
|
164
170
|
};
|
|
165
171
|
ObservableQuery.prototype.resetQueryStoreErrors = function () {
|
|
166
172
|
this.queryManager.resetErrors(this.queryId);
|
|
167
173
|
};
|
|
168
174
|
ObservableQuery.prototype.refetch = function (variables) {
|
|
175
|
+
var _a;
|
|
169
176
|
var reobserveOptions = {
|
|
170
177
|
pollInterval: 0,
|
|
171
178
|
};
|
|
@@ -176,6 +183,13 @@ var ObservableQuery = (function (_super) {
|
|
|
176
183
|
else if (fetchPolicy !== 'cache-and-network') {
|
|
177
184
|
reobserveOptions.fetchPolicy = 'network-only';
|
|
178
185
|
}
|
|
186
|
+
if (__DEV__ && variables && hasOwnProperty$1.call(variables, "variables")) {
|
|
187
|
+
var queryDef = utilities.getQueryDefinition(this.options.query);
|
|
188
|
+
var vars = queryDef.variableDefinitions;
|
|
189
|
+
if (!vars || !vars.some(function (v) { return v.variable.name.value === "variables"; })) {
|
|
190
|
+
__DEV__ && globals.invariant.warn("Called refetch(" + JSON.stringify(variables) + ") for query " + (((_a = queryDef.name) === null || _a === void 0 ? void 0 : _a.value) || JSON.stringify(queryDef)) + ", which does not declare a $variables variable.\nDid you mean to call refetch(variables) instead of refetch({ variables })?");
|
|
191
|
+
}
|
|
192
|
+
}
|
|
179
193
|
if (variables && !equality.equal(this.options.variables, variables)) {
|
|
180
194
|
reobserveOptions.variables = this.options.variables = tslib.__assign(tslib.__assign({}, this.options.variables), variables);
|
|
181
195
|
}
|
|
@@ -196,7 +210,7 @@ var ObservableQuery = (function (_super) {
|
|
|
196
210
|
if (updateQuery) {
|
|
197
211
|
if (__DEV__ &&
|
|
198
212
|
!warnedAboutUpdateQuery) {
|
|
199
|
-
__DEV__ &&
|
|
213
|
+
__DEV__ && globals.invariant.warn("The updateQuery callback for fetchMore is deprecated, and will be removed\nin the next major version of Apollo Client.\n\nPlease convert updateQuery functions to field policies with appropriate\nread and merge functions, or use/adapt a helper function (such as\nconcatPagination, offsetLimitPagination, or relayStylePagination) from\n@apollo/client/utilities.\n\nThe field policy system handles pagination more effectively than a\nhand-written updateQuery function, and you only need to define the policy\nonce, rather than every time you call fetchMore.");
|
|
200
214
|
warnedAboutUpdateQuery = true;
|
|
201
215
|
}
|
|
202
216
|
_this.updateQuery(function (previous) { return updateQuery(previous, {
|
|
@@ -243,7 +257,7 @@ var ObservableQuery = (function (_super) {
|
|
|
243
257
|
options.onError(err);
|
|
244
258
|
return;
|
|
245
259
|
}
|
|
246
|
-
__DEV__ &&
|
|
260
|
+
__DEV__ && globals.invariant.error('Unhandled GraphQL subscription error', err);
|
|
247
261
|
},
|
|
248
262
|
});
|
|
249
263
|
this.subscriptions.add(subscription);
|
|
@@ -272,12 +286,10 @@ var ObservableQuery = (function (_super) {
|
|
|
272
286
|
}, exports.NetworkStatus.setVariables);
|
|
273
287
|
};
|
|
274
288
|
ObservableQuery.prototype.updateQuery = function (mapFn) {
|
|
275
|
-
var _a;
|
|
276
289
|
var queryManager = this.queryManager;
|
|
277
290
|
var result = queryManager.cache.diff({
|
|
278
291
|
query: this.options.query,
|
|
279
292
|
variables: this.variables,
|
|
280
|
-
previousResult: (_a = this.lastResult) === null || _a === void 0 ? void 0 : _a.data,
|
|
281
293
|
returnPartialData: true,
|
|
282
294
|
optimistic: false,
|
|
283
295
|
}).result;
|
|
@@ -322,7 +334,7 @@ var ObservableQuery = (function (_super) {
|
|
|
322
334
|
pollingInfo.interval === pollInterval) {
|
|
323
335
|
return;
|
|
324
336
|
}
|
|
325
|
-
__DEV__ ?
|
|
337
|
+
__DEV__ ? globals.invariant(pollInterval, 'Attempted to start a polling query without a polling interval.') : globals.invariant(pollInterval, 12);
|
|
326
338
|
var info = pollingInfo || (this.pollingInfo = {});
|
|
327
339
|
info.interval = pollInterval;
|
|
328
340
|
var maybeFetch = function () {
|
|
@@ -346,18 +358,18 @@ var ObservableQuery = (function (_super) {
|
|
|
346
358
|
};
|
|
347
359
|
poll();
|
|
348
360
|
};
|
|
349
|
-
ObservableQuery.prototype.updateLastResult = function (newResult) {
|
|
350
|
-
|
|
351
|
-
this.
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
: utilities.cloneDeep(newResult);
|
|
361
|
+
ObservableQuery.prototype.updateLastResult = function (newResult, variables) {
|
|
362
|
+
if (variables === void 0) { variables = this.variables; }
|
|
363
|
+
this.last = tslib.__assign(tslib.__assign({}, this.last), { result: this.queryManager.assumeImmutableResults
|
|
364
|
+
? newResult
|
|
365
|
+
: utilities.cloneDeep(newResult), variables: variables });
|
|
355
366
|
if (!utilities.isNonEmptyArray(newResult.errors)) {
|
|
356
|
-
delete this.
|
|
367
|
+
delete this.last.error;
|
|
357
368
|
}
|
|
358
|
-
return
|
|
369
|
+
return this.last;
|
|
359
370
|
};
|
|
360
371
|
ObservableQuery.prototype.reobserve = function (newOptions, newNetworkStatus) {
|
|
372
|
+
var _this = this;
|
|
361
373
|
this.isTornDown = false;
|
|
362
374
|
var useDisposableConcast = newNetworkStatus === exports.NetworkStatus.refetch ||
|
|
363
375
|
newNetworkStatus === exports.NetworkStatus.fetchMore ||
|
|
@@ -365,7 +377,7 @@ var ObservableQuery = (function (_super) {
|
|
|
365
377
|
var oldVariables = this.options.variables;
|
|
366
378
|
var options = useDisposableConcast
|
|
367
379
|
? utilities.compact(this.options, newOptions)
|
|
368
|
-
:
|
|
380
|
+
: assign(this.options, utilities.compact(newOptions));
|
|
369
381
|
if (!useDisposableConcast) {
|
|
370
382
|
this.updatePolling();
|
|
371
383
|
if (newOptions &&
|
|
@@ -378,18 +390,39 @@ var ObservableQuery = (function (_super) {
|
|
|
378
390
|
}
|
|
379
391
|
}
|
|
380
392
|
}
|
|
393
|
+
var variables = options.variables && tslib.__assign({}, options.variables);
|
|
381
394
|
var concast = this.fetch(options, newNetworkStatus);
|
|
395
|
+
var observer = {
|
|
396
|
+
next: function (result) {
|
|
397
|
+
_this.reportResult(result, variables);
|
|
398
|
+
},
|
|
399
|
+
error: function (error) {
|
|
400
|
+
_this.reportError(error, variables);
|
|
401
|
+
},
|
|
402
|
+
};
|
|
382
403
|
if (!useDisposableConcast) {
|
|
383
|
-
if (this.concast) {
|
|
404
|
+
if (this.concast && this.observer) {
|
|
384
405
|
this.concast.removeObserver(this.observer, true);
|
|
385
406
|
}
|
|
386
407
|
this.concast = concast;
|
|
408
|
+
this.observer = observer;
|
|
387
409
|
}
|
|
388
|
-
concast.addObserver(
|
|
410
|
+
concast.addObserver(observer);
|
|
389
411
|
return concast.promise;
|
|
390
412
|
};
|
|
391
413
|
ObservableQuery.prototype.observe = function () {
|
|
392
|
-
this.
|
|
414
|
+
this.reportResult(this.getCurrentResult(false), this.variables);
|
|
415
|
+
};
|
|
416
|
+
ObservableQuery.prototype.reportResult = function (result, variables) {
|
|
417
|
+
if (this.getLastError() || this.isDifferentFromLastResult(result)) {
|
|
418
|
+
this.updateLastResult(result, variables);
|
|
419
|
+
utilities.iterateObserversSafely(this.observers, 'next', result);
|
|
420
|
+
}
|
|
421
|
+
};
|
|
422
|
+
ObservableQuery.prototype.reportError = function (error, variables) {
|
|
423
|
+
var errorResult = tslib.__assign(tslib.__assign({}, this.getLastResult()), { error: error, errors: error.graphQLErrors, networkStatus: exports.NetworkStatus.error, loading: false });
|
|
424
|
+
this.updateLastResult(errorResult, variables);
|
|
425
|
+
utilities.iterateObserversSafely(this.observers, 'error', this.last.error = error);
|
|
393
426
|
};
|
|
394
427
|
ObservableQuery.prototype.hasObservers = function () {
|
|
395
428
|
return this.observers.size > 0;
|
|
@@ -397,9 +430,10 @@ var ObservableQuery = (function (_super) {
|
|
|
397
430
|
ObservableQuery.prototype.tearDownQuery = function () {
|
|
398
431
|
if (this.isTornDown)
|
|
399
432
|
return;
|
|
400
|
-
if (this.concast) {
|
|
433
|
+
if (this.concast && this.observer) {
|
|
401
434
|
this.concast.removeObserver(this.observer);
|
|
402
435
|
delete this.concast;
|
|
436
|
+
delete this.observer;
|
|
403
437
|
}
|
|
404
438
|
this.stopPolling();
|
|
405
439
|
this.subscriptions.forEach(function (sub) { return sub.unsubscribe(); });
|
|
@@ -412,11 +446,11 @@ var ObservableQuery = (function (_super) {
|
|
|
412
446
|
}(utilities.Observable));
|
|
413
447
|
utilities.fixObservableSubclass(ObservableQuery);
|
|
414
448
|
function defaultSubscriptionObserverErrorCallback(error) {
|
|
415
|
-
__DEV__ &&
|
|
449
|
+
__DEV__ && globals.invariant.error('Unhandled error', error.message, error.stack);
|
|
416
450
|
}
|
|
417
451
|
function logMissingFieldErrors(missing) {
|
|
418
452
|
if (__DEV__ && utilities.isNonEmptyArray(missing)) {
|
|
419
|
-
__DEV__ &&
|
|
453
|
+
__DEV__ && globals.invariant.debug("Missing cache result fields: " + missing.map(function (m) { return m.path.join('.'); }).join(', '), missing);
|
|
420
454
|
}
|
|
421
455
|
}
|
|
422
456
|
function applyNextFetchPolicy(options) {
|
|
@@ -597,7 +631,7 @@ var LocalState = (function () {
|
|
|
597
631
|
}
|
|
598
632
|
else {
|
|
599
633
|
fragment = fragmentMap[selection.name.value];
|
|
600
|
-
__DEV__ ?
|
|
634
|
+
__DEV__ ? globals.invariant(fragment, "No fragment named " + selection.name.value) : globals.invariant(fragment, 11);
|
|
601
635
|
}
|
|
602
636
|
if (fragment && fragment.typeCondition) {
|
|
603
637
|
typeCondition = fragment.typeCondition.name.value;
|
|
@@ -983,7 +1017,7 @@ var QueryManager = (function () {
|
|
|
983
1017
|
this.queries.forEach(function (_info, queryId) {
|
|
984
1018
|
_this.stopQueryNoBroadcast(queryId);
|
|
985
1019
|
});
|
|
986
|
-
this.cancelPendingFetches(__DEV__ ? new
|
|
1020
|
+
this.cancelPendingFetches(__DEV__ ? new globals.InvariantError('QueryManager stopped while query was in flight') : new globals.InvariantError(13));
|
|
987
1021
|
};
|
|
988
1022
|
QueryManager.prototype.cancelPendingFetches = function (error) {
|
|
989
1023
|
this.fetchCancelFns.forEach(function (cancel) { return cancel(error); });
|
|
@@ -996,10 +1030,10 @@ var QueryManager = (function () {
|
|
|
996
1030
|
return tslib.__generator(this, function (_f) {
|
|
997
1031
|
switch (_f.label) {
|
|
998
1032
|
case 0:
|
|
999
|
-
__DEV__ ?
|
|
1000
|
-
__DEV__ ?
|
|
1001
|
-
fetchPolicy === 'no-cache', "Mutations support only 'network-only' or 'no-cache' fetchPolicy strings. The default `network-only` behavior automatically writes mutation results to the cache. Passing `no-cache` skips the cache write.") :
|
|
1002
|
-
fetchPolicy === 'no-cache',
|
|
1033
|
+
__DEV__ ? globals.invariant(mutation, 'mutation option is required. You must specify your GraphQL document in the mutation option.') : globals.invariant(mutation, 14);
|
|
1034
|
+
__DEV__ ? globals.invariant(fetchPolicy === 'network-only' ||
|
|
1035
|
+
fetchPolicy === 'no-cache', "Mutations support only 'network-only' or 'no-cache' fetchPolicy strings. The default `network-only` behavior automatically writes mutation results to the cache. Passing `no-cache` skips the cache write.") : globals.invariant(fetchPolicy === 'network-only' ||
|
|
1036
|
+
fetchPolicy === 'no-cache', 15);
|
|
1003
1037
|
mutationId = this.generateMutationId();
|
|
1004
1038
|
mutation = this.transform(mutation).document;
|
|
1005
1039
|
variables = this.getVariables(mutation, variables);
|
|
@@ -1198,7 +1232,7 @@ var QueryManager = (function () {
|
|
|
1198
1232
|
_this.markMutationResult(tslib.__assign(tslib.__assign({}, mutation), { result: { data: data } }), cache);
|
|
1199
1233
|
}
|
|
1200
1234
|
catch (error) {
|
|
1201
|
-
__DEV__ &&
|
|
1235
|
+
__DEV__ && globals.invariant.error(error);
|
|
1202
1236
|
}
|
|
1203
1237
|
}, mutation.mutationId);
|
|
1204
1238
|
};
|
|
@@ -1283,11 +1317,11 @@ var QueryManager = (function () {
|
|
|
1283
1317
|
QueryManager.prototype.query = function (options, queryId) {
|
|
1284
1318
|
var _this = this;
|
|
1285
1319
|
if (queryId === void 0) { queryId = this.generateQueryId(); }
|
|
1286
|
-
__DEV__ ?
|
|
1287
|
-
'in the query option.') :
|
|
1288
|
-
__DEV__ ?
|
|
1289
|
-
__DEV__ ?
|
|
1290
|
-
__DEV__ ?
|
|
1320
|
+
__DEV__ ? globals.invariant(options.query, 'query option is required. You must specify your GraphQL document ' +
|
|
1321
|
+
'in the query option.') : globals.invariant(options.query, 16);
|
|
1322
|
+
__DEV__ ? globals.invariant(options.query.kind === 'Document', 'You must wrap the query string in a "gql" tag.') : globals.invariant(options.query.kind === 'Document', 17);
|
|
1323
|
+
__DEV__ ? globals.invariant(!options.returnPartialData, 'returnPartialData option only supported on watchQuery.') : globals.invariant(!options.returnPartialData, 18);
|
|
1324
|
+
__DEV__ ? globals.invariant(!options.pollInterval, 'pollInterval option only supported on watchQuery.') : globals.invariant(!options.pollInterval, 19);
|
|
1291
1325
|
return this.fetchQuery(queryId, options).finally(function () { return _this.stopQuery(queryId); });
|
|
1292
1326
|
};
|
|
1293
1327
|
QueryManager.prototype.generateQueryId = function () {
|
|
@@ -1309,7 +1343,7 @@ var QueryManager = (function () {
|
|
|
1309
1343
|
queryInfo.stop();
|
|
1310
1344
|
};
|
|
1311
1345
|
QueryManager.prototype.clearStore = function () {
|
|
1312
|
-
this.cancelPendingFetches(__DEV__ ? new
|
|
1346
|
+
this.cancelPendingFetches(__DEV__ ? new globals.InvariantError('Store reset while query was in flight (not completed in link chain)') : new globals.InvariantError(20));
|
|
1313
1347
|
this.queries.forEach(function (queryInfo) {
|
|
1314
1348
|
if (queryInfo.observableQuery) {
|
|
1315
1349
|
queryInfo.networkStatus = exports.NetworkStatus.loading;
|
|
@@ -1382,7 +1416,7 @@ var QueryManager = (function () {
|
|
|
1382
1416
|
queryInfo: queryInfo,
|
|
1383
1417
|
options: tslib.__assign(tslib.__assign({}, options), { fetchPolicy: "network-only" }),
|
|
1384
1418
|
});
|
|
1385
|
-
|
|
1419
|
+
globals.invariant(oq.queryId === queryId);
|
|
1386
1420
|
queryInfo.setObservableQuery(oq);
|
|
1387
1421
|
queries.set(queryId, oq);
|
|
1388
1422
|
});
|
|
@@ -1390,7 +1424,7 @@ var QueryManager = (function () {
|
|
|
1390
1424
|
if (__DEV__ && queryNamesAndDocs.size) {
|
|
1391
1425
|
queryNamesAndDocs.forEach(function (included, nameOrDoc) {
|
|
1392
1426
|
if (!included) {
|
|
1393
|
-
__DEV__ &&
|
|
1427
|
+
__DEV__ && globals.invariant.warn("Unknown query " + (typeof nameOrDoc === "string" ? "named " : "") + JSON.stringify(nameOrDoc, null, 2) + " requested in refetchQueries options.include array");
|
|
1394
1428
|
}
|
|
1395
1429
|
});
|
|
1396
1430
|
}
|
|
@@ -1584,7 +1618,7 @@ var QueryManager = (function () {
|
|
|
1584
1618
|
return _this.fetchQueryByPolicy(queryInfo, normalized, networkStatus);
|
|
1585
1619
|
};
|
|
1586
1620
|
this.fetchCancelFns.set(queryId, function (reason) {
|
|
1587
|
-
|
|
1621
|
+
setTimeout(function () { return concast.cancel(reason); });
|
|
1588
1622
|
});
|
|
1589
1623
|
var concast = new utilities.Concast(this.transform(normalized.query).hasClientExports
|
|
1590
1624
|
? this.localState.addExportedVariables(normalized.query, normalized.variables, normalized.context).then(fromVariables)
|
|
@@ -1800,9 +1834,9 @@ var ApolloClient = (function () {
|
|
|
1800
1834
|
: core.ApolloLink.empty();
|
|
1801
1835
|
}
|
|
1802
1836
|
if (!cache) {
|
|
1803
|
-
throw __DEV__ ? new
|
|
1837
|
+
throw __DEV__ ? new globals.InvariantError("To initialize Apollo Client, you must specify a 'cache' property " +
|
|
1804
1838
|
"in the options object. \n" +
|
|
1805
|
-
"For more information, please visit: https://go.apollo.dev/c/docs") : new
|
|
1839
|
+
"For more information, please visit: https://go.apollo.dev/c/docs") : new globals.InvariantError(9);
|
|
1806
1840
|
}
|
|
1807
1841
|
this.link = link;
|
|
1808
1842
|
this.cache = cache;
|
|
@@ -1840,7 +1874,7 @@ var ApolloClient = (function () {
|
|
|
1840
1874
|
}
|
|
1841
1875
|
}
|
|
1842
1876
|
if (url) {
|
|
1843
|
-
__DEV__ &&
|
|
1877
|
+
__DEV__ && globals.invariant.log("Download the Apollo DevTools for a better development " +
|
|
1844
1878
|
"experience: " + url);
|
|
1845
1879
|
}
|
|
1846
1880
|
}
|
|
@@ -1895,10 +1929,10 @@ var ApolloClient = (function () {
|
|
|
1895
1929
|
if (this.defaultOptions.query) {
|
|
1896
1930
|
options = mergeOptions(this.defaultOptions.query, options);
|
|
1897
1931
|
}
|
|
1898
|
-
__DEV__ ?
|
|
1932
|
+
__DEV__ ? globals.invariant(options.fetchPolicy !== 'cache-and-network', 'The cache-and-network fetchPolicy does not work with client.query, because ' +
|
|
1899
1933
|
'client.query can only return a single result. Please use client.watchQuery ' +
|
|
1900
1934
|
'to receive multiple results from the cache and the network, or consider ' +
|
|
1901
|
-
'using a different fetchPolicy, such as cache-first or network-only.') :
|
|
1935
|
+
'using a different fetchPolicy, such as cache-first or network-only.') : globals.invariant(options.fetchPolicy !== 'cache-and-network', 10);
|
|
1902
1936
|
if (this.disableNetworkFetches && options.fetchPolicy === 'network-only') {
|
|
1903
1937
|
options = tslib.__assign(tslib.__assign({}, options), { fetchPolicy: 'cache-first' });
|
|
1904
1938
|
}
|
|
@@ -1977,7 +2011,7 @@ var ApolloClient = (function () {
|
|
|
1977
2011
|
result.queries = queries;
|
|
1978
2012
|
result.results = results;
|
|
1979
2013
|
result.catch(function (error) {
|
|
1980
|
-
__DEV__ &&
|
|
2014
|
+
__DEV__ && globals.invariant.debug("In client.refetchQueries, Promise.all promise rejected with error " + error);
|
|
1981
2015
|
});
|
|
1982
2016
|
return result;
|
|
1983
2017
|
};
|
|
@@ -2009,12 +2043,11 @@ var ApolloClient = (function () {
|
|
|
2009
2043
|
return ApolloClient;
|
|
2010
2044
|
}());
|
|
2011
2045
|
|
|
2012
|
-
tsInvariant.setVerbosity(
|
|
2046
|
+
tsInvariant.setVerbosity(globals.DEV ? "log" : "silent");
|
|
2013
2047
|
|
|
2014
2048
|
exports.Observable = utilities.Observable;
|
|
2015
2049
|
exports.isReference = utilities.isReference;
|
|
2016
2050
|
exports.makeReference = utilities.makeReference;
|
|
2017
|
-
exports.setLogVerbosity = tsInvariant.setVerbosity;
|
|
2018
2051
|
exports.ApolloCache = cache.ApolloCache;
|
|
2019
2052
|
exports.Cache = cache.Cache;
|
|
2020
2053
|
exports.InMemoryCache = cache.InMemoryCache;
|
|
@@ -2027,6 +2060,7 @@ exports.fromError = utils.fromError;
|
|
|
2027
2060
|
exports.fromPromise = utils.fromPromise;
|
|
2028
2061
|
exports.throwServerError = utils.throwServerError;
|
|
2029
2062
|
exports.toPromise = utils.toPromise;
|
|
2063
|
+
exports.setLogVerbosity = tsInvariant.setVerbosity;
|
|
2030
2064
|
exports.disableExperimentalFragmentVariables = graphqlTag.disableExperimentalFragmentVariables;
|
|
2031
2065
|
exports.disableFragmentWarnings = graphqlTag.disableFragmentWarnings;
|
|
2032
2066
|
exports.enableExperimentalFragmentVariables = graphqlTag.enableExperimentalFragmentVariables;
|