@apollo/client 3.6.2 → 3.6.5
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 +164 -105
- package/apollo-client.cjs.map +1 -1
- package/apollo-client.min.cjs +1 -1
- package/cache/cache.cjs +9 -10
- package/cache/cache.cjs.map +1 -1
- package/cache/cache.cjs.native.js +2288 -0
- package/cache/inmemory/readFromStore.d.ts.map +1 -1
- package/cache/inmemory/readFromStore.js +10 -11
- package/cache/inmemory/readFromStore.js.map +1 -1
- package/core/ApolloClient.d.ts.map +1 -1
- package/core/ApolloClient.js.map +1 -1
- package/core/ObservableQuery.d.ts.map +1 -1
- package/core/ObservableQuery.js +5 -3
- package/core/ObservableQuery.js.map +1 -1
- package/core/core.cjs +5 -3
- package/core/core.cjs.map +1 -1
- package/core/core.cjs.native.js +2141 -0
- package/errors/errors.cjs.native.js +48 -0
- package/invariantErrorCodes.js +1 -1
- package/link/batch/batch.cjs.native.js +161 -0
- package/link/batch-http/batch-http.cjs.native.js +127 -0
- package/link/context/context.cjs.native.js +38 -0
- package/link/core/core.cjs.native.js +121 -0
- package/link/error/error.cjs.native.js +90 -0
- package/link/http/http.cjs.native.js +320 -0
- package/link/http/selectHttpOptionsAndBody.d.ts.map +1 -1
- package/link/http/selectHttpOptionsAndBody.js.map +1 -1
- package/link/persisted-queries/persisted-queries.cjs.native.js +174 -0
- package/link/retry/retry.cjs.native.js +170 -0
- package/link/schema/schema.cjs.native.js +56 -0
- package/link/subscriptions/subscriptions.cjs.native.js +45 -0
- package/link/utils/utils.cjs.native.js +115 -0
- package/link/ws/ws.cjs.native.js +28 -0
- package/main.cjs.native.js +16 -0
- package/package.json +16 -17
- package/react/components/components.cjs.native.js +79 -0
- package/react/context/context.cjs.native.js +67 -0
- package/react/hoc/hoc.cjs.native.js +325 -0
- package/react/hooks/hooks.cjs +168 -99
- package/react/hooks/hooks.cjs.map +1 -1
- package/react/hooks/hooks.cjs.native.js +612 -0
- package/react/hooks/useLazyQuery.d.ts.map +1 -1
- package/react/hooks/useLazyQuery.js +12 -23
- package/react/hooks/useLazyQuery.js.map +1 -1
- package/react/hooks/useMutation.js +7 -7
- package/react/hooks/useMutation.js.map +1 -1
- package/react/hooks/useQuery.d.ts +6 -2
- package/react/hooks/useQuery.d.ts.map +1 -1
- package/react/hooks/useQuery.js +52 -40
- package/react/hooks/useQuery.js.map +1 -1
- package/react/hooks/useSubscription.d.ts.map +1 -1
- package/react/hooks/useSubscription.js +17 -7
- package/react/hooks/useSubscription.js.map +1 -1
- package/react/hooks/useSyncExternalStore.d.ts +4 -0
- package/react/hooks/useSyncExternalStore.d.ts.map +1 -0
- package/react/hooks/useSyncExternalStore.js +48 -0
- package/react/hooks/useSyncExternalStore.js.map +1 -0
- package/react/parser/parser.cjs.native.js +103 -0
- package/react/react.cjs.native.js +22 -0
- package/react/ssr/ssr.cjs.native.js +150 -0
- package/testing/core/core.cjs.native.js +288 -0
- package/testing/testing.cjs.native.js +58 -0
- package/utilities/common/canUse.d.ts +2 -0
- package/utilities/common/canUse.d.ts.map +1 -1
- package/utilities/common/canUse.js +6 -2
- package/utilities/common/canUse.js.map +1 -1
- package/utilities/common/mergeDeep.d.ts.map +1 -1
- package/utilities/common/mergeDeep.js +8 -11
- package/utilities/common/mergeDeep.js.map +1 -1
- package/utilities/common/mergeOptions.d.ts +1 -1
- package/utilities/common/mergeOptions.d.ts.map +1 -1
- package/utilities/common/mergeOptions.js +1 -1
- package/utilities/common/mergeOptions.js.map +1 -1
- package/utilities/globals/globals.cjs.native.js +56 -0
- package/utilities/observables/Concast.d.ts.map +1 -1
- package/utilities/observables/Concast.js +5 -2
- package/utilities/observables/Concast.js.map +1 -1
- package/utilities/policies/pagination.d.ts.map +1 -1
- package/utilities/policies/pagination.js +9 -7
- package/utilities/policies/pagination.js.map +1 -1
- package/utilities/utilities.cjs +30 -23
- package/utilities/utilities.cjs.map +1 -1
- package/utilities/utilities.cjs.native.js +1281 -0
- package/version.js +1 -1
|
@@ -0,0 +1,2141 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var globals = require('../utilities/globals');
|
|
6
|
+
var tslib = require('tslib');
|
|
7
|
+
var core = require('../link/core');
|
|
8
|
+
var http = require('../link/http');
|
|
9
|
+
var equality = require('@wry/equality');
|
|
10
|
+
var cache = require('../cache');
|
|
11
|
+
var utilities = require('../utilities');
|
|
12
|
+
var errors = require('../errors');
|
|
13
|
+
var graphql = require('graphql');
|
|
14
|
+
var utils = require('../link/utils');
|
|
15
|
+
var tsInvariant = require('ts-invariant');
|
|
16
|
+
var graphqlTag = require('graphql-tag');
|
|
17
|
+
|
|
18
|
+
var version = '3.6.5';
|
|
19
|
+
|
|
20
|
+
exports.NetworkStatus = void 0;
|
|
21
|
+
(function (NetworkStatus) {
|
|
22
|
+
NetworkStatus[NetworkStatus["loading"] = 1] = "loading";
|
|
23
|
+
NetworkStatus[NetworkStatus["setVariables"] = 2] = "setVariables";
|
|
24
|
+
NetworkStatus[NetworkStatus["fetchMore"] = 3] = "fetchMore";
|
|
25
|
+
NetworkStatus[NetworkStatus["refetch"] = 4] = "refetch";
|
|
26
|
+
NetworkStatus[NetworkStatus["poll"] = 6] = "poll";
|
|
27
|
+
NetworkStatus[NetworkStatus["ready"] = 7] = "ready";
|
|
28
|
+
NetworkStatus[NetworkStatus["error"] = 8] = "error";
|
|
29
|
+
})(exports.NetworkStatus || (exports.NetworkStatus = {}));
|
|
30
|
+
function isNetworkRequestInFlight(networkStatus) {
|
|
31
|
+
return networkStatus ? networkStatus < 7 : false;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
var assign = Object.assign, hasOwnProperty$1 = Object.hasOwnProperty;
|
|
35
|
+
var ObservableQuery = (function (_super) {
|
|
36
|
+
tslib.__extends(ObservableQuery, _super);
|
|
37
|
+
function ObservableQuery(_a) {
|
|
38
|
+
var queryManager = _a.queryManager, queryInfo = _a.queryInfo, options = _a.options;
|
|
39
|
+
var _this = _super.call(this, function (observer) {
|
|
40
|
+
try {
|
|
41
|
+
var subObserver = observer._subscription._observer;
|
|
42
|
+
if (subObserver && !subObserver.error) {
|
|
43
|
+
subObserver.error = defaultSubscriptionObserverErrorCallback;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
catch (_a) { }
|
|
47
|
+
var first = !_this.observers.size;
|
|
48
|
+
_this.observers.add(observer);
|
|
49
|
+
var last = _this.last;
|
|
50
|
+
if (last && last.error) {
|
|
51
|
+
observer.error && observer.error(last.error);
|
|
52
|
+
}
|
|
53
|
+
else if (last && last.result) {
|
|
54
|
+
observer.next && observer.next(last.result);
|
|
55
|
+
}
|
|
56
|
+
if (first) {
|
|
57
|
+
_this.reobserve().catch(function () { });
|
|
58
|
+
}
|
|
59
|
+
return function () {
|
|
60
|
+
if (_this.observers.delete(observer) && !_this.observers.size) {
|
|
61
|
+
_this.tearDownQuery();
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
}) || this;
|
|
65
|
+
_this.observers = new Set();
|
|
66
|
+
_this.subscriptions = new Set();
|
|
67
|
+
_this.queryInfo = queryInfo;
|
|
68
|
+
_this.queryManager = queryManager;
|
|
69
|
+
_this.isTornDown = false;
|
|
70
|
+
var _b = queryManager.defaultOptions.watchQuery, _c = _b === void 0 ? {} : _b, _d = _c.fetchPolicy, defaultFetchPolicy = _d === void 0 ? "cache-first" : _d;
|
|
71
|
+
var _e = options.fetchPolicy, fetchPolicy = _e === void 0 ? defaultFetchPolicy : _e, _f = options.initialFetchPolicy, initialFetchPolicy = _f === void 0 ? (fetchPolicy === "standby" ? defaultFetchPolicy : fetchPolicy) : _f;
|
|
72
|
+
_this.options = tslib.__assign(tslib.__assign({}, options), { initialFetchPolicy: initialFetchPolicy, fetchPolicy: fetchPolicy });
|
|
73
|
+
_this.queryId = queryInfo.queryId || queryManager.generateQueryId();
|
|
74
|
+
var opDef = utilities.getOperationDefinition(_this.query);
|
|
75
|
+
_this.queryName = opDef && opDef.name && opDef.name.value;
|
|
76
|
+
return _this;
|
|
77
|
+
}
|
|
78
|
+
Object.defineProperty(ObservableQuery.prototype, "query", {
|
|
79
|
+
get: function () {
|
|
80
|
+
return this.queryManager.transform(this.options.query).document;
|
|
81
|
+
},
|
|
82
|
+
enumerable: false,
|
|
83
|
+
configurable: true
|
|
84
|
+
});
|
|
85
|
+
Object.defineProperty(ObservableQuery.prototype, "variables", {
|
|
86
|
+
get: function () {
|
|
87
|
+
return this.options.variables;
|
|
88
|
+
},
|
|
89
|
+
enumerable: false,
|
|
90
|
+
configurable: true
|
|
91
|
+
});
|
|
92
|
+
ObservableQuery.prototype.result = function () {
|
|
93
|
+
var _this = this;
|
|
94
|
+
return new Promise(function (resolve, reject) {
|
|
95
|
+
var observer = {
|
|
96
|
+
next: function (result) {
|
|
97
|
+
resolve(result);
|
|
98
|
+
_this.observers.delete(observer);
|
|
99
|
+
if (!_this.observers.size) {
|
|
100
|
+
_this.queryManager.removeQuery(_this.queryId);
|
|
101
|
+
}
|
|
102
|
+
setTimeout(function () {
|
|
103
|
+
subscription.unsubscribe();
|
|
104
|
+
}, 0);
|
|
105
|
+
},
|
|
106
|
+
error: reject,
|
|
107
|
+
};
|
|
108
|
+
var subscription = _this.subscribe(observer);
|
|
109
|
+
});
|
|
110
|
+
};
|
|
111
|
+
ObservableQuery.prototype.getCurrentResult = function (saveAsLastResult) {
|
|
112
|
+
if (saveAsLastResult === void 0) { saveAsLastResult = true; }
|
|
113
|
+
var lastResult = this.getLastResult(true);
|
|
114
|
+
var networkStatus = this.queryInfo.networkStatus ||
|
|
115
|
+
(lastResult && lastResult.networkStatus) ||
|
|
116
|
+
exports.NetworkStatus.ready;
|
|
117
|
+
var result = tslib.__assign(tslib.__assign({}, lastResult), { loading: isNetworkRequestInFlight(networkStatus), networkStatus: networkStatus });
|
|
118
|
+
var _a = this.options.fetchPolicy, fetchPolicy = _a === void 0 ? "cache-first" : _a;
|
|
119
|
+
if (fetchPolicy === 'network-only' ||
|
|
120
|
+
fetchPolicy === 'no-cache' ||
|
|
121
|
+
fetchPolicy === 'standby' ||
|
|
122
|
+
this.queryManager.transform(this.options.query).hasForcedResolvers) ;
|
|
123
|
+
else {
|
|
124
|
+
var diff = this.queryInfo.getDiff();
|
|
125
|
+
if (diff.complete || this.options.returnPartialData) {
|
|
126
|
+
result.data = diff.result;
|
|
127
|
+
}
|
|
128
|
+
if (equality.equal(result.data, {})) {
|
|
129
|
+
result.data = void 0;
|
|
130
|
+
}
|
|
131
|
+
if (diff.complete) {
|
|
132
|
+
delete result.partial;
|
|
133
|
+
if (diff.complete &&
|
|
134
|
+
result.networkStatus === exports.NetworkStatus.loading &&
|
|
135
|
+
(fetchPolicy === 'cache-first' ||
|
|
136
|
+
fetchPolicy === 'cache-only')) {
|
|
137
|
+
result.networkStatus = exports.NetworkStatus.ready;
|
|
138
|
+
result.loading = false;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
result.partial = true;
|
|
143
|
+
}
|
|
144
|
+
if (__DEV__ &&
|
|
145
|
+
!diff.complete &&
|
|
146
|
+
!this.options.partialRefetch &&
|
|
147
|
+
!result.loading &&
|
|
148
|
+
!result.data &&
|
|
149
|
+
!result.error) {
|
|
150
|
+
logMissingFieldErrors(diff.missing);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if (saveAsLastResult) {
|
|
154
|
+
this.updateLastResult(result);
|
|
155
|
+
}
|
|
156
|
+
return result;
|
|
157
|
+
};
|
|
158
|
+
ObservableQuery.prototype.isDifferentFromLastResult = function (newResult) {
|
|
159
|
+
return !this.last || !equality.equal(this.last.result, newResult);
|
|
160
|
+
};
|
|
161
|
+
ObservableQuery.prototype.getLast = function (key, variablesMustMatch) {
|
|
162
|
+
var last = this.last;
|
|
163
|
+
if (last &&
|
|
164
|
+
last[key] &&
|
|
165
|
+
(!variablesMustMatch || equality.equal(last.variables, this.variables))) {
|
|
166
|
+
return last[key];
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
ObservableQuery.prototype.getLastResult = function (variablesMustMatch) {
|
|
170
|
+
return this.getLast("result", variablesMustMatch);
|
|
171
|
+
};
|
|
172
|
+
ObservableQuery.prototype.getLastError = function (variablesMustMatch) {
|
|
173
|
+
return this.getLast("error", variablesMustMatch);
|
|
174
|
+
};
|
|
175
|
+
ObservableQuery.prototype.resetLastResults = function () {
|
|
176
|
+
delete this.last;
|
|
177
|
+
this.isTornDown = false;
|
|
178
|
+
};
|
|
179
|
+
ObservableQuery.prototype.resetQueryStoreErrors = function () {
|
|
180
|
+
this.queryManager.resetErrors(this.queryId);
|
|
181
|
+
};
|
|
182
|
+
ObservableQuery.prototype.refetch = function (variables) {
|
|
183
|
+
var _a;
|
|
184
|
+
var reobserveOptions = {
|
|
185
|
+
pollInterval: 0,
|
|
186
|
+
};
|
|
187
|
+
var fetchPolicy = this.options.fetchPolicy;
|
|
188
|
+
if (fetchPolicy === 'cache-and-network') {
|
|
189
|
+
reobserveOptions.fetchPolicy = fetchPolicy;
|
|
190
|
+
}
|
|
191
|
+
else if (fetchPolicy === 'no-cache') {
|
|
192
|
+
reobserveOptions.fetchPolicy = 'no-cache';
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
reobserveOptions.fetchPolicy = 'network-only';
|
|
196
|
+
}
|
|
197
|
+
if (__DEV__ && variables && hasOwnProperty$1.call(variables, "variables")) {
|
|
198
|
+
var queryDef = utilities.getQueryDefinition(this.query);
|
|
199
|
+
var vars = queryDef.variableDefinitions;
|
|
200
|
+
if (!vars || !vars.some(function (v) { return v.variable.name.value === "variables"; })) {
|
|
201
|
+
__DEV__ && globals.invariant.warn("Called refetch(".concat(JSON.stringify(variables), ") for query ").concat(((_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 })?"));
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
if (variables && !equality.equal(this.options.variables, variables)) {
|
|
205
|
+
reobserveOptions.variables = this.options.variables = tslib.__assign(tslib.__assign({}, this.options.variables), variables);
|
|
206
|
+
}
|
|
207
|
+
this.queryInfo.resetLastWrite();
|
|
208
|
+
return this.reobserve(reobserveOptions, exports.NetworkStatus.refetch);
|
|
209
|
+
};
|
|
210
|
+
ObservableQuery.prototype.fetchMore = function (fetchMoreOptions) {
|
|
211
|
+
var _this = this;
|
|
212
|
+
var combinedOptions = tslib.__assign(tslib.__assign({}, (fetchMoreOptions.query ? fetchMoreOptions : tslib.__assign(tslib.__assign(tslib.__assign(tslib.__assign({}, this.options), { query: this.query }), fetchMoreOptions), { variables: tslib.__assign(tslib.__assign({}, this.options.variables), fetchMoreOptions.variables) }))), { fetchPolicy: "no-cache" });
|
|
213
|
+
var qid = this.queryManager.generateQueryId();
|
|
214
|
+
var queryInfo = this.queryInfo;
|
|
215
|
+
var originalNetworkStatus = queryInfo.networkStatus;
|
|
216
|
+
queryInfo.networkStatus = exports.NetworkStatus.fetchMore;
|
|
217
|
+
if (combinedOptions.notifyOnNetworkStatusChange) {
|
|
218
|
+
this.observe();
|
|
219
|
+
}
|
|
220
|
+
var updatedQuerySet = new Set();
|
|
221
|
+
return this.queryManager.fetchQuery(qid, combinedOptions, exports.NetworkStatus.fetchMore).then(function (fetchMoreResult) {
|
|
222
|
+
_this.queryManager.removeQuery(qid);
|
|
223
|
+
if (queryInfo.networkStatus === exports.NetworkStatus.fetchMore) {
|
|
224
|
+
queryInfo.networkStatus = originalNetworkStatus;
|
|
225
|
+
}
|
|
226
|
+
_this.queryManager.cache.batch({
|
|
227
|
+
update: function (cache) {
|
|
228
|
+
var updateQuery = fetchMoreOptions.updateQuery;
|
|
229
|
+
if (updateQuery) {
|
|
230
|
+
cache.updateQuery({
|
|
231
|
+
query: _this.query,
|
|
232
|
+
variables: _this.variables,
|
|
233
|
+
returnPartialData: true,
|
|
234
|
+
optimistic: false,
|
|
235
|
+
}, function (previous) { return updateQuery(previous, {
|
|
236
|
+
fetchMoreResult: fetchMoreResult.data,
|
|
237
|
+
variables: combinedOptions.variables,
|
|
238
|
+
}); });
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
cache.writeQuery({
|
|
242
|
+
query: combinedOptions.query,
|
|
243
|
+
variables: combinedOptions.variables,
|
|
244
|
+
data: fetchMoreResult.data,
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
},
|
|
248
|
+
onWatchUpdated: function (watch) {
|
|
249
|
+
updatedQuerySet.add(watch.query);
|
|
250
|
+
},
|
|
251
|
+
});
|
|
252
|
+
return fetchMoreResult;
|
|
253
|
+
}).finally(function () {
|
|
254
|
+
if (!updatedQuerySet.has(_this.query)) {
|
|
255
|
+
reobserveCacheFirst(_this);
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
};
|
|
259
|
+
ObservableQuery.prototype.subscribeToMore = function (options) {
|
|
260
|
+
var _this = this;
|
|
261
|
+
var subscription = this.queryManager
|
|
262
|
+
.startGraphQLSubscription({
|
|
263
|
+
query: options.document,
|
|
264
|
+
variables: options.variables,
|
|
265
|
+
context: options.context,
|
|
266
|
+
})
|
|
267
|
+
.subscribe({
|
|
268
|
+
next: function (subscriptionData) {
|
|
269
|
+
var updateQuery = options.updateQuery;
|
|
270
|
+
if (updateQuery) {
|
|
271
|
+
_this.updateQuery(function (previous, _a) {
|
|
272
|
+
var variables = _a.variables;
|
|
273
|
+
return updateQuery(previous, {
|
|
274
|
+
subscriptionData: subscriptionData,
|
|
275
|
+
variables: variables,
|
|
276
|
+
});
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
},
|
|
280
|
+
error: function (err) {
|
|
281
|
+
if (options.onError) {
|
|
282
|
+
options.onError(err);
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
__DEV__ && globals.invariant.error('Unhandled GraphQL subscription error', err);
|
|
286
|
+
},
|
|
287
|
+
});
|
|
288
|
+
this.subscriptions.add(subscription);
|
|
289
|
+
return function () {
|
|
290
|
+
if (_this.subscriptions.delete(subscription)) {
|
|
291
|
+
subscription.unsubscribe();
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
};
|
|
295
|
+
ObservableQuery.prototype.setOptions = function (newOptions) {
|
|
296
|
+
return this.reobserve(newOptions);
|
|
297
|
+
};
|
|
298
|
+
ObservableQuery.prototype.setVariables = function (variables) {
|
|
299
|
+
if (equality.equal(this.variables, variables)) {
|
|
300
|
+
return this.observers.size
|
|
301
|
+
? this.result()
|
|
302
|
+
: Promise.resolve();
|
|
303
|
+
}
|
|
304
|
+
this.options.variables = variables;
|
|
305
|
+
if (!this.observers.size) {
|
|
306
|
+
return Promise.resolve();
|
|
307
|
+
}
|
|
308
|
+
return this.reobserve({
|
|
309
|
+
fetchPolicy: this.options.initialFetchPolicy,
|
|
310
|
+
variables: variables,
|
|
311
|
+
}, exports.NetworkStatus.setVariables);
|
|
312
|
+
};
|
|
313
|
+
ObservableQuery.prototype.updateQuery = function (mapFn) {
|
|
314
|
+
var queryManager = this.queryManager;
|
|
315
|
+
var result = queryManager.cache.diff({
|
|
316
|
+
query: this.options.query,
|
|
317
|
+
variables: this.variables,
|
|
318
|
+
returnPartialData: true,
|
|
319
|
+
optimistic: false,
|
|
320
|
+
}).result;
|
|
321
|
+
var newResult = mapFn(result, {
|
|
322
|
+
variables: this.variables,
|
|
323
|
+
});
|
|
324
|
+
if (newResult) {
|
|
325
|
+
queryManager.cache.writeQuery({
|
|
326
|
+
query: this.options.query,
|
|
327
|
+
data: newResult,
|
|
328
|
+
variables: this.variables,
|
|
329
|
+
});
|
|
330
|
+
queryManager.broadcastQueries();
|
|
331
|
+
}
|
|
332
|
+
};
|
|
333
|
+
ObservableQuery.prototype.startPolling = function (pollInterval) {
|
|
334
|
+
this.options.pollInterval = pollInterval;
|
|
335
|
+
this.updatePolling();
|
|
336
|
+
};
|
|
337
|
+
ObservableQuery.prototype.stopPolling = function () {
|
|
338
|
+
this.options.pollInterval = 0;
|
|
339
|
+
this.updatePolling();
|
|
340
|
+
};
|
|
341
|
+
ObservableQuery.prototype.applyNextFetchPolicy = function (reason, options) {
|
|
342
|
+
if (options.nextFetchPolicy) {
|
|
343
|
+
var _a = options.fetchPolicy, fetchPolicy = _a === void 0 ? "cache-first" : _a, _b = options.initialFetchPolicy, initialFetchPolicy = _b === void 0 ? fetchPolicy : _b;
|
|
344
|
+
if (typeof options.nextFetchPolicy === "function") {
|
|
345
|
+
options.fetchPolicy = options.nextFetchPolicy(fetchPolicy, {
|
|
346
|
+
reason: reason,
|
|
347
|
+
options: options,
|
|
348
|
+
observable: this,
|
|
349
|
+
initialFetchPolicy: initialFetchPolicy,
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
else if (reason === "variables-changed") {
|
|
353
|
+
options.fetchPolicy = initialFetchPolicy;
|
|
354
|
+
}
|
|
355
|
+
else {
|
|
356
|
+
options.fetchPolicy = options.nextFetchPolicy;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
return options.fetchPolicy;
|
|
360
|
+
};
|
|
361
|
+
ObservableQuery.prototype.fetch = function (options, newNetworkStatus) {
|
|
362
|
+
this.queryManager.setObservableQuery(this);
|
|
363
|
+
return this.queryManager.fetchQueryObservable(this.queryId, options, newNetworkStatus);
|
|
364
|
+
};
|
|
365
|
+
ObservableQuery.prototype.updatePolling = function () {
|
|
366
|
+
var _this = this;
|
|
367
|
+
if (this.queryManager.ssrMode) {
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
var _a = this, pollingInfo = _a.pollingInfo, pollInterval = _a.options.pollInterval;
|
|
371
|
+
if (!pollInterval) {
|
|
372
|
+
if (pollingInfo) {
|
|
373
|
+
clearTimeout(pollingInfo.timeout);
|
|
374
|
+
delete this.pollingInfo;
|
|
375
|
+
}
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
if (pollingInfo &&
|
|
379
|
+
pollingInfo.interval === pollInterval) {
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
__DEV__ ? globals.invariant(pollInterval, 'Attempted to start a polling query without a polling interval.') : globals.invariant(pollInterval, 10);
|
|
383
|
+
var info = pollingInfo || (this.pollingInfo = {});
|
|
384
|
+
info.interval = pollInterval;
|
|
385
|
+
var maybeFetch = function () {
|
|
386
|
+
if (_this.pollingInfo) {
|
|
387
|
+
if (!isNetworkRequestInFlight(_this.queryInfo.networkStatus)) {
|
|
388
|
+
_this.reobserve({
|
|
389
|
+
fetchPolicy: "network-only",
|
|
390
|
+
}, exports.NetworkStatus.poll).then(poll, poll);
|
|
391
|
+
}
|
|
392
|
+
else {
|
|
393
|
+
poll();
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
};
|
|
397
|
+
var poll = function () {
|
|
398
|
+
var info = _this.pollingInfo;
|
|
399
|
+
if (info) {
|
|
400
|
+
clearTimeout(info.timeout);
|
|
401
|
+
info.timeout = setTimeout(maybeFetch, info.interval);
|
|
402
|
+
}
|
|
403
|
+
};
|
|
404
|
+
poll();
|
|
405
|
+
};
|
|
406
|
+
ObservableQuery.prototype.updateLastResult = function (newResult, variables) {
|
|
407
|
+
if (variables === void 0) { variables = this.variables; }
|
|
408
|
+
this.last = tslib.__assign(tslib.__assign({}, this.last), { result: this.queryManager.assumeImmutableResults
|
|
409
|
+
? newResult
|
|
410
|
+
: utilities.cloneDeep(newResult), variables: variables });
|
|
411
|
+
if (!utilities.isNonEmptyArray(newResult.errors)) {
|
|
412
|
+
delete this.last.error;
|
|
413
|
+
}
|
|
414
|
+
return this.last;
|
|
415
|
+
};
|
|
416
|
+
ObservableQuery.prototype.reobserve = function (newOptions, newNetworkStatus) {
|
|
417
|
+
var _this = this;
|
|
418
|
+
this.isTornDown = false;
|
|
419
|
+
var useDisposableConcast = newNetworkStatus === exports.NetworkStatus.refetch ||
|
|
420
|
+
newNetworkStatus === exports.NetworkStatus.fetchMore ||
|
|
421
|
+
newNetworkStatus === exports.NetworkStatus.poll;
|
|
422
|
+
var oldVariables = this.options.variables;
|
|
423
|
+
var oldFetchPolicy = this.options.fetchPolicy;
|
|
424
|
+
var mergedOptions = utilities.compact(this.options, newOptions || {});
|
|
425
|
+
var options = useDisposableConcast
|
|
426
|
+
? mergedOptions
|
|
427
|
+
: assign(this.options, mergedOptions);
|
|
428
|
+
if (!useDisposableConcast) {
|
|
429
|
+
this.updatePolling();
|
|
430
|
+
if (newOptions &&
|
|
431
|
+
newOptions.variables &&
|
|
432
|
+
!equality.equal(newOptions.variables, oldVariables) &&
|
|
433
|
+
(!newOptions.fetchPolicy || newOptions.fetchPolicy === oldFetchPolicy)) {
|
|
434
|
+
this.applyNextFetchPolicy("variables-changed", options);
|
|
435
|
+
if (newNetworkStatus === void 0) {
|
|
436
|
+
newNetworkStatus = exports.NetworkStatus.setVariables;
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
var variables = options.variables && tslib.__assign({}, options.variables);
|
|
441
|
+
var concast = this.fetch(options, newNetworkStatus);
|
|
442
|
+
var observer = {
|
|
443
|
+
next: function (result) {
|
|
444
|
+
_this.reportResult(result, variables);
|
|
445
|
+
},
|
|
446
|
+
error: function (error) {
|
|
447
|
+
_this.reportError(error, variables);
|
|
448
|
+
},
|
|
449
|
+
};
|
|
450
|
+
if (!useDisposableConcast) {
|
|
451
|
+
if (this.concast && this.observer) {
|
|
452
|
+
this.concast.removeObserver(this.observer, true);
|
|
453
|
+
}
|
|
454
|
+
this.concast = concast;
|
|
455
|
+
this.observer = observer;
|
|
456
|
+
}
|
|
457
|
+
concast.addObserver(observer);
|
|
458
|
+
return concast.promise;
|
|
459
|
+
};
|
|
460
|
+
ObservableQuery.prototype.observe = function () {
|
|
461
|
+
this.reportResult(this.getCurrentResult(false), this.variables);
|
|
462
|
+
};
|
|
463
|
+
ObservableQuery.prototype.reportResult = function (result, variables) {
|
|
464
|
+
var lastError = this.getLastError();
|
|
465
|
+
if (lastError || this.isDifferentFromLastResult(result)) {
|
|
466
|
+
if (lastError || !result.partial || this.options.returnPartialData) {
|
|
467
|
+
this.updateLastResult(result, variables);
|
|
468
|
+
}
|
|
469
|
+
utilities.iterateObserversSafely(this.observers, 'next', result);
|
|
470
|
+
}
|
|
471
|
+
};
|
|
472
|
+
ObservableQuery.prototype.reportError = function (error, variables) {
|
|
473
|
+
var errorResult = tslib.__assign(tslib.__assign({}, this.getLastResult()), { error: error, errors: error.graphQLErrors, networkStatus: exports.NetworkStatus.error, loading: false });
|
|
474
|
+
this.updateLastResult(errorResult, variables);
|
|
475
|
+
utilities.iterateObserversSafely(this.observers, 'error', this.last.error = error);
|
|
476
|
+
};
|
|
477
|
+
ObservableQuery.prototype.hasObservers = function () {
|
|
478
|
+
return this.observers.size > 0;
|
|
479
|
+
};
|
|
480
|
+
ObservableQuery.prototype.tearDownQuery = function () {
|
|
481
|
+
if (this.isTornDown)
|
|
482
|
+
return;
|
|
483
|
+
if (this.concast && this.observer) {
|
|
484
|
+
this.concast.removeObserver(this.observer);
|
|
485
|
+
delete this.concast;
|
|
486
|
+
delete this.observer;
|
|
487
|
+
}
|
|
488
|
+
this.stopPolling();
|
|
489
|
+
this.subscriptions.forEach(function (sub) { return sub.unsubscribe(); });
|
|
490
|
+
this.subscriptions.clear();
|
|
491
|
+
this.queryManager.stopQuery(this.queryId);
|
|
492
|
+
this.observers.clear();
|
|
493
|
+
this.isTornDown = true;
|
|
494
|
+
};
|
|
495
|
+
return ObservableQuery;
|
|
496
|
+
}(utilities.Observable));
|
|
497
|
+
utilities.fixObservableSubclass(ObservableQuery);
|
|
498
|
+
function reobserveCacheFirst(obsQuery) {
|
|
499
|
+
var _a = obsQuery.options, fetchPolicy = _a.fetchPolicy, nextFetchPolicy = _a.nextFetchPolicy;
|
|
500
|
+
if (fetchPolicy === "cache-and-network" ||
|
|
501
|
+
fetchPolicy === "network-only") {
|
|
502
|
+
return obsQuery.reobserve({
|
|
503
|
+
fetchPolicy: "cache-first",
|
|
504
|
+
nextFetchPolicy: function () {
|
|
505
|
+
this.nextFetchPolicy = nextFetchPolicy;
|
|
506
|
+
if (typeof nextFetchPolicy === "function") {
|
|
507
|
+
return nextFetchPolicy.apply(this, arguments);
|
|
508
|
+
}
|
|
509
|
+
return fetchPolicy;
|
|
510
|
+
},
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
return obsQuery.reobserve();
|
|
514
|
+
}
|
|
515
|
+
function defaultSubscriptionObserverErrorCallback(error) {
|
|
516
|
+
__DEV__ && globals.invariant.error('Unhandled error', error.message, error.stack);
|
|
517
|
+
}
|
|
518
|
+
function logMissingFieldErrors(missing) {
|
|
519
|
+
if (__DEV__ && missing) {
|
|
520
|
+
__DEV__ && globals.invariant.debug("Missing cache result fields: ".concat(JSON.stringify(missing)), missing);
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
var LocalState = (function () {
|
|
525
|
+
function LocalState(_a) {
|
|
526
|
+
var cache = _a.cache, client = _a.client, resolvers = _a.resolvers, fragmentMatcher = _a.fragmentMatcher;
|
|
527
|
+
this.cache = cache;
|
|
528
|
+
if (client) {
|
|
529
|
+
this.client = client;
|
|
530
|
+
}
|
|
531
|
+
if (resolvers) {
|
|
532
|
+
this.addResolvers(resolvers);
|
|
533
|
+
}
|
|
534
|
+
if (fragmentMatcher) {
|
|
535
|
+
this.setFragmentMatcher(fragmentMatcher);
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
LocalState.prototype.addResolvers = function (resolvers) {
|
|
539
|
+
var _this = this;
|
|
540
|
+
this.resolvers = this.resolvers || {};
|
|
541
|
+
if (Array.isArray(resolvers)) {
|
|
542
|
+
resolvers.forEach(function (resolverGroup) {
|
|
543
|
+
_this.resolvers = utilities.mergeDeep(_this.resolvers, resolverGroup);
|
|
544
|
+
});
|
|
545
|
+
}
|
|
546
|
+
else {
|
|
547
|
+
this.resolvers = utilities.mergeDeep(this.resolvers, resolvers);
|
|
548
|
+
}
|
|
549
|
+
};
|
|
550
|
+
LocalState.prototype.setResolvers = function (resolvers) {
|
|
551
|
+
this.resolvers = {};
|
|
552
|
+
this.addResolvers(resolvers);
|
|
553
|
+
};
|
|
554
|
+
LocalState.prototype.getResolvers = function () {
|
|
555
|
+
return this.resolvers || {};
|
|
556
|
+
};
|
|
557
|
+
LocalState.prototype.runResolvers = function (_a) {
|
|
558
|
+
var document = _a.document, remoteResult = _a.remoteResult, context = _a.context, variables = _a.variables, _b = _a.onlyRunForcedResolvers, onlyRunForcedResolvers = _b === void 0 ? false : _b;
|
|
559
|
+
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
560
|
+
return tslib.__generator(this, function (_c) {
|
|
561
|
+
if (document) {
|
|
562
|
+
return [2, this.resolveDocument(document, remoteResult.data, context, variables, this.fragmentMatcher, onlyRunForcedResolvers).then(function (localResult) { return (tslib.__assign(tslib.__assign({}, remoteResult), { data: localResult.result })); })];
|
|
563
|
+
}
|
|
564
|
+
return [2, remoteResult];
|
|
565
|
+
});
|
|
566
|
+
});
|
|
567
|
+
};
|
|
568
|
+
LocalState.prototype.setFragmentMatcher = function (fragmentMatcher) {
|
|
569
|
+
this.fragmentMatcher = fragmentMatcher;
|
|
570
|
+
};
|
|
571
|
+
LocalState.prototype.getFragmentMatcher = function () {
|
|
572
|
+
return this.fragmentMatcher;
|
|
573
|
+
};
|
|
574
|
+
LocalState.prototype.clientQuery = function (document) {
|
|
575
|
+
if (utilities.hasDirectives(['client'], document)) {
|
|
576
|
+
if (this.resolvers) {
|
|
577
|
+
return document;
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
return null;
|
|
581
|
+
};
|
|
582
|
+
LocalState.prototype.serverQuery = function (document) {
|
|
583
|
+
return utilities.removeClientSetsFromDocument(document);
|
|
584
|
+
};
|
|
585
|
+
LocalState.prototype.prepareContext = function (context) {
|
|
586
|
+
var cache = this.cache;
|
|
587
|
+
return tslib.__assign(tslib.__assign({}, context), { cache: cache, getCacheKey: function (obj) {
|
|
588
|
+
return cache.identify(obj);
|
|
589
|
+
} });
|
|
590
|
+
};
|
|
591
|
+
LocalState.prototype.addExportedVariables = function (document, variables, context) {
|
|
592
|
+
if (variables === void 0) { variables = {}; }
|
|
593
|
+
if (context === void 0) { context = {}; }
|
|
594
|
+
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
595
|
+
return tslib.__generator(this, function (_a) {
|
|
596
|
+
if (document) {
|
|
597
|
+
return [2, this.resolveDocument(document, this.buildRootValueFromCache(document, variables) || {}, this.prepareContext(context), variables).then(function (data) { return (tslib.__assign(tslib.__assign({}, variables), data.exportedVariables)); })];
|
|
598
|
+
}
|
|
599
|
+
return [2, tslib.__assign({}, variables)];
|
|
600
|
+
});
|
|
601
|
+
});
|
|
602
|
+
};
|
|
603
|
+
LocalState.prototype.shouldForceResolvers = function (document) {
|
|
604
|
+
var forceResolvers = false;
|
|
605
|
+
graphql.visit(document, {
|
|
606
|
+
Directive: {
|
|
607
|
+
enter: function (node) {
|
|
608
|
+
if (node.name.value === 'client' && node.arguments) {
|
|
609
|
+
forceResolvers = node.arguments.some(function (arg) {
|
|
610
|
+
return arg.name.value === 'always' &&
|
|
611
|
+
arg.value.kind === 'BooleanValue' &&
|
|
612
|
+
arg.value.value === true;
|
|
613
|
+
});
|
|
614
|
+
if (forceResolvers) {
|
|
615
|
+
return graphql.BREAK;
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
},
|
|
619
|
+
},
|
|
620
|
+
});
|
|
621
|
+
return forceResolvers;
|
|
622
|
+
};
|
|
623
|
+
LocalState.prototype.buildRootValueFromCache = function (document, variables) {
|
|
624
|
+
return this.cache.diff({
|
|
625
|
+
query: utilities.buildQueryFromSelectionSet(document),
|
|
626
|
+
variables: variables,
|
|
627
|
+
returnPartialData: true,
|
|
628
|
+
optimistic: false,
|
|
629
|
+
}).result;
|
|
630
|
+
};
|
|
631
|
+
LocalState.prototype.resolveDocument = function (document, rootValue, context, variables, fragmentMatcher, onlyRunForcedResolvers) {
|
|
632
|
+
if (context === void 0) { context = {}; }
|
|
633
|
+
if (variables === void 0) { variables = {}; }
|
|
634
|
+
if (fragmentMatcher === void 0) { fragmentMatcher = function () { return true; }; }
|
|
635
|
+
if (onlyRunForcedResolvers === void 0) { onlyRunForcedResolvers = false; }
|
|
636
|
+
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
637
|
+
var mainDefinition, fragments, fragmentMap, definitionOperation, defaultOperationType, _a, cache, client, execContext;
|
|
638
|
+
return tslib.__generator(this, function (_b) {
|
|
639
|
+
mainDefinition = utilities.getMainDefinition(document);
|
|
640
|
+
fragments = utilities.getFragmentDefinitions(document);
|
|
641
|
+
fragmentMap = utilities.createFragmentMap(fragments);
|
|
642
|
+
definitionOperation = mainDefinition
|
|
643
|
+
.operation;
|
|
644
|
+
defaultOperationType = definitionOperation
|
|
645
|
+
? definitionOperation.charAt(0).toUpperCase() +
|
|
646
|
+
definitionOperation.slice(1)
|
|
647
|
+
: 'Query';
|
|
648
|
+
_a = this, cache = _a.cache, client = _a.client;
|
|
649
|
+
execContext = {
|
|
650
|
+
fragmentMap: fragmentMap,
|
|
651
|
+
context: tslib.__assign(tslib.__assign({}, context), { cache: cache, client: client }),
|
|
652
|
+
variables: variables,
|
|
653
|
+
fragmentMatcher: fragmentMatcher,
|
|
654
|
+
defaultOperationType: defaultOperationType,
|
|
655
|
+
exportedVariables: {},
|
|
656
|
+
onlyRunForcedResolvers: onlyRunForcedResolvers,
|
|
657
|
+
};
|
|
658
|
+
return [2, this.resolveSelectionSet(mainDefinition.selectionSet, rootValue, execContext).then(function (result) { return ({
|
|
659
|
+
result: result,
|
|
660
|
+
exportedVariables: execContext.exportedVariables,
|
|
661
|
+
}); })];
|
|
662
|
+
});
|
|
663
|
+
});
|
|
664
|
+
};
|
|
665
|
+
LocalState.prototype.resolveSelectionSet = function (selectionSet, rootValue, execContext) {
|
|
666
|
+
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
667
|
+
var fragmentMap, context, variables, resultsToMerge, execute;
|
|
668
|
+
var _this = this;
|
|
669
|
+
return tslib.__generator(this, function (_a) {
|
|
670
|
+
fragmentMap = execContext.fragmentMap, context = execContext.context, variables = execContext.variables;
|
|
671
|
+
resultsToMerge = [rootValue];
|
|
672
|
+
execute = function (selection) { return tslib.__awaiter(_this, void 0, void 0, function () {
|
|
673
|
+
var fragment, typeCondition;
|
|
674
|
+
return tslib.__generator(this, function (_a) {
|
|
675
|
+
if (!utilities.shouldInclude(selection, variables)) {
|
|
676
|
+
return [2];
|
|
677
|
+
}
|
|
678
|
+
if (utilities.isField(selection)) {
|
|
679
|
+
return [2, this.resolveField(selection, rootValue, execContext).then(function (fieldResult) {
|
|
680
|
+
var _a;
|
|
681
|
+
if (typeof fieldResult !== 'undefined') {
|
|
682
|
+
resultsToMerge.push((_a = {},
|
|
683
|
+
_a[utilities.resultKeyNameFromField(selection)] = fieldResult,
|
|
684
|
+
_a));
|
|
685
|
+
}
|
|
686
|
+
})];
|
|
687
|
+
}
|
|
688
|
+
if (utilities.isInlineFragment(selection)) {
|
|
689
|
+
fragment = selection;
|
|
690
|
+
}
|
|
691
|
+
else {
|
|
692
|
+
fragment = fragmentMap[selection.name.value];
|
|
693
|
+
__DEV__ ? globals.invariant(fragment, "No fragment named ".concat(selection.name.value)) : globals.invariant(fragment, 9);
|
|
694
|
+
}
|
|
695
|
+
if (fragment && fragment.typeCondition) {
|
|
696
|
+
typeCondition = fragment.typeCondition.name.value;
|
|
697
|
+
if (execContext.fragmentMatcher(rootValue, typeCondition, context)) {
|
|
698
|
+
return [2, this.resolveSelectionSet(fragment.selectionSet, rootValue, execContext).then(function (fragmentResult) {
|
|
699
|
+
resultsToMerge.push(fragmentResult);
|
|
700
|
+
})];
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
return [2];
|
|
704
|
+
});
|
|
705
|
+
}); };
|
|
706
|
+
return [2, Promise.all(selectionSet.selections.map(execute)).then(function () {
|
|
707
|
+
return utilities.mergeDeepArray(resultsToMerge);
|
|
708
|
+
})];
|
|
709
|
+
});
|
|
710
|
+
});
|
|
711
|
+
};
|
|
712
|
+
LocalState.prototype.resolveField = function (field, rootValue, execContext) {
|
|
713
|
+
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
714
|
+
var variables, fieldName, aliasedFieldName, aliasUsed, defaultResult, resultPromise, resolverType, resolverMap, resolve;
|
|
715
|
+
var _this = this;
|
|
716
|
+
return tslib.__generator(this, function (_a) {
|
|
717
|
+
variables = execContext.variables;
|
|
718
|
+
fieldName = field.name.value;
|
|
719
|
+
aliasedFieldName = utilities.resultKeyNameFromField(field);
|
|
720
|
+
aliasUsed = fieldName !== aliasedFieldName;
|
|
721
|
+
defaultResult = rootValue[aliasedFieldName] || rootValue[fieldName];
|
|
722
|
+
resultPromise = Promise.resolve(defaultResult);
|
|
723
|
+
if (!execContext.onlyRunForcedResolvers ||
|
|
724
|
+
this.shouldForceResolvers(field)) {
|
|
725
|
+
resolverType = rootValue.__typename || execContext.defaultOperationType;
|
|
726
|
+
resolverMap = this.resolvers && this.resolvers[resolverType];
|
|
727
|
+
if (resolverMap) {
|
|
728
|
+
resolve = resolverMap[aliasUsed ? fieldName : aliasedFieldName];
|
|
729
|
+
if (resolve) {
|
|
730
|
+
resultPromise = Promise.resolve(cache.cacheSlot.withValue(this.cache, resolve, [
|
|
731
|
+
rootValue,
|
|
732
|
+
utilities.argumentsObjectFromField(field, variables),
|
|
733
|
+
execContext.context,
|
|
734
|
+
{ field: field, fragmentMap: execContext.fragmentMap },
|
|
735
|
+
]));
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
return [2, resultPromise.then(function (result) {
|
|
740
|
+
if (result === void 0) { result = defaultResult; }
|
|
741
|
+
if (field.directives) {
|
|
742
|
+
field.directives.forEach(function (directive) {
|
|
743
|
+
if (directive.name.value === 'export' && directive.arguments) {
|
|
744
|
+
directive.arguments.forEach(function (arg) {
|
|
745
|
+
if (arg.name.value === 'as' && arg.value.kind === 'StringValue') {
|
|
746
|
+
execContext.exportedVariables[arg.value.value] = result;
|
|
747
|
+
}
|
|
748
|
+
});
|
|
749
|
+
}
|
|
750
|
+
});
|
|
751
|
+
}
|
|
752
|
+
if (!field.selectionSet) {
|
|
753
|
+
return result;
|
|
754
|
+
}
|
|
755
|
+
if (result == null) {
|
|
756
|
+
return result;
|
|
757
|
+
}
|
|
758
|
+
if (Array.isArray(result)) {
|
|
759
|
+
return _this.resolveSubSelectedArray(field, result, execContext);
|
|
760
|
+
}
|
|
761
|
+
if (field.selectionSet) {
|
|
762
|
+
return _this.resolveSelectionSet(field.selectionSet, result, execContext);
|
|
763
|
+
}
|
|
764
|
+
})];
|
|
765
|
+
});
|
|
766
|
+
});
|
|
767
|
+
};
|
|
768
|
+
LocalState.prototype.resolveSubSelectedArray = function (field, result, execContext) {
|
|
769
|
+
var _this = this;
|
|
770
|
+
return Promise.all(result.map(function (item) {
|
|
771
|
+
if (item === null) {
|
|
772
|
+
return null;
|
|
773
|
+
}
|
|
774
|
+
if (Array.isArray(item)) {
|
|
775
|
+
return _this.resolveSubSelectedArray(field, item, execContext);
|
|
776
|
+
}
|
|
777
|
+
if (field.selectionSet) {
|
|
778
|
+
return _this.resolveSelectionSet(field.selectionSet, item, execContext);
|
|
779
|
+
}
|
|
780
|
+
}));
|
|
781
|
+
};
|
|
782
|
+
return LocalState;
|
|
783
|
+
}());
|
|
784
|
+
|
|
785
|
+
var destructiveMethodCounts = new (utilities.canUseWeakMap ? WeakMap : Map)();
|
|
786
|
+
function wrapDestructiveCacheMethod(cache, methodName) {
|
|
787
|
+
var original = cache[methodName];
|
|
788
|
+
if (typeof original === "function") {
|
|
789
|
+
cache[methodName] = function () {
|
|
790
|
+
destructiveMethodCounts.set(cache, (destructiveMethodCounts.get(cache) + 1) % 1e15);
|
|
791
|
+
return original.apply(this, arguments);
|
|
792
|
+
};
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
function cancelNotifyTimeout(info) {
|
|
796
|
+
if (info["notifyTimeout"]) {
|
|
797
|
+
clearTimeout(info["notifyTimeout"]);
|
|
798
|
+
info["notifyTimeout"] = void 0;
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
var QueryInfo = (function () {
|
|
802
|
+
function QueryInfo(queryManager, queryId) {
|
|
803
|
+
if (queryId === void 0) { queryId = queryManager.generateQueryId(); }
|
|
804
|
+
this.queryId = queryId;
|
|
805
|
+
this.listeners = new Set();
|
|
806
|
+
this.document = null;
|
|
807
|
+
this.lastRequestId = 1;
|
|
808
|
+
this.subscriptions = new Set();
|
|
809
|
+
this.stopped = false;
|
|
810
|
+
this.dirty = false;
|
|
811
|
+
this.observableQuery = null;
|
|
812
|
+
var cache = this.cache = queryManager.cache;
|
|
813
|
+
if (!destructiveMethodCounts.has(cache)) {
|
|
814
|
+
destructiveMethodCounts.set(cache, 0);
|
|
815
|
+
wrapDestructiveCacheMethod(cache, "evict");
|
|
816
|
+
wrapDestructiveCacheMethod(cache, "modify");
|
|
817
|
+
wrapDestructiveCacheMethod(cache, "reset");
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
QueryInfo.prototype.init = function (query) {
|
|
821
|
+
var networkStatus = query.networkStatus || exports.NetworkStatus.loading;
|
|
822
|
+
if (this.variables &&
|
|
823
|
+
this.networkStatus !== exports.NetworkStatus.loading &&
|
|
824
|
+
!equality.equal(this.variables, query.variables)) {
|
|
825
|
+
networkStatus = exports.NetworkStatus.setVariables;
|
|
826
|
+
}
|
|
827
|
+
if (!equality.equal(query.variables, this.variables)) {
|
|
828
|
+
this.lastDiff = void 0;
|
|
829
|
+
}
|
|
830
|
+
Object.assign(this, {
|
|
831
|
+
document: query.document,
|
|
832
|
+
variables: query.variables,
|
|
833
|
+
networkError: null,
|
|
834
|
+
graphQLErrors: this.graphQLErrors || [],
|
|
835
|
+
networkStatus: networkStatus,
|
|
836
|
+
});
|
|
837
|
+
if (query.observableQuery) {
|
|
838
|
+
this.setObservableQuery(query.observableQuery);
|
|
839
|
+
}
|
|
840
|
+
if (query.lastRequestId) {
|
|
841
|
+
this.lastRequestId = query.lastRequestId;
|
|
842
|
+
}
|
|
843
|
+
return this;
|
|
844
|
+
};
|
|
845
|
+
QueryInfo.prototype.reset = function () {
|
|
846
|
+
cancelNotifyTimeout(this);
|
|
847
|
+
this.lastDiff = void 0;
|
|
848
|
+
this.dirty = false;
|
|
849
|
+
};
|
|
850
|
+
QueryInfo.prototype.getDiff = function (variables) {
|
|
851
|
+
if (variables === void 0) { variables = this.variables; }
|
|
852
|
+
var options = this.getDiffOptions(variables);
|
|
853
|
+
if (this.lastDiff && equality.equal(options, this.lastDiff.options)) {
|
|
854
|
+
return this.lastDiff.diff;
|
|
855
|
+
}
|
|
856
|
+
this.updateWatch(this.variables = variables);
|
|
857
|
+
var oq = this.observableQuery;
|
|
858
|
+
if (oq && oq.options.fetchPolicy === "no-cache") {
|
|
859
|
+
return { complete: false };
|
|
860
|
+
}
|
|
861
|
+
var diff = this.cache.diff(options);
|
|
862
|
+
this.updateLastDiff(diff, options);
|
|
863
|
+
return diff;
|
|
864
|
+
};
|
|
865
|
+
QueryInfo.prototype.updateLastDiff = function (diff, options) {
|
|
866
|
+
this.lastDiff = diff ? {
|
|
867
|
+
diff: diff,
|
|
868
|
+
options: options || this.getDiffOptions(),
|
|
869
|
+
} : void 0;
|
|
870
|
+
};
|
|
871
|
+
QueryInfo.prototype.getDiffOptions = function (variables) {
|
|
872
|
+
var _a;
|
|
873
|
+
if (variables === void 0) { variables = this.variables; }
|
|
874
|
+
return {
|
|
875
|
+
query: this.document,
|
|
876
|
+
variables: variables,
|
|
877
|
+
returnPartialData: true,
|
|
878
|
+
optimistic: true,
|
|
879
|
+
canonizeResults: (_a = this.observableQuery) === null || _a === void 0 ? void 0 : _a.options.canonizeResults,
|
|
880
|
+
};
|
|
881
|
+
};
|
|
882
|
+
QueryInfo.prototype.setDiff = function (diff) {
|
|
883
|
+
var _this = this;
|
|
884
|
+
var oldDiff = this.lastDiff && this.lastDiff.diff;
|
|
885
|
+
this.updateLastDiff(diff);
|
|
886
|
+
if (!this.dirty &&
|
|
887
|
+
!equality.equal(oldDiff && oldDiff.result, diff && diff.result)) {
|
|
888
|
+
this.dirty = true;
|
|
889
|
+
if (!this.notifyTimeout) {
|
|
890
|
+
this.notifyTimeout = setTimeout(function () { return _this.notify(); }, 0);
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
};
|
|
894
|
+
QueryInfo.prototype.setObservableQuery = function (oq) {
|
|
895
|
+
var _this = this;
|
|
896
|
+
if (oq === this.observableQuery)
|
|
897
|
+
return;
|
|
898
|
+
if (this.oqListener) {
|
|
899
|
+
this.listeners.delete(this.oqListener);
|
|
900
|
+
}
|
|
901
|
+
this.observableQuery = oq;
|
|
902
|
+
if (oq) {
|
|
903
|
+
oq["queryInfo"] = this;
|
|
904
|
+
this.listeners.add(this.oqListener = function () {
|
|
905
|
+
var diff = _this.getDiff();
|
|
906
|
+
if (diff.fromOptimisticTransaction) {
|
|
907
|
+
oq["observe"]();
|
|
908
|
+
}
|
|
909
|
+
else {
|
|
910
|
+
reobserveCacheFirst(oq);
|
|
911
|
+
}
|
|
912
|
+
});
|
|
913
|
+
}
|
|
914
|
+
else {
|
|
915
|
+
delete this.oqListener;
|
|
916
|
+
}
|
|
917
|
+
};
|
|
918
|
+
QueryInfo.prototype.notify = function () {
|
|
919
|
+
var _this = this;
|
|
920
|
+
cancelNotifyTimeout(this);
|
|
921
|
+
if (this.shouldNotify()) {
|
|
922
|
+
this.listeners.forEach(function (listener) { return listener(_this); });
|
|
923
|
+
}
|
|
924
|
+
this.dirty = false;
|
|
925
|
+
};
|
|
926
|
+
QueryInfo.prototype.shouldNotify = function () {
|
|
927
|
+
if (!this.dirty || !this.listeners.size) {
|
|
928
|
+
return false;
|
|
929
|
+
}
|
|
930
|
+
if (isNetworkRequestInFlight(this.networkStatus) &&
|
|
931
|
+
this.observableQuery) {
|
|
932
|
+
var fetchPolicy = this.observableQuery.options.fetchPolicy;
|
|
933
|
+
if (fetchPolicy !== "cache-only" &&
|
|
934
|
+
fetchPolicy !== "cache-and-network") {
|
|
935
|
+
return false;
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
return true;
|
|
939
|
+
};
|
|
940
|
+
QueryInfo.prototype.stop = function () {
|
|
941
|
+
if (!this.stopped) {
|
|
942
|
+
this.stopped = true;
|
|
943
|
+
this.reset();
|
|
944
|
+
this.cancel();
|
|
945
|
+
this.cancel = QueryInfo.prototype.cancel;
|
|
946
|
+
this.subscriptions.forEach(function (sub) { return sub.unsubscribe(); });
|
|
947
|
+
var oq = this.observableQuery;
|
|
948
|
+
if (oq)
|
|
949
|
+
oq.stopPolling();
|
|
950
|
+
}
|
|
951
|
+
};
|
|
952
|
+
QueryInfo.prototype.cancel = function () { };
|
|
953
|
+
QueryInfo.prototype.updateWatch = function (variables) {
|
|
954
|
+
var _this = this;
|
|
955
|
+
if (variables === void 0) { variables = this.variables; }
|
|
956
|
+
var oq = this.observableQuery;
|
|
957
|
+
if (oq && oq.options.fetchPolicy === "no-cache") {
|
|
958
|
+
return;
|
|
959
|
+
}
|
|
960
|
+
var watchOptions = tslib.__assign(tslib.__assign({}, this.getDiffOptions(variables)), { watcher: this, callback: function (diff) { return _this.setDiff(diff); } });
|
|
961
|
+
if (!this.lastWatch ||
|
|
962
|
+
!equality.equal(watchOptions, this.lastWatch)) {
|
|
963
|
+
this.cancel();
|
|
964
|
+
this.cancel = this.cache.watch(this.lastWatch = watchOptions);
|
|
965
|
+
}
|
|
966
|
+
};
|
|
967
|
+
QueryInfo.prototype.resetLastWrite = function () {
|
|
968
|
+
this.lastWrite = void 0;
|
|
969
|
+
};
|
|
970
|
+
QueryInfo.prototype.shouldWrite = function (result, variables) {
|
|
971
|
+
var lastWrite = this.lastWrite;
|
|
972
|
+
return !(lastWrite &&
|
|
973
|
+
lastWrite.dmCount === destructiveMethodCounts.get(this.cache) &&
|
|
974
|
+
equality.equal(variables, lastWrite.variables) &&
|
|
975
|
+
equality.equal(result.data, lastWrite.result.data));
|
|
976
|
+
};
|
|
977
|
+
QueryInfo.prototype.markResult = function (result, options, cacheWriteBehavior) {
|
|
978
|
+
var _this = this;
|
|
979
|
+
this.graphQLErrors = utilities.isNonEmptyArray(result.errors) ? result.errors : [];
|
|
980
|
+
this.reset();
|
|
981
|
+
if (options.fetchPolicy === 'no-cache') {
|
|
982
|
+
this.updateLastDiff({ result: result.data, complete: true }, this.getDiffOptions(options.variables));
|
|
983
|
+
}
|
|
984
|
+
else if (cacheWriteBehavior !== 0) {
|
|
985
|
+
if (shouldWriteResult(result, options.errorPolicy)) {
|
|
986
|
+
this.cache.performTransaction(function (cache) {
|
|
987
|
+
if (_this.shouldWrite(result, options.variables)) {
|
|
988
|
+
cache.writeQuery({
|
|
989
|
+
query: _this.document,
|
|
990
|
+
data: result.data,
|
|
991
|
+
variables: options.variables,
|
|
992
|
+
overwrite: cacheWriteBehavior === 1,
|
|
993
|
+
});
|
|
994
|
+
_this.lastWrite = {
|
|
995
|
+
result: result,
|
|
996
|
+
variables: options.variables,
|
|
997
|
+
dmCount: destructiveMethodCounts.get(_this.cache),
|
|
998
|
+
};
|
|
999
|
+
}
|
|
1000
|
+
else {
|
|
1001
|
+
if (_this.lastDiff &&
|
|
1002
|
+
_this.lastDiff.diff.complete) {
|
|
1003
|
+
result.data = _this.lastDiff.diff.result;
|
|
1004
|
+
return;
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
var diffOptions = _this.getDiffOptions(options.variables);
|
|
1008
|
+
var diff = cache.diff(diffOptions);
|
|
1009
|
+
if (!_this.stopped) {
|
|
1010
|
+
_this.updateWatch(options.variables);
|
|
1011
|
+
}
|
|
1012
|
+
_this.updateLastDiff(diff, diffOptions);
|
|
1013
|
+
if (diff.complete) {
|
|
1014
|
+
result.data = diff.result;
|
|
1015
|
+
}
|
|
1016
|
+
});
|
|
1017
|
+
}
|
|
1018
|
+
else {
|
|
1019
|
+
this.lastWrite = void 0;
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
};
|
|
1023
|
+
QueryInfo.prototype.markReady = function () {
|
|
1024
|
+
this.networkError = null;
|
|
1025
|
+
return this.networkStatus = exports.NetworkStatus.ready;
|
|
1026
|
+
};
|
|
1027
|
+
QueryInfo.prototype.markError = function (error) {
|
|
1028
|
+
this.networkStatus = exports.NetworkStatus.error;
|
|
1029
|
+
this.lastWrite = void 0;
|
|
1030
|
+
this.reset();
|
|
1031
|
+
if (error.graphQLErrors) {
|
|
1032
|
+
this.graphQLErrors = error.graphQLErrors;
|
|
1033
|
+
}
|
|
1034
|
+
if (error.networkError) {
|
|
1035
|
+
this.networkError = error.networkError;
|
|
1036
|
+
}
|
|
1037
|
+
return error;
|
|
1038
|
+
};
|
|
1039
|
+
return QueryInfo;
|
|
1040
|
+
}());
|
|
1041
|
+
function shouldWriteResult(result, errorPolicy) {
|
|
1042
|
+
if (errorPolicy === void 0) { errorPolicy = "none"; }
|
|
1043
|
+
var ignoreErrors = errorPolicy === "ignore" ||
|
|
1044
|
+
errorPolicy === "all";
|
|
1045
|
+
var writeWithErrors = !utilities.graphQLResultHasError(result);
|
|
1046
|
+
if (!writeWithErrors && ignoreErrors && result.data) {
|
|
1047
|
+
writeWithErrors = true;
|
|
1048
|
+
}
|
|
1049
|
+
return writeWithErrors;
|
|
1050
|
+
}
|
|
1051
|
+
|
|
1052
|
+
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
1053
|
+
var QueryManager = (function () {
|
|
1054
|
+
function QueryManager(_a) {
|
|
1055
|
+
var cache = _a.cache, link = _a.link, defaultOptions = _a.defaultOptions, _b = _a.queryDeduplication, queryDeduplication = _b === void 0 ? false : _b, onBroadcast = _a.onBroadcast, _c = _a.ssrMode, ssrMode = _c === void 0 ? false : _c, _d = _a.clientAwareness, clientAwareness = _d === void 0 ? {} : _d, localState = _a.localState, assumeImmutableResults = _a.assumeImmutableResults;
|
|
1056
|
+
this.clientAwareness = {};
|
|
1057
|
+
this.queries = new Map();
|
|
1058
|
+
this.fetchCancelFns = new Map();
|
|
1059
|
+
this.transformCache = new (utilities.canUseWeakMap ? WeakMap : Map)();
|
|
1060
|
+
this.queryIdCounter = 1;
|
|
1061
|
+
this.requestIdCounter = 1;
|
|
1062
|
+
this.mutationIdCounter = 1;
|
|
1063
|
+
this.inFlightLinkObservables = new Map();
|
|
1064
|
+
this.cache = cache;
|
|
1065
|
+
this.link = link;
|
|
1066
|
+
this.defaultOptions = defaultOptions || Object.create(null);
|
|
1067
|
+
this.queryDeduplication = queryDeduplication;
|
|
1068
|
+
this.clientAwareness = clientAwareness;
|
|
1069
|
+
this.localState = localState || new LocalState({ cache: cache });
|
|
1070
|
+
this.ssrMode = ssrMode;
|
|
1071
|
+
this.assumeImmutableResults = !!assumeImmutableResults;
|
|
1072
|
+
if ((this.onBroadcast = onBroadcast)) {
|
|
1073
|
+
this.mutationStore = Object.create(null);
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
QueryManager.prototype.stop = function () {
|
|
1077
|
+
var _this = this;
|
|
1078
|
+
this.queries.forEach(function (_info, queryId) {
|
|
1079
|
+
_this.stopQueryNoBroadcast(queryId);
|
|
1080
|
+
});
|
|
1081
|
+
this.cancelPendingFetches(__DEV__ ? new globals.InvariantError('QueryManager stopped while query was in flight') : new globals.InvariantError(11));
|
|
1082
|
+
};
|
|
1083
|
+
QueryManager.prototype.cancelPendingFetches = function (error) {
|
|
1084
|
+
this.fetchCancelFns.forEach(function (cancel) { return cancel(error); });
|
|
1085
|
+
this.fetchCancelFns.clear();
|
|
1086
|
+
};
|
|
1087
|
+
QueryManager.prototype.mutate = function (_a) {
|
|
1088
|
+
var _b, _c;
|
|
1089
|
+
var mutation = _a.mutation, variables = _a.variables, optimisticResponse = _a.optimisticResponse, updateQueries = _a.updateQueries, _d = _a.refetchQueries, refetchQueries = _d === void 0 ? [] : _d, _e = _a.awaitRefetchQueries, awaitRefetchQueries = _e === void 0 ? false : _e, updateWithProxyFn = _a.update, onQueryUpdated = _a.onQueryUpdated, _f = _a.fetchPolicy, fetchPolicy = _f === void 0 ? ((_b = this.defaultOptions.mutate) === null || _b === void 0 ? void 0 : _b.fetchPolicy) || "network-only" : _f, _g = _a.errorPolicy, errorPolicy = _g === void 0 ? ((_c = this.defaultOptions.mutate) === null || _c === void 0 ? void 0 : _c.errorPolicy) || "none" : _g, keepRootFields = _a.keepRootFields, context = _a.context;
|
|
1090
|
+
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
1091
|
+
var mutationId, mutationStoreValue, self;
|
|
1092
|
+
return tslib.__generator(this, function (_h) {
|
|
1093
|
+
switch (_h.label) {
|
|
1094
|
+
case 0:
|
|
1095
|
+
__DEV__ ? globals.invariant(mutation, 'mutation option is required. You must specify your GraphQL document in the mutation option.') : globals.invariant(mutation, 12);
|
|
1096
|
+
__DEV__ ? globals.invariant(fetchPolicy === 'network-only' ||
|
|
1097
|
+
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' ||
|
|
1098
|
+
fetchPolicy === 'no-cache', 13);
|
|
1099
|
+
mutationId = this.generateMutationId();
|
|
1100
|
+
mutation = this.transform(mutation).document;
|
|
1101
|
+
variables = this.getVariables(mutation, variables);
|
|
1102
|
+
if (!this.transform(mutation).hasClientExports) return [3, 2];
|
|
1103
|
+
return [4, this.localState.addExportedVariables(mutation, variables, context)];
|
|
1104
|
+
case 1:
|
|
1105
|
+
variables = (_h.sent());
|
|
1106
|
+
_h.label = 2;
|
|
1107
|
+
case 2:
|
|
1108
|
+
mutationStoreValue = this.mutationStore &&
|
|
1109
|
+
(this.mutationStore[mutationId] = {
|
|
1110
|
+
mutation: mutation,
|
|
1111
|
+
variables: variables,
|
|
1112
|
+
loading: true,
|
|
1113
|
+
error: null,
|
|
1114
|
+
});
|
|
1115
|
+
if (optimisticResponse) {
|
|
1116
|
+
this.markMutationOptimistic(optimisticResponse, {
|
|
1117
|
+
mutationId: mutationId,
|
|
1118
|
+
document: mutation,
|
|
1119
|
+
variables: variables,
|
|
1120
|
+
fetchPolicy: fetchPolicy,
|
|
1121
|
+
errorPolicy: errorPolicy,
|
|
1122
|
+
context: context,
|
|
1123
|
+
updateQueries: updateQueries,
|
|
1124
|
+
update: updateWithProxyFn,
|
|
1125
|
+
keepRootFields: keepRootFields,
|
|
1126
|
+
});
|
|
1127
|
+
}
|
|
1128
|
+
this.broadcastQueries();
|
|
1129
|
+
self = this;
|
|
1130
|
+
return [2, new Promise(function (resolve, reject) {
|
|
1131
|
+
return utilities.asyncMap(self.getObservableFromLink(mutation, tslib.__assign(tslib.__assign({}, context), { optimisticResponse: optimisticResponse }), variables, false), function (result) {
|
|
1132
|
+
if (utilities.graphQLResultHasError(result) && errorPolicy === 'none') {
|
|
1133
|
+
throw new errors.ApolloError({
|
|
1134
|
+
graphQLErrors: result.errors,
|
|
1135
|
+
});
|
|
1136
|
+
}
|
|
1137
|
+
if (mutationStoreValue) {
|
|
1138
|
+
mutationStoreValue.loading = false;
|
|
1139
|
+
mutationStoreValue.error = null;
|
|
1140
|
+
}
|
|
1141
|
+
var storeResult = tslib.__assign({}, result);
|
|
1142
|
+
if (typeof refetchQueries === "function") {
|
|
1143
|
+
refetchQueries = refetchQueries(storeResult);
|
|
1144
|
+
}
|
|
1145
|
+
if (errorPolicy === 'ignore' &&
|
|
1146
|
+
utilities.graphQLResultHasError(storeResult)) {
|
|
1147
|
+
delete storeResult.errors;
|
|
1148
|
+
}
|
|
1149
|
+
return self.markMutationResult({
|
|
1150
|
+
mutationId: mutationId,
|
|
1151
|
+
result: storeResult,
|
|
1152
|
+
document: mutation,
|
|
1153
|
+
variables: variables,
|
|
1154
|
+
fetchPolicy: fetchPolicy,
|
|
1155
|
+
errorPolicy: errorPolicy,
|
|
1156
|
+
context: context,
|
|
1157
|
+
update: updateWithProxyFn,
|
|
1158
|
+
updateQueries: updateQueries,
|
|
1159
|
+
awaitRefetchQueries: awaitRefetchQueries,
|
|
1160
|
+
refetchQueries: refetchQueries,
|
|
1161
|
+
removeOptimistic: optimisticResponse ? mutationId : void 0,
|
|
1162
|
+
onQueryUpdated: onQueryUpdated,
|
|
1163
|
+
keepRootFields: keepRootFields,
|
|
1164
|
+
});
|
|
1165
|
+
}).subscribe({
|
|
1166
|
+
next: function (storeResult) {
|
|
1167
|
+
self.broadcastQueries();
|
|
1168
|
+
resolve(storeResult);
|
|
1169
|
+
},
|
|
1170
|
+
error: function (err) {
|
|
1171
|
+
if (mutationStoreValue) {
|
|
1172
|
+
mutationStoreValue.loading = false;
|
|
1173
|
+
mutationStoreValue.error = err;
|
|
1174
|
+
}
|
|
1175
|
+
if (optimisticResponse) {
|
|
1176
|
+
self.cache.removeOptimistic(mutationId);
|
|
1177
|
+
}
|
|
1178
|
+
self.broadcastQueries();
|
|
1179
|
+
reject(err instanceof errors.ApolloError ? err : new errors.ApolloError({
|
|
1180
|
+
networkError: err,
|
|
1181
|
+
}));
|
|
1182
|
+
},
|
|
1183
|
+
});
|
|
1184
|
+
})];
|
|
1185
|
+
}
|
|
1186
|
+
});
|
|
1187
|
+
});
|
|
1188
|
+
};
|
|
1189
|
+
QueryManager.prototype.markMutationResult = function (mutation, cache) {
|
|
1190
|
+
var _this = this;
|
|
1191
|
+
if (cache === void 0) { cache = this.cache; }
|
|
1192
|
+
var result = mutation.result;
|
|
1193
|
+
var cacheWrites = [];
|
|
1194
|
+
var skipCache = mutation.fetchPolicy === "no-cache";
|
|
1195
|
+
if (!skipCache && shouldWriteResult(result, mutation.errorPolicy)) {
|
|
1196
|
+
cacheWrites.push({
|
|
1197
|
+
result: result.data,
|
|
1198
|
+
dataId: 'ROOT_MUTATION',
|
|
1199
|
+
query: mutation.document,
|
|
1200
|
+
variables: mutation.variables,
|
|
1201
|
+
});
|
|
1202
|
+
var updateQueries_1 = mutation.updateQueries;
|
|
1203
|
+
if (updateQueries_1) {
|
|
1204
|
+
this.queries.forEach(function (_a, queryId) {
|
|
1205
|
+
var observableQuery = _a.observableQuery;
|
|
1206
|
+
var queryName = observableQuery && observableQuery.queryName;
|
|
1207
|
+
if (!queryName || !hasOwnProperty.call(updateQueries_1, queryName)) {
|
|
1208
|
+
return;
|
|
1209
|
+
}
|
|
1210
|
+
var updater = updateQueries_1[queryName];
|
|
1211
|
+
var _b = _this.queries.get(queryId), document = _b.document, variables = _b.variables;
|
|
1212
|
+
var _c = cache.diff({
|
|
1213
|
+
query: document,
|
|
1214
|
+
variables: variables,
|
|
1215
|
+
returnPartialData: true,
|
|
1216
|
+
optimistic: false,
|
|
1217
|
+
}), currentQueryResult = _c.result, complete = _c.complete;
|
|
1218
|
+
if (complete && currentQueryResult) {
|
|
1219
|
+
var nextQueryResult = updater(currentQueryResult, {
|
|
1220
|
+
mutationResult: result,
|
|
1221
|
+
queryName: document && utilities.getOperationName(document) || void 0,
|
|
1222
|
+
queryVariables: variables,
|
|
1223
|
+
});
|
|
1224
|
+
if (nextQueryResult) {
|
|
1225
|
+
cacheWrites.push({
|
|
1226
|
+
result: nextQueryResult,
|
|
1227
|
+
dataId: 'ROOT_QUERY',
|
|
1228
|
+
query: document,
|
|
1229
|
+
variables: variables,
|
|
1230
|
+
});
|
|
1231
|
+
}
|
|
1232
|
+
}
|
|
1233
|
+
});
|
|
1234
|
+
}
|
|
1235
|
+
}
|
|
1236
|
+
if (cacheWrites.length > 0 ||
|
|
1237
|
+
mutation.refetchQueries ||
|
|
1238
|
+
mutation.update ||
|
|
1239
|
+
mutation.onQueryUpdated ||
|
|
1240
|
+
mutation.removeOptimistic) {
|
|
1241
|
+
var results_1 = [];
|
|
1242
|
+
this.refetchQueries({
|
|
1243
|
+
updateCache: function (cache) {
|
|
1244
|
+
if (!skipCache) {
|
|
1245
|
+
cacheWrites.forEach(function (write) { return cache.write(write); });
|
|
1246
|
+
}
|
|
1247
|
+
var update = mutation.update;
|
|
1248
|
+
if (update) {
|
|
1249
|
+
if (!skipCache) {
|
|
1250
|
+
var diff = cache.diff({
|
|
1251
|
+
id: "ROOT_MUTATION",
|
|
1252
|
+
query: _this.transform(mutation.document).asQuery,
|
|
1253
|
+
variables: mutation.variables,
|
|
1254
|
+
optimistic: false,
|
|
1255
|
+
returnPartialData: true,
|
|
1256
|
+
});
|
|
1257
|
+
if (diff.complete) {
|
|
1258
|
+
result = tslib.__assign(tslib.__assign({}, result), { data: diff.result });
|
|
1259
|
+
}
|
|
1260
|
+
}
|
|
1261
|
+
update(cache, result, {
|
|
1262
|
+
context: mutation.context,
|
|
1263
|
+
variables: mutation.variables,
|
|
1264
|
+
});
|
|
1265
|
+
}
|
|
1266
|
+
if (!skipCache && !mutation.keepRootFields) {
|
|
1267
|
+
cache.modify({
|
|
1268
|
+
id: 'ROOT_MUTATION',
|
|
1269
|
+
fields: function (value, _a) {
|
|
1270
|
+
var fieldName = _a.fieldName, DELETE = _a.DELETE;
|
|
1271
|
+
return fieldName === "__typename" ? value : DELETE;
|
|
1272
|
+
},
|
|
1273
|
+
});
|
|
1274
|
+
}
|
|
1275
|
+
},
|
|
1276
|
+
include: mutation.refetchQueries,
|
|
1277
|
+
optimistic: false,
|
|
1278
|
+
removeOptimistic: mutation.removeOptimistic,
|
|
1279
|
+
onQueryUpdated: mutation.onQueryUpdated || null,
|
|
1280
|
+
}).forEach(function (result) { return results_1.push(result); });
|
|
1281
|
+
if (mutation.awaitRefetchQueries || mutation.onQueryUpdated) {
|
|
1282
|
+
return Promise.all(results_1).then(function () { return result; });
|
|
1283
|
+
}
|
|
1284
|
+
}
|
|
1285
|
+
return Promise.resolve(result);
|
|
1286
|
+
};
|
|
1287
|
+
QueryManager.prototype.markMutationOptimistic = function (optimisticResponse, mutation) {
|
|
1288
|
+
var _this = this;
|
|
1289
|
+
var data = typeof optimisticResponse === "function"
|
|
1290
|
+
? optimisticResponse(mutation.variables)
|
|
1291
|
+
: optimisticResponse;
|
|
1292
|
+
return this.cache.recordOptimisticTransaction(function (cache) {
|
|
1293
|
+
try {
|
|
1294
|
+
_this.markMutationResult(tslib.__assign(tslib.__assign({}, mutation), { result: { data: data } }), cache);
|
|
1295
|
+
}
|
|
1296
|
+
catch (error) {
|
|
1297
|
+
__DEV__ && globals.invariant.error(error);
|
|
1298
|
+
}
|
|
1299
|
+
}, mutation.mutationId);
|
|
1300
|
+
};
|
|
1301
|
+
QueryManager.prototype.fetchQuery = function (queryId, options, networkStatus) {
|
|
1302
|
+
return this.fetchQueryObservable(queryId, options, networkStatus).promise;
|
|
1303
|
+
};
|
|
1304
|
+
QueryManager.prototype.getQueryStore = function () {
|
|
1305
|
+
var store = Object.create(null);
|
|
1306
|
+
this.queries.forEach(function (info, queryId) {
|
|
1307
|
+
store[queryId] = {
|
|
1308
|
+
variables: info.variables,
|
|
1309
|
+
networkStatus: info.networkStatus,
|
|
1310
|
+
networkError: info.networkError,
|
|
1311
|
+
graphQLErrors: info.graphQLErrors,
|
|
1312
|
+
};
|
|
1313
|
+
});
|
|
1314
|
+
return store;
|
|
1315
|
+
};
|
|
1316
|
+
QueryManager.prototype.resetErrors = function (queryId) {
|
|
1317
|
+
var queryInfo = this.queries.get(queryId);
|
|
1318
|
+
if (queryInfo) {
|
|
1319
|
+
queryInfo.networkError = undefined;
|
|
1320
|
+
queryInfo.graphQLErrors = [];
|
|
1321
|
+
}
|
|
1322
|
+
};
|
|
1323
|
+
QueryManager.prototype.transform = function (document) {
|
|
1324
|
+
var transformCache = this.transformCache;
|
|
1325
|
+
if (!transformCache.has(document)) {
|
|
1326
|
+
var transformed = this.cache.transformDocument(document);
|
|
1327
|
+
var forLink = utilities.removeConnectionDirectiveFromDocument(this.cache.transformForLink(transformed));
|
|
1328
|
+
var clientQuery = this.localState.clientQuery(transformed);
|
|
1329
|
+
var serverQuery = forLink && this.localState.serverQuery(forLink);
|
|
1330
|
+
var cacheEntry_1 = {
|
|
1331
|
+
document: transformed,
|
|
1332
|
+
hasClientExports: utilities.hasClientExports(transformed),
|
|
1333
|
+
hasForcedResolvers: this.localState.shouldForceResolvers(transformed),
|
|
1334
|
+
clientQuery: clientQuery,
|
|
1335
|
+
serverQuery: serverQuery,
|
|
1336
|
+
defaultVars: utilities.getDefaultValues(utilities.getOperationDefinition(transformed)),
|
|
1337
|
+
asQuery: tslib.__assign(tslib.__assign({}, transformed), { definitions: transformed.definitions.map(function (def) {
|
|
1338
|
+
if (def.kind === "OperationDefinition" &&
|
|
1339
|
+
def.operation !== "query") {
|
|
1340
|
+
return tslib.__assign(tslib.__assign({}, def), { operation: "query" });
|
|
1341
|
+
}
|
|
1342
|
+
return def;
|
|
1343
|
+
}) })
|
|
1344
|
+
};
|
|
1345
|
+
var add = function (doc) {
|
|
1346
|
+
if (doc && !transformCache.has(doc)) {
|
|
1347
|
+
transformCache.set(doc, cacheEntry_1);
|
|
1348
|
+
}
|
|
1349
|
+
};
|
|
1350
|
+
add(document);
|
|
1351
|
+
add(transformed);
|
|
1352
|
+
add(clientQuery);
|
|
1353
|
+
add(serverQuery);
|
|
1354
|
+
}
|
|
1355
|
+
return transformCache.get(document);
|
|
1356
|
+
};
|
|
1357
|
+
QueryManager.prototype.getVariables = function (document, variables) {
|
|
1358
|
+
return tslib.__assign(tslib.__assign({}, this.transform(document).defaultVars), variables);
|
|
1359
|
+
};
|
|
1360
|
+
QueryManager.prototype.watchQuery = function (options) {
|
|
1361
|
+
options = tslib.__assign(tslib.__assign({}, options), { variables: this.getVariables(options.query, options.variables) });
|
|
1362
|
+
if (typeof options.notifyOnNetworkStatusChange === 'undefined') {
|
|
1363
|
+
options.notifyOnNetworkStatusChange = false;
|
|
1364
|
+
}
|
|
1365
|
+
var queryInfo = new QueryInfo(this);
|
|
1366
|
+
var observable = new ObservableQuery({
|
|
1367
|
+
queryManager: this,
|
|
1368
|
+
queryInfo: queryInfo,
|
|
1369
|
+
options: options,
|
|
1370
|
+
});
|
|
1371
|
+
this.queries.set(observable.queryId, queryInfo);
|
|
1372
|
+
queryInfo.init({
|
|
1373
|
+
document: observable.query,
|
|
1374
|
+
observableQuery: observable,
|
|
1375
|
+
variables: observable.variables,
|
|
1376
|
+
});
|
|
1377
|
+
return observable;
|
|
1378
|
+
};
|
|
1379
|
+
QueryManager.prototype.query = function (options, queryId) {
|
|
1380
|
+
var _this = this;
|
|
1381
|
+
if (queryId === void 0) { queryId = this.generateQueryId(); }
|
|
1382
|
+
__DEV__ ? globals.invariant(options.query, 'query option is required. You must specify your GraphQL document ' +
|
|
1383
|
+
'in the query option.') : globals.invariant(options.query, 14);
|
|
1384
|
+
__DEV__ ? globals.invariant(options.query.kind === 'Document', 'You must wrap the query string in a "gql" tag.') : globals.invariant(options.query.kind === 'Document', 15);
|
|
1385
|
+
__DEV__ ? globals.invariant(!options.returnPartialData, 'returnPartialData option only supported on watchQuery.') : globals.invariant(!options.returnPartialData, 16);
|
|
1386
|
+
__DEV__ ? globals.invariant(!options.pollInterval, 'pollInterval option only supported on watchQuery.') : globals.invariant(!options.pollInterval, 17);
|
|
1387
|
+
return this.fetchQuery(queryId, options).finally(function () { return _this.stopQuery(queryId); });
|
|
1388
|
+
};
|
|
1389
|
+
QueryManager.prototype.generateQueryId = function () {
|
|
1390
|
+
return String(this.queryIdCounter++);
|
|
1391
|
+
};
|
|
1392
|
+
QueryManager.prototype.generateRequestId = function () {
|
|
1393
|
+
return this.requestIdCounter++;
|
|
1394
|
+
};
|
|
1395
|
+
QueryManager.prototype.generateMutationId = function () {
|
|
1396
|
+
return String(this.mutationIdCounter++);
|
|
1397
|
+
};
|
|
1398
|
+
QueryManager.prototype.stopQueryInStore = function (queryId) {
|
|
1399
|
+
this.stopQueryInStoreNoBroadcast(queryId);
|
|
1400
|
+
this.broadcastQueries();
|
|
1401
|
+
};
|
|
1402
|
+
QueryManager.prototype.stopQueryInStoreNoBroadcast = function (queryId) {
|
|
1403
|
+
var queryInfo = this.queries.get(queryId);
|
|
1404
|
+
if (queryInfo)
|
|
1405
|
+
queryInfo.stop();
|
|
1406
|
+
};
|
|
1407
|
+
QueryManager.prototype.clearStore = function (options) {
|
|
1408
|
+
if (options === void 0) { options = {
|
|
1409
|
+
discardWatches: true,
|
|
1410
|
+
}; }
|
|
1411
|
+
this.cancelPendingFetches(__DEV__ ? new globals.InvariantError('Store reset while query was in flight (not completed in link chain)') : new globals.InvariantError(18));
|
|
1412
|
+
this.queries.forEach(function (queryInfo) {
|
|
1413
|
+
if (queryInfo.observableQuery) {
|
|
1414
|
+
queryInfo.networkStatus = exports.NetworkStatus.loading;
|
|
1415
|
+
}
|
|
1416
|
+
else {
|
|
1417
|
+
queryInfo.stop();
|
|
1418
|
+
}
|
|
1419
|
+
});
|
|
1420
|
+
if (this.mutationStore) {
|
|
1421
|
+
this.mutationStore = Object.create(null);
|
|
1422
|
+
}
|
|
1423
|
+
return this.cache.reset(options);
|
|
1424
|
+
};
|
|
1425
|
+
QueryManager.prototype.getObservableQueries = function (include) {
|
|
1426
|
+
var _this = this;
|
|
1427
|
+
if (include === void 0) { include = "active"; }
|
|
1428
|
+
var queries = new Map();
|
|
1429
|
+
var queryNamesAndDocs = new Map();
|
|
1430
|
+
var legacyQueryOptions = new Set();
|
|
1431
|
+
if (Array.isArray(include)) {
|
|
1432
|
+
include.forEach(function (desc) {
|
|
1433
|
+
if (typeof desc === "string") {
|
|
1434
|
+
queryNamesAndDocs.set(desc, false);
|
|
1435
|
+
}
|
|
1436
|
+
else if (utilities.isDocumentNode(desc)) {
|
|
1437
|
+
queryNamesAndDocs.set(_this.transform(desc).document, false);
|
|
1438
|
+
}
|
|
1439
|
+
else if (utilities.isNonNullObject(desc) && desc.query) {
|
|
1440
|
+
legacyQueryOptions.add(desc);
|
|
1441
|
+
}
|
|
1442
|
+
});
|
|
1443
|
+
}
|
|
1444
|
+
this.queries.forEach(function (_a, queryId) {
|
|
1445
|
+
var oq = _a.observableQuery, document = _a.document;
|
|
1446
|
+
if (oq) {
|
|
1447
|
+
if (include === "all") {
|
|
1448
|
+
queries.set(queryId, oq);
|
|
1449
|
+
return;
|
|
1450
|
+
}
|
|
1451
|
+
var queryName = oq.queryName, fetchPolicy = oq.options.fetchPolicy;
|
|
1452
|
+
if (fetchPolicy === "standby" ||
|
|
1453
|
+
(include === "active" && !oq.hasObservers())) {
|
|
1454
|
+
return;
|
|
1455
|
+
}
|
|
1456
|
+
if (include === "active" ||
|
|
1457
|
+
(queryName && queryNamesAndDocs.has(queryName)) ||
|
|
1458
|
+
(document && queryNamesAndDocs.has(document))) {
|
|
1459
|
+
queries.set(queryId, oq);
|
|
1460
|
+
if (queryName)
|
|
1461
|
+
queryNamesAndDocs.set(queryName, true);
|
|
1462
|
+
if (document)
|
|
1463
|
+
queryNamesAndDocs.set(document, true);
|
|
1464
|
+
}
|
|
1465
|
+
}
|
|
1466
|
+
});
|
|
1467
|
+
if (legacyQueryOptions.size) {
|
|
1468
|
+
legacyQueryOptions.forEach(function (options) {
|
|
1469
|
+
var queryId = utilities.makeUniqueId("legacyOneTimeQuery");
|
|
1470
|
+
var queryInfo = _this.getQuery(queryId).init({
|
|
1471
|
+
document: options.query,
|
|
1472
|
+
variables: options.variables,
|
|
1473
|
+
});
|
|
1474
|
+
var oq = new ObservableQuery({
|
|
1475
|
+
queryManager: _this,
|
|
1476
|
+
queryInfo: queryInfo,
|
|
1477
|
+
options: tslib.__assign(tslib.__assign({}, options), { fetchPolicy: "network-only" }),
|
|
1478
|
+
});
|
|
1479
|
+
globals.invariant(oq.queryId === queryId);
|
|
1480
|
+
queryInfo.setObservableQuery(oq);
|
|
1481
|
+
queries.set(queryId, oq);
|
|
1482
|
+
});
|
|
1483
|
+
}
|
|
1484
|
+
if (__DEV__ && queryNamesAndDocs.size) {
|
|
1485
|
+
queryNamesAndDocs.forEach(function (included, nameOrDoc) {
|
|
1486
|
+
if (!included) {
|
|
1487
|
+
__DEV__ && globals.invariant.warn("Unknown query ".concat(typeof nameOrDoc === "string" ? "named " : "").concat(JSON.stringify(nameOrDoc, null, 2), " requested in refetchQueries options.include array"));
|
|
1488
|
+
}
|
|
1489
|
+
});
|
|
1490
|
+
}
|
|
1491
|
+
return queries;
|
|
1492
|
+
};
|
|
1493
|
+
QueryManager.prototype.reFetchObservableQueries = function (includeStandby) {
|
|
1494
|
+
var _this = this;
|
|
1495
|
+
if (includeStandby === void 0) { includeStandby = false; }
|
|
1496
|
+
var observableQueryPromises = [];
|
|
1497
|
+
this.getObservableQueries(includeStandby ? "all" : "active").forEach(function (observableQuery, queryId) {
|
|
1498
|
+
var fetchPolicy = observableQuery.options.fetchPolicy;
|
|
1499
|
+
observableQuery.resetLastResults();
|
|
1500
|
+
if (includeStandby ||
|
|
1501
|
+
(fetchPolicy !== "standby" &&
|
|
1502
|
+
fetchPolicy !== "cache-only")) {
|
|
1503
|
+
observableQueryPromises.push(observableQuery.refetch());
|
|
1504
|
+
}
|
|
1505
|
+
_this.getQuery(queryId).setDiff(null);
|
|
1506
|
+
});
|
|
1507
|
+
this.broadcastQueries();
|
|
1508
|
+
return Promise.all(observableQueryPromises);
|
|
1509
|
+
};
|
|
1510
|
+
QueryManager.prototype.setObservableQuery = function (observableQuery) {
|
|
1511
|
+
this.getQuery(observableQuery.queryId).setObservableQuery(observableQuery);
|
|
1512
|
+
};
|
|
1513
|
+
QueryManager.prototype.startGraphQLSubscription = function (_a) {
|
|
1514
|
+
var _this = this;
|
|
1515
|
+
var query = _a.query, fetchPolicy = _a.fetchPolicy, errorPolicy = _a.errorPolicy, variables = _a.variables, _b = _a.context, context = _b === void 0 ? {} : _b;
|
|
1516
|
+
query = this.transform(query).document;
|
|
1517
|
+
variables = this.getVariables(query, variables);
|
|
1518
|
+
var makeObservable = function (variables) {
|
|
1519
|
+
return _this.getObservableFromLink(query, context, variables).map(function (result) {
|
|
1520
|
+
if (fetchPolicy !== 'no-cache') {
|
|
1521
|
+
if (shouldWriteResult(result, errorPolicy)) {
|
|
1522
|
+
_this.cache.write({
|
|
1523
|
+
query: query,
|
|
1524
|
+
result: result.data,
|
|
1525
|
+
dataId: 'ROOT_SUBSCRIPTION',
|
|
1526
|
+
variables: variables,
|
|
1527
|
+
});
|
|
1528
|
+
}
|
|
1529
|
+
_this.broadcastQueries();
|
|
1530
|
+
}
|
|
1531
|
+
if (utilities.graphQLResultHasError(result)) {
|
|
1532
|
+
throw new errors.ApolloError({
|
|
1533
|
+
graphQLErrors: result.errors,
|
|
1534
|
+
});
|
|
1535
|
+
}
|
|
1536
|
+
return result;
|
|
1537
|
+
});
|
|
1538
|
+
};
|
|
1539
|
+
if (this.transform(query).hasClientExports) {
|
|
1540
|
+
var observablePromise_1 = this.localState.addExportedVariables(query, variables, context).then(makeObservable);
|
|
1541
|
+
return new utilities.Observable(function (observer) {
|
|
1542
|
+
var sub = null;
|
|
1543
|
+
observablePromise_1.then(function (observable) { return sub = observable.subscribe(observer); }, observer.error);
|
|
1544
|
+
return function () { return sub && sub.unsubscribe(); };
|
|
1545
|
+
});
|
|
1546
|
+
}
|
|
1547
|
+
return makeObservable(variables);
|
|
1548
|
+
};
|
|
1549
|
+
QueryManager.prototype.stopQuery = function (queryId) {
|
|
1550
|
+
this.stopQueryNoBroadcast(queryId);
|
|
1551
|
+
this.broadcastQueries();
|
|
1552
|
+
};
|
|
1553
|
+
QueryManager.prototype.stopQueryNoBroadcast = function (queryId) {
|
|
1554
|
+
this.stopQueryInStoreNoBroadcast(queryId);
|
|
1555
|
+
this.removeQuery(queryId);
|
|
1556
|
+
};
|
|
1557
|
+
QueryManager.prototype.removeQuery = function (queryId) {
|
|
1558
|
+
this.fetchCancelFns.delete(queryId);
|
|
1559
|
+
if (this.queries.has(queryId)) {
|
|
1560
|
+
this.getQuery(queryId).stop();
|
|
1561
|
+
this.queries.delete(queryId);
|
|
1562
|
+
}
|
|
1563
|
+
};
|
|
1564
|
+
QueryManager.prototype.broadcastQueries = function () {
|
|
1565
|
+
if (this.onBroadcast)
|
|
1566
|
+
this.onBroadcast();
|
|
1567
|
+
this.queries.forEach(function (info) { return info.notify(); });
|
|
1568
|
+
};
|
|
1569
|
+
QueryManager.prototype.getLocalState = function () {
|
|
1570
|
+
return this.localState;
|
|
1571
|
+
};
|
|
1572
|
+
QueryManager.prototype.getObservableFromLink = function (query, context, variables, deduplication) {
|
|
1573
|
+
var _this = this;
|
|
1574
|
+
var _a;
|
|
1575
|
+
if (deduplication === void 0) { deduplication = (_a = context === null || context === void 0 ? void 0 : context.queryDeduplication) !== null && _a !== void 0 ? _a : this.queryDeduplication; }
|
|
1576
|
+
var observable;
|
|
1577
|
+
var serverQuery = this.transform(query).serverQuery;
|
|
1578
|
+
if (serverQuery) {
|
|
1579
|
+
var _b = this, inFlightLinkObservables_1 = _b.inFlightLinkObservables, link = _b.link;
|
|
1580
|
+
var operation = {
|
|
1581
|
+
query: serverQuery,
|
|
1582
|
+
variables: variables,
|
|
1583
|
+
operationName: utilities.getOperationName(serverQuery) || void 0,
|
|
1584
|
+
context: this.prepareContext(tslib.__assign(tslib.__assign({}, context), { forceFetch: !deduplication })),
|
|
1585
|
+
};
|
|
1586
|
+
context = operation.context;
|
|
1587
|
+
if (deduplication) {
|
|
1588
|
+
var byVariables_1 = inFlightLinkObservables_1.get(serverQuery) || new Map();
|
|
1589
|
+
inFlightLinkObservables_1.set(serverQuery, byVariables_1);
|
|
1590
|
+
var varJson_1 = cache.canonicalStringify(variables);
|
|
1591
|
+
observable = byVariables_1.get(varJson_1);
|
|
1592
|
+
if (!observable) {
|
|
1593
|
+
var concast = new utilities.Concast([
|
|
1594
|
+
core.execute(link, operation)
|
|
1595
|
+
]);
|
|
1596
|
+
byVariables_1.set(varJson_1, observable = concast);
|
|
1597
|
+
concast.cleanup(function () {
|
|
1598
|
+
if (byVariables_1.delete(varJson_1) &&
|
|
1599
|
+
byVariables_1.size < 1) {
|
|
1600
|
+
inFlightLinkObservables_1.delete(serverQuery);
|
|
1601
|
+
}
|
|
1602
|
+
});
|
|
1603
|
+
}
|
|
1604
|
+
}
|
|
1605
|
+
else {
|
|
1606
|
+
observable = new utilities.Concast([
|
|
1607
|
+
core.execute(link, operation)
|
|
1608
|
+
]);
|
|
1609
|
+
}
|
|
1610
|
+
}
|
|
1611
|
+
else {
|
|
1612
|
+
observable = new utilities.Concast([
|
|
1613
|
+
utilities.Observable.of({ data: {} })
|
|
1614
|
+
]);
|
|
1615
|
+
context = this.prepareContext(context);
|
|
1616
|
+
}
|
|
1617
|
+
var clientQuery = this.transform(query).clientQuery;
|
|
1618
|
+
if (clientQuery) {
|
|
1619
|
+
observable = utilities.asyncMap(observable, function (result) {
|
|
1620
|
+
return _this.localState.runResolvers({
|
|
1621
|
+
document: clientQuery,
|
|
1622
|
+
remoteResult: result,
|
|
1623
|
+
context: context,
|
|
1624
|
+
variables: variables,
|
|
1625
|
+
});
|
|
1626
|
+
});
|
|
1627
|
+
}
|
|
1628
|
+
return observable;
|
|
1629
|
+
};
|
|
1630
|
+
QueryManager.prototype.getResultsFromLink = function (queryInfo, cacheWriteBehavior, options) {
|
|
1631
|
+
var requestId = queryInfo.lastRequestId = this.generateRequestId();
|
|
1632
|
+
return utilities.asyncMap(this.getObservableFromLink(queryInfo.document, options.context, options.variables), function (result) {
|
|
1633
|
+
var hasErrors = utilities.isNonEmptyArray(result.errors);
|
|
1634
|
+
if (requestId >= queryInfo.lastRequestId) {
|
|
1635
|
+
if (hasErrors && options.errorPolicy === "none") {
|
|
1636
|
+
throw queryInfo.markError(new errors.ApolloError({
|
|
1637
|
+
graphQLErrors: result.errors,
|
|
1638
|
+
}));
|
|
1639
|
+
}
|
|
1640
|
+
queryInfo.markResult(result, options, cacheWriteBehavior);
|
|
1641
|
+
queryInfo.markReady();
|
|
1642
|
+
}
|
|
1643
|
+
var aqr = {
|
|
1644
|
+
data: result.data,
|
|
1645
|
+
loading: false,
|
|
1646
|
+
networkStatus: exports.NetworkStatus.ready,
|
|
1647
|
+
};
|
|
1648
|
+
if (hasErrors && options.errorPolicy !== "ignore") {
|
|
1649
|
+
aqr.errors = result.errors;
|
|
1650
|
+
aqr.networkStatus = exports.NetworkStatus.error;
|
|
1651
|
+
}
|
|
1652
|
+
return aqr;
|
|
1653
|
+
}, function (networkError) {
|
|
1654
|
+
var error = errors.isApolloError(networkError)
|
|
1655
|
+
? networkError
|
|
1656
|
+
: new errors.ApolloError({ networkError: networkError });
|
|
1657
|
+
if (requestId >= queryInfo.lastRequestId) {
|
|
1658
|
+
queryInfo.markError(error);
|
|
1659
|
+
}
|
|
1660
|
+
throw error;
|
|
1661
|
+
});
|
|
1662
|
+
};
|
|
1663
|
+
QueryManager.prototype.fetchQueryObservable = function (queryId, options, networkStatus) {
|
|
1664
|
+
var _this = this;
|
|
1665
|
+
if (networkStatus === void 0) { networkStatus = exports.NetworkStatus.loading; }
|
|
1666
|
+
var query = this.transform(options.query).document;
|
|
1667
|
+
var variables = this.getVariables(query, options.variables);
|
|
1668
|
+
var queryInfo = this.getQuery(queryId);
|
|
1669
|
+
var defaults = this.defaultOptions.watchQuery;
|
|
1670
|
+
var _a = options.fetchPolicy, fetchPolicy = _a === void 0 ? defaults && defaults.fetchPolicy || "cache-first" : _a, _b = options.errorPolicy, errorPolicy = _b === void 0 ? defaults && defaults.errorPolicy || "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;
|
|
1671
|
+
var normalized = Object.assign({}, options, {
|
|
1672
|
+
query: query,
|
|
1673
|
+
variables: variables,
|
|
1674
|
+
fetchPolicy: fetchPolicy,
|
|
1675
|
+
errorPolicy: errorPolicy,
|
|
1676
|
+
returnPartialData: returnPartialData,
|
|
1677
|
+
notifyOnNetworkStatusChange: notifyOnNetworkStatusChange,
|
|
1678
|
+
context: context,
|
|
1679
|
+
});
|
|
1680
|
+
var fromVariables = function (variables) {
|
|
1681
|
+
normalized.variables = variables;
|
|
1682
|
+
return _this.fetchQueryByPolicy(queryInfo, normalized, networkStatus);
|
|
1683
|
+
};
|
|
1684
|
+
this.fetchCancelFns.set(queryId, function (reason) {
|
|
1685
|
+
setTimeout(function () { return concast.cancel(reason); });
|
|
1686
|
+
});
|
|
1687
|
+
var concast = new utilities.Concast(this.transform(normalized.query).hasClientExports
|
|
1688
|
+
? this.localState.addExportedVariables(normalized.query, normalized.variables, normalized.context).then(fromVariables)
|
|
1689
|
+
: fromVariables(normalized.variables));
|
|
1690
|
+
concast.cleanup(function () {
|
|
1691
|
+
_this.fetchCancelFns.delete(queryId);
|
|
1692
|
+
if (queryInfo.observableQuery) {
|
|
1693
|
+
queryInfo.observableQuery["applyNextFetchPolicy"]("after-fetch", options);
|
|
1694
|
+
}
|
|
1695
|
+
});
|
|
1696
|
+
return concast;
|
|
1697
|
+
};
|
|
1698
|
+
QueryManager.prototype.refetchQueries = function (_a) {
|
|
1699
|
+
var _this = this;
|
|
1700
|
+
var updateCache = _a.updateCache, include = _a.include, _b = _a.optimistic, optimistic = _b === void 0 ? false : _b, _c = _a.removeOptimistic, removeOptimistic = _c === void 0 ? optimistic ? utilities.makeUniqueId("refetchQueries") : void 0 : _c, onQueryUpdated = _a.onQueryUpdated;
|
|
1701
|
+
var includedQueriesById = new Map();
|
|
1702
|
+
if (include) {
|
|
1703
|
+
this.getObservableQueries(include).forEach(function (oq, queryId) {
|
|
1704
|
+
includedQueriesById.set(queryId, {
|
|
1705
|
+
oq: oq,
|
|
1706
|
+
lastDiff: _this.getQuery(queryId).getDiff(),
|
|
1707
|
+
});
|
|
1708
|
+
});
|
|
1709
|
+
}
|
|
1710
|
+
var results = new Map;
|
|
1711
|
+
if (updateCache) {
|
|
1712
|
+
this.cache.batch({
|
|
1713
|
+
update: updateCache,
|
|
1714
|
+
optimistic: optimistic && removeOptimistic || false,
|
|
1715
|
+
removeOptimistic: removeOptimistic,
|
|
1716
|
+
onWatchUpdated: function (watch, diff, lastDiff) {
|
|
1717
|
+
var oq = watch.watcher instanceof QueryInfo &&
|
|
1718
|
+
watch.watcher.observableQuery;
|
|
1719
|
+
if (oq) {
|
|
1720
|
+
if (onQueryUpdated) {
|
|
1721
|
+
includedQueriesById.delete(oq.queryId);
|
|
1722
|
+
var result = onQueryUpdated(oq, diff, lastDiff);
|
|
1723
|
+
if (result === true) {
|
|
1724
|
+
result = oq.refetch();
|
|
1725
|
+
}
|
|
1726
|
+
if (result !== false) {
|
|
1727
|
+
results.set(oq, result);
|
|
1728
|
+
}
|
|
1729
|
+
return result;
|
|
1730
|
+
}
|
|
1731
|
+
if (onQueryUpdated !== null) {
|
|
1732
|
+
includedQueriesById.set(oq.queryId, { oq: oq, lastDiff: lastDiff, diff: diff });
|
|
1733
|
+
}
|
|
1734
|
+
}
|
|
1735
|
+
},
|
|
1736
|
+
});
|
|
1737
|
+
}
|
|
1738
|
+
if (includedQueriesById.size) {
|
|
1739
|
+
includedQueriesById.forEach(function (_a, queryId) {
|
|
1740
|
+
var oq = _a.oq, lastDiff = _a.lastDiff, diff = _a.diff;
|
|
1741
|
+
var result;
|
|
1742
|
+
if (onQueryUpdated) {
|
|
1743
|
+
if (!diff) {
|
|
1744
|
+
var info = oq["queryInfo"];
|
|
1745
|
+
info.reset();
|
|
1746
|
+
diff = info.getDiff();
|
|
1747
|
+
}
|
|
1748
|
+
result = onQueryUpdated(oq, diff, lastDiff);
|
|
1749
|
+
}
|
|
1750
|
+
if (!onQueryUpdated || result === true) {
|
|
1751
|
+
result = oq.refetch();
|
|
1752
|
+
}
|
|
1753
|
+
if (result !== false) {
|
|
1754
|
+
results.set(oq, result);
|
|
1755
|
+
}
|
|
1756
|
+
if (queryId.indexOf("legacyOneTimeQuery") >= 0) {
|
|
1757
|
+
_this.stopQueryNoBroadcast(queryId);
|
|
1758
|
+
}
|
|
1759
|
+
});
|
|
1760
|
+
}
|
|
1761
|
+
if (removeOptimistic) {
|
|
1762
|
+
this.cache.removeOptimistic(removeOptimistic);
|
|
1763
|
+
}
|
|
1764
|
+
return results;
|
|
1765
|
+
};
|
|
1766
|
+
QueryManager.prototype.fetchQueryByPolicy = function (queryInfo, _a, networkStatus) {
|
|
1767
|
+
var _this = this;
|
|
1768
|
+
var query = _a.query, variables = _a.variables, fetchPolicy = _a.fetchPolicy, refetchWritePolicy = _a.refetchWritePolicy, errorPolicy = _a.errorPolicy, returnPartialData = _a.returnPartialData, context = _a.context, notifyOnNetworkStatusChange = _a.notifyOnNetworkStatusChange;
|
|
1769
|
+
var oldNetworkStatus = queryInfo.networkStatus;
|
|
1770
|
+
queryInfo.init({
|
|
1771
|
+
document: this.transform(query).document,
|
|
1772
|
+
variables: variables,
|
|
1773
|
+
networkStatus: networkStatus,
|
|
1774
|
+
});
|
|
1775
|
+
var readCache = function () { return queryInfo.getDiff(variables); };
|
|
1776
|
+
var resultsFromCache = function (diff, networkStatus) {
|
|
1777
|
+
if (networkStatus === void 0) { networkStatus = queryInfo.networkStatus || exports.NetworkStatus.loading; }
|
|
1778
|
+
var data = diff.result;
|
|
1779
|
+
if (__DEV__ &&
|
|
1780
|
+
!returnPartialData &&
|
|
1781
|
+
!equality.equal(data, {})) {
|
|
1782
|
+
logMissingFieldErrors(diff.missing);
|
|
1783
|
+
}
|
|
1784
|
+
var fromData = function (data) { return utilities.Observable.of(tslib.__assign({ data: data, loading: isNetworkRequestInFlight(networkStatus), networkStatus: networkStatus }, (diff.complete ? null : { partial: true }))); };
|
|
1785
|
+
if (data && _this.transform(query).hasForcedResolvers) {
|
|
1786
|
+
return _this.localState.runResolvers({
|
|
1787
|
+
document: query,
|
|
1788
|
+
remoteResult: { data: data },
|
|
1789
|
+
context: context,
|
|
1790
|
+
variables: variables,
|
|
1791
|
+
onlyRunForcedResolvers: true,
|
|
1792
|
+
}).then(function (resolved) { return fromData(resolved.data || void 0); });
|
|
1793
|
+
}
|
|
1794
|
+
return fromData(data);
|
|
1795
|
+
};
|
|
1796
|
+
var cacheWriteBehavior = fetchPolicy === "no-cache" ? 0 :
|
|
1797
|
+
(networkStatus === exports.NetworkStatus.refetch &&
|
|
1798
|
+
refetchWritePolicy !== "merge") ? 1
|
|
1799
|
+
: 2;
|
|
1800
|
+
var resultsFromLink = function () { return _this.getResultsFromLink(queryInfo, cacheWriteBehavior, {
|
|
1801
|
+
variables: variables,
|
|
1802
|
+
context: context,
|
|
1803
|
+
fetchPolicy: fetchPolicy,
|
|
1804
|
+
errorPolicy: errorPolicy,
|
|
1805
|
+
}); };
|
|
1806
|
+
var shouldNotify = notifyOnNetworkStatusChange &&
|
|
1807
|
+
typeof oldNetworkStatus === "number" &&
|
|
1808
|
+
oldNetworkStatus !== networkStatus &&
|
|
1809
|
+
isNetworkRequestInFlight(networkStatus);
|
|
1810
|
+
switch (fetchPolicy) {
|
|
1811
|
+
default:
|
|
1812
|
+
case "cache-first": {
|
|
1813
|
+
var diff = readCache();
|
|
1814
|
+
if (diff.complete) {
|
|
1815
|
+
return [
|
|
1816
|
+
resultsFromCache(diff, queryInfo.markReady()),
|
|
1817
|
+
];
|
|
1818
|
+
}
|
|
1819
|
+
if (returnPartialData || shouldNotify) {
|
|
1820
|
+
return [
|
|
1821
|
+
resultsFromCache(diff),
|
|
1822
|
+
resultsFromLink(),
|
|
1823
|
+
];
|
|
1824
|
+
}
|
|
1825
|
+
return [
|
|
1826
|
+
resultsFromLink(),
|
|
1827
|
+
];
|
|
1828
|
+
}
|
|
1829
|
+
case "cache-and-network": {
|
|
1830
|
+
var diff = readCache();
|
|
1831
|
+
if (diff.complete || returnPartialData || shouldNotify) {
|
|
1832
|
+
return [
|
|
1833
|
+
resultsFromCache(diff),
|
|
1834
|
+
resultsFromLink(),
|
|
1835
|
+
];
|
|
1836
|
+
}
|
|
1837
|
+
return [
|
|
1838
|
+
resultsFromLink(),
|
|
1839
|
+
];
|
|
1840
|
+
}
|
|
1841
|
+
case "cache-only":
|
|
1842
|
+
return [
|
|
1843
|
+
resultsFromCache(readCache(), queryInfo.markReady()),
|
|
1844
|
+
];
|
|
1845
|
+
case "network-only":
|
|
1846
|
+
if (shouldNotify) {
|
|
1847
|
+
return [
|
|
1848
|
+
resultsFromCache(readCache()),
|
|
1849
|
+
resultsFromLink(),
|
|
1850
|
+
];
|
|
1851
|
+
}
|
|
1852
|
+
return [resultsFromLink()];
|
|
1853
|
+
case "no-cache":
|
|
1854
|
+
if (shouldNotify) {
|
|
1855
|
+
return [
|
|
1856
|
+
resultsFromCache(queryInfo.getDiff()),
|
|
1857
|
+
resultsFromLink(),
|
|
1858
|
+
];
|
|
1859
|
+
}
|
|
1860
|
+
return [resultsFromLink()];
|
|
1861
|
+
case "standby":
|
|
1862
|
+
return [];
|
|
1863
|
+
}
|
|
1864
|
+
};
|
|
1865
|
+
QueryManager.prototype.getQuery = function (queryId) {
|
|
1866
|
+
if (queryId && !this.queries.has(queryId)) {
|
|
1867
|
+
this.queries.set(queryId, new QueryInfo(this, queryId));
|
|
1868
|
+
}
|
|
1869
|
+
return this.queries.get(queryId);
|
|
1870
|
+
};
|
|
1871
|
+
QueryManager.prototype.prepareContext = function (context) {
|
|
1872
|
+
if (context === void 0) { context = {}; }
|
|
1873
|
+
var newContext = this.localState.prepareContext(context);
|
|
1874
|
+
return tslib.__assign(tslib.__assign({}, newContext), { clientAwareness: this.clientAwareness });
|
|
1875
|
+
};
|
|
1876
|
+
return QueryManager;
|
|
1877
|
+
}());
|
|
1878
|
+
|
|
1879
|
+
var hasSuggestedDevtools = false;
|
|
1880
|
+
var ApolloClient = (function () {
|
|
1881
|
+
function ApolloClient(options) {
|
|
1882
|
+
var _this = this;
|
|
1883
|
+
this.resetStoreCallbacks = [];
|
|
1884
|
+
this.clearStoreCallbacks = [];
|
|
1885
|
+
var uri = options.uri, credentials = options.credentials, headers = options.headers, cache = options.cache, _a = options.ssrMode, ssrMode = _a === void 0 ? false : _a, _b = options.ssrForceFetchDelay, ssrForceFetchDelay = _b === void 0 ? 0 : _b, _c = options.connectToDevTools, connectToDevTools = _c === void 0 ? typeof window === 'object' &&
|
|
1886
|
+
!window.__APOLLO_CLIENT__ &&
|
|
1887
|
+
__DEV__ : _c, _d = options.queryDeduplication, queryDeduplication = _d === void 0 ? true : _d, defaultOptions = options.defaultOptions, _e = options.assumeImmutableResults, assumeImmutableResults = _e === void 0 ? false : _e, resolvers = options.resolvers, typeDefs = options.typeDefs, fragmentMatcher = options.fragmentMatcher, clientAwarenessName = options.name, clientAwarenessVersion = options.version;
|
|
1888
|
+
var link = options.link;
|
|
1889
|
+
if (!link) {
|
|
1890
|
+
link = uri
|
|
1891
|
+
? new http.HttpLink({ uri: uri, credentials: credentials, headers: headers })
|
|
1892
|
+
: core.ApolloLink.empty();
|
|
1893
|
+
}
|
|
1894
|
+
if (!cache) {
|
|
1895
|
+
throw __DEV__ ? new globals.InvariantError("To initialize Apollo Client, you must specify a 'cache' property " +
|
|
1896
|
+
"in the options object. \n" +
|
|
1897
|
+
"For more information, please visit: https://go.apollo.dev/c/docs") : new globals.InvariantError(7);
|
|
1898
|
+
}
|
|
1899
|
+
this.link = link;
|
|
1900
|
+
this.cache = cache;
|
|
1901
|
+
this.disableNetworkFetches = ssrMode || ssrForceFetchDelay > 0;
|
|
1902
|
+
this.queryDeduplication = queryDeduplication;
|
|
1903
|
+
this.defaultOptions = defaultOptions || Object.create(null);
|
|
1904
|
+
this.typeDefs = typeDefs;
|
|
1905
|
+
if (ssrForceFetchDelay) {
|
|
1906
|
+
setTimeout(function () { return (_this.disableNetworkFetches = false); }, ssrForceFetchDelay);
|
|
1907
|
+
}
|
|
1908
|
+
this.watchQuery = this.watchQuery.bind(this);
|
|
1909
|
+
this.query = this.query.bind(this);
|
|
1910
|
+
this.mutate = this.mutate.bind(this);
|
|
1911
|
+
this.resetStore = this.resetStore.bind(this);
|
|
1912
|
+
this.reFetchObservableQueries = this.reFetchObservableQueries.bind(this);
|
|
1913
|
+
if (connectToDevTools && typeof window === 'object') {
|
|
1914
|
+
window.__APOLLO_CLIENT__ = this;
|
|
1915
|
+
}
|
|
1916
|
+
if (!hasSuggestedDevtools && __DEV__) {
|
|
1917
|
+
hasSuggestedDevtools = true;
|
|
1918
|
+
if (typeof window !== 'undefined' &&
|
|
1919
|
+
window.document &&
|
|
1920
|
+
window.top === window.self &&
|
|
1921
|
+
!window.__APOLLO_DEVTOOLS_GLOBAL_HOOK__) {
|
|
1922
|
+
var nav = window.navigator;
|
|
1923
|
+
var ua = nav && nav.userAgent;
|
|
1924
|
+
var url = void 0;
|
|
1925
|
+
if (typeof ua === "string") {
|
|
1926
|
+
if (ua.indexOf("Chrome/") > -1) {
|
|
1927
|
+
url = "https://chrome.google.com/webstore/detail/" +
|
|
1928
|
+
"apollo-client-developer-t/jdkknkkbebbapilgoeccciglkfbmbnfm";
|
|
1929
|
+
}
|
|
1930
|
+
else if (ua.indexOf("Firefox/") > -1) {
|
|
1931
|
+
url = "https://addons.mozilla.org/en-US/firefox/addon/apollo-developer-tools/";
|
|
1932
|
+
}
|
|
1933
|
+
}
|
|
1934
|
+
if (url) {
|
|
1935
|
+
__DEV__ && globals.invariant.log("Download the Apollo DevTools for a better development " +
|
|
1936
|
+
"experience: " + url);
|
|
1937
|
+
}
|
|
1938
|
+
}
|
|
1939
|
+
}
|
|
1940
|
+
this.version = version;
|
|
1941
|
+
this.localState = new LocalState({
|
|
1942
|
+
cache: cache,
|
|
1943
|
+
client: this,
|
|
1944
|
+
resolvers: resolvers,
|
|
1945
|
+
fragmentMatcher: fragmentMatcher,
|
|
1946
|
+
});
|
|
1947
|
+
this.queryManager = new QueryManager({
|
|
1948
|
+
cache: this.cache,
|
|
1949
|
+
link: this.link,
|
|
1950
|
+
defaultOptions: this.defaultOptions,
|
|
1951
|
+
queryDeduplication: queryDeduplication,
|
|
1952
|
+
ssrMode: ssrMode,
|
|
1953
|
+
clientAwareness: {
|
|
1954
|
+
name: clientAwarenessName,
|
|
1955
|
+
version: clientAwarenessVersion,
|
|
1956
|
+
},
|
|
1957
|
+
localState: this.localState,
|
|
1958
|
+
assumeImmutableResults: assumeImmutableResults,
|
|
1959
|
+
onBroadcast: connectToDevTools ? function () {
|
|
1960
|
+
if (_this.devToolsHookCb) {
|
|
1961
|
+
_this.devToolsHookCb({
|
|
1962
|
+
action: {},
|
|
1963
|
+
state: {
|
|
1964
|
+
queries: _this.queryManager.getQueryStore(),
|
|
1965
|
+
mutations: _this.queryManager.mutationStore || {},
|
|
1966
|
+
},
|
|
1967
|
+
dataWithOptimisticResults: _this.cache.extract(true),
|
|
1968
|
+
});
|
|
1969
|
+
}
|
|
1970
|
+
} : void 0,
|
|
1971
|
+
});
|
|
1972
|
+
}
|
|
1973
|
+
ApolloClient.prototype.stop = function () {
|
|
1974
|
+
this.queryManager.stop();
|
|
1975
|
+
};
|
|
1976
|
+
ApolloClient.prototype.watchQuery = function (options) {
|
|
1977
|
+
if (this.defaultOptions.watchQuery) {
|
|
1978
|
+
options = utilities.mergeOptions(this.defaultOptions.watchQuery, options);
|
|
1979
|
+
}
|
|
1980
|
+
if (this.disableNetworkFetches &&
|
|
1981
|
+
(options.fetchPolicy === 'network-only' ||
|
|
1982
|
+
options.fetchPolicy === 'cache-and-network')) {
|
|
1983
|
+
options = tslib.__assign(tslib.__assign({}, options), { fetchPolicy: 'cache-first' });
|
|
1984
|
+
}
|
|
1985
|
+
return this.queryManager.watchQuery(options);
|
|
1986
|
+
};
|
|
1987
|
+
ApolloClient.prototype.query = function (options) {
|
|
1988
|
+
if (this.defaultOptions.query) {
|
|
1989
|
+
options = utilities.mergeOptions(this.defaultOptions.query, options);
|
|
1990
|
+
}
|
|
1991
|
+
__DEV__ ? globals.invariant(options.fetchPolicy !== 'cache-and-network', 'The cache-and-network fetchPolicy does not work with client.query, because ' +
|
|
1992
|
+
'client.query can only return a single result. Please use client.watchQuery ' +
|
|
1993
|
+
'to receive multiple results from the cache and the network, or consider ' +
|
|
1994
|
+
'using a different fetchPolicy, such as cache-first or network-only.') : globals.invariant(options.fetchPolicy !== 'cache-and-network', 8);
|
|
1995
|
+
if (this.disableNetworkFetches && options.fetchPolicy === 'network-only') {
|
|
1996
|
+
options = tslib.__assign(tslib.__assign({}, options), { fetchPolicy: 'cache-first' });
|
|
1997
|
+
}
|
|
1998
|
+
return this.queryManager.query(options);
|
|
1999
|
+
};
|
|
2000
|
+
ApolloClient.prototype.mutate = function (options) {
|
|
2001
|
+
if (this.defaultOptions.mutate) {
|
|
2002
|
+
options = utilities.mergeOptions(this.defaultOptions.mutate, options);
|
|
2003
|
+
}
|
|
2004
|
+
return this.queryManager.mutate(options);
|
|
2005
|
+
};
|
|
2006
|
+
ApolloClient.prototype.subscribe = function (options) {
|
|
2007
|
+
return this.queryManager.startGraphQLSubscription(options);
|
|
2008
|
+
};
|
|
2009
|
+
ApolloClient.prototype.readQuery = function (options, optimistic) {
|
|
2010
|
+
if (optimistic === void 0) { optimistic = false; }
|
|
2011
|
+
return this.cache.readQuery(options, optimistic);
|
|
2012
|
+
};
|
|
2013
|
+
ApolloClient.prototype.readFragment = function (options, optimistic) {
|
|
2014
|
+
if (optimistic === void 0) { optimistic = false; }
|
|
2015
|
+
return this.cache.readFragment(options, optimistic);
|
|
2016
|
+
};
|
|
2017
|
+
ApolloClient.prototype.writeQuery = function (options) {
|
|
2018
|
+
this.cache.writeQuery(options);
|
|
2019
|
+
this.queryManager.broadcastQueries();
|
|
2020
|
+
};
|
|
2021
|
+
ApolloClient.prototype.writeFragment = function (options) {
|
|
2022
|
+
this.cache.writeFragment(options);
|
|
2023
|
+
this.queryManager.broadcastQueries();
|
|
2024
|
+
};
|
|
2025
|
+
ApolloClient.prototype.__actionHookForDevTools = function (cb) {
|
|
2026
|
+
this.devToolsHookCb = cb;
|
|
2027
|
+
};
|
|
2028
|
+
ApolloClient.prototype.__requestRaw = function (payload) {
|
|
2029
|
+
return core.execute(this.link, payload);
|
|
2030
|
+
};
|
|
2031
|
+
ApolloClient.prototype.resetStore = function () {
|
|
2032
|
+
var _this = this;
|
|
2033
|
+
return Promise.resolve()
|
|
2034
|
+
.then(function () { return _this.queryManager.clearStore({
|
|
2035
|
+
discardWatches: false,
|
|
2036
|
+
}); })
|
|
2037
|
+
.then(function () { return Promise.all(_this.resetStoreCallbacks.map(function (fn) { return fn(); })); })
|
|
2038
|
+
.then(function () { return _this.reFetchObservableQueries(); });
|
|
2039
|
+
};
|
|
2040
|
+
ApolloClient.prototype.clearStore = function () {
|
|
2041
|
+
var _this = this;
|
|
2042
|
+
return Promise.resolve()
|
|
2043
|
+
.then(function () { return _this.queryManager.clearStore({
|
|
2044
|
+
discardWatches: true,
|
|
2045
|
+
}); })
|
|
2046
|
+
.then(function () { return Promise.all(_this.clearStoreCallbacks.map(function (fn) { return fn(); })); });
|
|
2047
|
+
};
|
|
2048
|
+
ApolloClient.prototype.onResetStore = function (cb) {
|
|
2049
|
+
var _this = this;
|
|
2050
|
+
this.resetStoreCallbacks.push(cb);
|
|
2051
|
+
return function () {
|
|
2052
|
+
_this.resetStoreCallbacks = _this.resetStoreCallbacks.filter(function (c) { return c !== cb; });
|
|
2053
|
+
};
|
|
2054
|
+
};
|
|
2055
|
+
ApolloClient.prototype.onClearStore = function (cb) {
|
|
2056
|
+
var _this = this;
|
|
2057
|
+
this.clearStoreCallbacks.push(cb);
|
|
2058
|
+
return function () {
|
|
2059
|
+
_this.clearStoreCallbacks = _this.clearStoreCallbacks.filter(function (c) { return c !== cb; });
|
|
2060
|
+
};
|
|
2061
|
+
};
|
|
2062
|
+
ApolloClient.prototype.reFetchObservableQueries = function (includeStandby) {
|
|
2063
|
+
return this.queryManager.reFetchObservableQueries(includeStandby);
|
|
2064
|
+
};
|
|
2065
|
+
ApolloClient.prototype.refetchQueries = function (options) {
|
|
2066
|
+
var map = this.queryManager.refetchQueries(options);
|
|
2067
|
+
var queries = [];
|
|
2068
|
+
var results = [];
|
|
2069
|
+
map.forEach(function (result, obsQuery) {
|
|
2070
|
+
queries.push(obsQuery);
|
|
2071
|
+
results.push(result);
|
|
2072
|
+
});
|
|
2073
|
+
var result = Promise.all(results);
|
|
2074
|
+
result.queries = queries;
|
|
2075
|
+
result.results = results;
|
|
2076
|
+
result.catch(function (error) {
|
|
2077
|
+
__DEV__ && globals.invariant.debug("In client.refetchQueries, Promise.all promise rejected with error ".concat(error));
|
|
2078
|
+
});
|
|
2079
|
+
return result;
|
|
2080
|
+
};
|
|
2081
|
+
ApolloClient.prototype.getObservableQueries = function (include) {
|
|
2082
|
+
if (include === void 0) { include = "active"; }
|
|
2083
|
+
return this.queryManager.getObservableQueries(include);
|
|
2084
|
+
};
|
|
2085
|
+
ApolloClient.prototype.extract = function (optimistic) {
|
|
2086
|
+
return this.cache.extract(optimistic);
|
|
2087
|
+
};
|
|
2088
|
+
ApolloClient.prototype.restore = function (serializedState) {
|
|
2089
|
+
return this.cache.restore(serializedState);
|
|
2090
|
+
};
|
|
2091
|
+
ApolloClient.prototype.addResolvers = function (resolvers) {
|
|
2092
|
+
this.localState.addResolvers(resolvers);
|
|
2093
|
+
};
|
|
2094
|
+
ApolloClient.prototype.setResolvers = function (resolvers) {
|
|
2095
|
+
this.localState.setResolvers(resolvers);
|
|
2096
|
+
};
|
|
2097
|
+
ApolloClient.prototype.getResolvers = function () {
|
|
2098
|
+
return this.localState.getResolvers();
|
|
2099
|
+
};
|
|
2100
|
+
ApolloClient.prototype.setLocalStateFragmentMatcher = function (fragmentMatcher) {
|
|
2101
|
+
this.localState.setFragmentMatcher(fragmentMatcher);
|
|
2102
|
+
};
|
|
2103
|
+
ApolloClient.prototype.setLink = function (newLink) {
|
|
2104
|
+
this.link = this.queryManager.link = newLink;
|
|
2105
|
+
};
|
|
2106
|
+
return ApolloClient;
|
|
2107
|
+
}());
|
|
2108
|
+
|
|
2109
|
+
tsInvariant.setVerbosity(globals.DEV ? "log" : "silent");
|
|
2110
|
+
|
|
2111
|
+
exports.ApolloCache = cache.ApolloCache;
|
|
2112
|
+
exports.Cache = cache.Cache;
|
|
2113
|
+
exports.InMemoryCache = cache.InMemoryCache;
|
|
2114
|
+
exports.MissingFieldError = cache.MissingFieldError;
|
|
2115
|
+
exports.defaultDataIdFromObject = cache.defaultDataIdFromObject;
|
|
2116
|
+
exports.makeVar = cache.makeVar;
|
|
2117
|
+
exports.Observable = utilities.Observable;
|
|
2118
|
+
exports.isReference = utilities.isReference;
|
|
2119
|
+
exports.makeReference = utilities.makeReference;
|
|
2120
|
+
exports.mergeOptions = utilities.mergeOptions;
|
|
2121
|
+
exports.ApolloError = errors.ApolloError;
|
|
2122
|
+
exports.isApolloError = errors.isApolloError;
|
|
2123
|
+
exports.fromError = utils.fromError;
|
|
2124
|
+
exports.fromPromise = utils.fromPromise;
|
|
2125
|
+
exports.throwServerError = utils.throwServerError;
|
|
2126
|
+
exports.toPromise = utils.toPromise;
|
|
2127
|
+
exports.setLogVerbosity = tsInvariant.setVerbosity;
|
|
2128
|
+
exports.disableExperimentalFragmentVariables = graphqlTag.disableExperimentalFragmentVariables;
|
|
2129
|
+
exports.disableFragmentWarnings = graphqlTag.disableFragmentWarnings;
|
|
2130
|
+
exports.enableExperimentalFragmentVariables = graphqlTag.enableExperimentalFragmentVariables;
|
|
2131
|
+
exports.gql = graphqlTag.gql;
|
|
2132
|
+
exports.resetCaches = graphqlTag.resetCaches;
|
|
2133
|
+
exports.ApolloClient = ApolloClient;
|
|
2134
|
+
exports.ObservableQuery = ObservableQuery;
|
|
2135
|
+
for (var k in core) {
|
|
2136
|
+
if (k !== 'default' && !exports.hasOwnProperty(k)) exports[k] = core[k];
|
|
2137
|
+
}
|
|
2138
|
+
for (var k in http) {
|
|
2139
|
+
if (k !== 'default' && !exports.hasOwnProperty(k)) exports[k] = http[k];
|
|
2140
|
+
}
|
|
2141
|
+
//# sourceMappingURL=core.cjs.map
|