1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', { value: true });
|
4 |
|
5 | var tslib = require('tslib');
|
6 | var globals = require('../utilities/globals');
|
7 | var core = require('../link/core');
|
8 | var http = require('../link/http');
|
9 | var equal = require('@wry/equality');
|
10 | var utilities = require('../utilities');
|
11 | var cache = require('../cache');
|
12 | var errors = require('../errors');
|
13 | var graphql = require('graphql');
|
14 | var trie = require('@wry/trie');
|
15 | var utils = require('../link/utils');
|
16 | var tsInvariant = require('ts-invariant');
|
17 | var graphqlTag = require('graphql-tag');
|
18 |
|
19 | function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
|
20 |
|
21 | var equal__default = _interopDefaultLegacy(equal);
|
22 |
|
23 | var version = "3.9.10";
|
24 |
|
25 | function isNonNullObject(obj) {
|
26 | return obj !== null && typeof obj === "object";
|
27 | }
|
28 |
|
29 | function isNonEmptyArray(value) {
|
30 | return Array.isArray(value) && value.length > 0;
|
31 | }
|
32 |
|
33 | var hasOwnProperty$2 = Object.prototype.hasOwnProperty;
|
34 | var defaultReconciler = function (target, source, property) {
|
35 | return this.merge(target[property], source[property]);
|
36 | };
|
37 | var DeepMerger = (function () {
|
38 | function DeepMerger(reconciler) {
|
39 | if (reconciler === void 0) { reconciler = defaultReconciler; }
|
40 | this.reconciler = reconciler;
|
41 | this.isObject = isNonNullObject;
|
42 | this.pastCopies = new Set();
|
43 | }
|
44 | DeepMerger.prototype.merge = function (target, source) {
|
45 | var _this = this;
|
46 | var context = [];
|
47 | for (var _i = 2; _i < arguments.length; _i++) {
|
48 | context[_i - 2] = arguments[_i];
|
49 | }
|
50 | if (isNonNullObject(source) && isNonNullObject(target)) {
|
51 | Object.keys(source).forEach(function (sourceKey) {
|
52 | if (hasOwnProperty$2.call(target, sourceKey)) {
|
53 | var targetValue = target[sourceKey];
|
54 | if (source[sourceKey] !== targetValue) {
|
55 | var result = _this.reconciler.apply(_this, tslib.__spreadArray([target,
|
56 | source,
|
57 | sourceKey], context, false));
|
58 | if (result !== targetValue) {
|
59 | target = _this.shallowCopyForMerge(target);
|
60 | target[sourceKey] = result;
|
61 | }
|
62 | }
|
63 | }
|
64 | else {
|
65 | target = _this.shallowCopyForMerge(target);
|
66 | target[sourceKey] = source[sourceKey];
|
67 | }
|
68 | });
|
69 | return target;
|
70 | }
|
71 | return source;
|
72 | };
|
73 | DeepMerger.prototype.shallowCopyForMerge = function (value) {
|
74 | if (isNonNullObject(value)) {
|
75 | if (!this.pastCopies.has(value)) {
|
76 | if (Array.isArray(value)) {
|
77 | value = value.slice(0);
|
78 | }
|
79 | else {
|
80 | value = tslib.__assign({ __proto__: Object.getPrototypeOf(value) }, value);
|
81 | }
|
82 | this.pastCopies.add(value);
|
83 | }
|
84 | }
|
85 | return value;
|
86 | };
|
87 | return DeepMerger;
|
88 | }());
|
89 |
|
90 | function isExecutionPatchIncrementalResult(value) {
|
91 | return "incremental" in value;
|
92 | }
|
93 | function mergeIncrementalData(prevResult, result) {
|
94 | var mergedData = prevResult;
|
95 | var merger = new DeepMerger();
|
96 | if (isExecutionPatchIncrementalResult(result) &&
|
97 | isNonEmptyArray(result.incremental)) {
|
98 | result.incremental.forEach(function (_a) {
|
99 | var data = _a.data, path = _a.path;
|
100 | for (var i = path.length - 1; i >= 0; --i) {
|
101 | var key = path[i];
|
102 | var isNumericKey = !isNaN(+key);
|
103 | var parent_1 = isNumericKey ? [] : {};
|
104 | parent_1[key] = data;
|
105 | data = parent_1;
|
106 | }
|
107 | mergedData = merger.merge(mergedData, data);
|
108 | });
|
109 | }
|
110 | return mergedData;
|
111 | }
|
112 |
|
113 | exports.NetworkStatus = void 0;
|
114 | (function (NetworkStatus) {
|
115 | NetworkStatus[NetworkStatus["loading"] = 1] = "loading";
|
116 | NetworkStatus[NetworkStatus["setVariables"] = 2] = "setVariables";
|
117 | NetworkStatus[NetworkStatus["fetchMore"] = 3] = "fetchMore";
|
118 | NetworkStatus[NetworkStatus["refetch"] = 4] = "refetch";
|
119 | NetworkStatus[NetworkStatus["poll"] = 6] = "poll";
|
120 | NetworkStatus[NetworkStatus["ready"] = 7] = "ready";
|
121 | NetworkStatus[NetworkStatus["error"] = 8] = "error";
|
122 | })(exports.NetworkStatus || (exports.NetworkStatus = {}));
|
123 | function isNetworkRequestInFlight(networkStatus) {
|
124 | return networkStatus ? networkStatus < 7 : false;
|
125 | }
|
126 | function isNetworkRequestSettled(networkStatus) {
|
127 | return networkStatus === 7 || networkStatus === 8;
|
128 | }
|
129 |
|
130 | function equalByQuery(query, _a, _b, variables) {
|
131 | var aData = _a.data, aRest = tslib.__rest(_a, ["data"]);
|
132 | var bData = _b.data, bRest = tslib.__rest(_b, ["data"]);
|
133 | return (equal__default(aRest, bRest) &&
|
134 | equalBySelectionSet(utilities.getMainDefinition(query).selectionSet, aData, bData, {
|
135 | fragmentMap: utilities.createFragmentMap(utilities.getFragmentDefinitions(query)),
|
136 | variables: variables,
|
137 | }));
|
138 | }
|
139 | function equalBySelectionSet(selectionSet, aResult, bResult, context) {
|
140 | if (aResult === bResult) {
|
141 | return true;
|
142 | }
|
143 | var seenSelections = new Set();
|
144 | return selectionSet.selections.every(function (selection) {
|
145 | if (seenSelections.has(selection))
|
146 | return true;
|
147 | seenSelections.add(selection);
|
148 | if (!utilities.shouldInclude(selection, context.variables))
|
149 | return true;
|
150 | if (selectionHasNonreactiveDirective(selection))
|
151 | return true;
|
152 | if (utilities.isField(selection)) {
|
153 | var resultKey = utilities.resultKeyNameFromField(selection);
|
154 | var aResultChild = aResult && aResult[resultKey];
|
155 | var bResultChild = bResult && bResult[resultKey];
|
156 | var childSelectionSet = selection.selectionSet;
|
157 | if (!childSelectionSet) {
|
158 | return equal__default(aResultChild, bResultChild);
|
159 | }
|
160 | var aChildIsArray = Array.isArray(aResultChild);
|
161 | var bChildIsArray = Array.isArray(bResultChild);
|
162 | if (aChildIsArray !== bChildIsArray)
|
163 | return false;
|
164 | if (aChildIsArray && bChildIsArray) {
|
165 | var length_1 = aResultChild.length;
|
166 | if (bResultChild.length !== length_1) {
|
167 | return false;
|
168 | }
|
169 | for (var i = 0; i < length_1; ++i) {
|
170 | if (!equalBySelectionSet(childSelectionSet, aResultChild[i], bResultChild[i], context)) {
|
171 | return false;
|
172 | }
|
173 | }
|
174 | return true;
|
175 | }
|
176 | return equalBySelectionSet(childSelectionSet, aResultChild, bResultChild, context);
|
177 | }
|
178 | else {
|
179 | var fragment = utilities.getFragmentFromSelection(selection, context.fragmentMap);
|
180 | if (fragment) {
|
181 | if (selectionHasNonreactiveDirective(fragment))
|
182 | return true;
|
183 | return equalBySelectionSet(fragment.selectionSet,
|
184 | aResult, bResult, context);
|
185 | }
|
186 | }
|
187 | });
|
188 | }
|
189 | function selectionHasNonreactiveDirective(selection) {
|
190 | return (!!selection.directives && selection.directives.some(directiveIsNonreactive));
|
191 | }
|
192 | function directiveIsNonreactive(dir) {
|
193 | return dir.name.value === "nonreactive";
|
194 | }
|
195 |
|
196 | var assign = Object.assign, hasOwnProperty$1 = Object.hasOwnProperty;
|
197 | var ObservableQuery = (function (_super) {
|
198 | tslib.__extends(ObservableQuery, _super);
|
199 | function ObservableQuery(_a) {
|
200 | var queryManager = _a.queryManager, queryInfo = _a.queryInfo, options = _a.options;
|
201 | var _this = _super.call(this, function (observer) {
|
202 | try {
|
203 | var subObserver = observer._subscription._observer;
|
204 | if (subObserver && !subObserver.error) {
|
205 | subObserver.error = defaultSubscriptionObserverErrorCallback;
|
206 | }
|
207 | }
|
208 | catch (_a) { }
|
209 | var first = !_this.observers.size;
|
210 | _this.observers.add(observer);
|
211 | var last = _this.last;
|
212 | if (last && last.error) {
|
213 | observer.error && observer.error(last.error);
|
214 | }
|
215 | else if (last && last.result) {
|
216 | observer.next && observer.next(last.result);
|
217 | }
|
218 | if (first) {
|
219 | _this.reobserve().catch(function () { });
|
220 | }
|
221 | return function () {
|
222 | if (_this.observers.delete(observer) && !_this.observers.size) {
|
223 | _this.tearDownQuery();
|
224 | }
|
225 | };
|
226 | }) || this;
|
227 | _this.observers = new Set();
|
228 | _this.subscriptions = new Set();
|
229 | _this.queryInfo = queryInfo;
|
230 | _this.queryManager = queryManager;
|
231 | _this.waitForOwnResult = skipCacheDataFor(options.fetchPolicy);
|
232 | _this.isTornDown = false;
|
233 | var _b = queryManager.defaultOptions.watchQuery, _c = _b === void 0 ? {} : _b, _d = _c.fetchPolicy, defaultFetchPolicy = _d === void 0 ? "cache-first" : _d;
|
234 | var _e = options.fetchPolicy, fetchPolicy = _e === void 0 ? defaultFetchPolicy : _e,
|
235 | _f = options.initialFetchPolicy,
|
236 | initialFetchPolicy = _f === void 0 ? fetchPolicy === "standby" ? defaultFetchPolicy : (fetchPolicy) : _f;
|
237 | _this.options = tslib.__assign(tslib.__assign({}, options), {
|
238 | initialFetchPolicy: initialFetchPolicy,
|
239 | fetchPolicy: fetchPolicy });
|
240 | _this.queryId = queryInfo.queryId || queryManager.generateQueryId();
|
241 | var opDef = utilities.getOperationDefinition(_this.query);
|
242 | _this.queryName = opDef && opDef.name && opDef.name.value;
|
243 | return _this;
|
244 | }
|
245 | Object.defineProperty(ObservableQuery.prototype, "query", {
|
246 | get: function () {
|
247 | return this.lastQuery || this.options.query;
|
248 | },
|
249 | enumerable: false,
|
250 | configurable: true
|
251 | });
|
252 | Object.defineProperty(ObservableQuery.prototype, "variables", {
|
253 | get: function () {
|
254 | return this.options.variables;
|
255 | },
|
256 | enumerable: false,
|
257 | configurable: true
|
258 | });
|
259 | ObservableQuery.prototype.result = function () {
|
260 | var _this = this;
|
261 | return new Promise(function (resolve, reject) {
|
262 | var observer = {
|
263 | next: function (result) {
|
264 | resolve(result);
|
265 | _this.observers.delete(observer);
|
266 | if (!_this.observers.size) {
|
267 | _this.queryManager.removeQuery(_this.queryId);
|
268 | }
|
269 | setTimeout(function () {
|
270 | subscription.unsubscribe();
|
271 | }, 0);
|
272 | },
|
273 | error: reject,
|
274 | };
|
275 | var subscription = _this.subscribe(observer);
|
276 | });
|
277 | };
|
278 | ObservableQuery.prototype.resetDiff = function () {
|
279 | this.queryInfo.resetDiff();
|
280 | };
|
281 | ObservableQuery.prototype.getCurrentResult = function (saveAsLastResult) {
|
282 | if (saveAsLastResult === void 0) { saveAsLastResult = true; }
|
283 | var lastResult = this.getLastResult(true);
|
284 | var networkStatus = this.queryInfo.networkStatus ||
|
285 | (lastResult && lastResult.networkStatus) ||
|
286 | exports.NetworkStatus.ready;
|
287 | var result = tslib.__assign(tslib.__assign({}, lastResult), { loading: isNetworkRequestInFlight(networkStatus), networkStatus: networkStatus });
|
288 | var _a = this.options.fetchPolicy, fetchPolicy = _a === void 0 ? "cache-first" : _a;
|
289 | if (
|
290 | skipCacheDataFor(fetchPolicy) ||
|
291 | this.queryManager.getDocumentInfo(this.query).hasForcedResolvers) ;
|
292 | else if (this.waitForOwnResult) {
|
293 | this.queryInfo["updateWatch"]();
|
294 | }
|
295 | else {
|
296 | var diff = this.queryInfo.getDiff();
|
297 | if (diff.complete || this.options.returnPartialData) {
|
298 | result.data = diff.result;
|
299 | }
|
300 | if (equal.equal(result.data, {})) {
|
301 | result.data = void 0;
|
302 | }
|
303 | if (diff.complete) {
|
304 | delete result.partial;
|
305 | if (diff.complete &&
|
306 | result.networkStatus === exports.NetworkStatus.loading &&
|
307 | (fetchPolicy === "cache-first" || fetchPolicy === "cache-only")) {
|
308 | result.networkStatus = exports.NetworkStatus.ready;
|
309 | result.loading = false;
|
310 | }
|
311 | }
|
312 | else {
|
313 | result.partial = true;
|
314 | }
|
315 | if (globalThis.__DEV__ !== false &&
|
316 | !diff.complete &&
|
317 | !this.options.partialRefetch &&
|
318 | !result.loading &&
|
319 | !result.data &&
|
320 | !result.error) {
|
321 | logMissingFieldErrors(diff.missing);
|
322 | }
|
323 | }
|
324 | if (saveAsLastResult) {
|
325 | this.updateLastResult(result);
|
326 | }
|
327 | return result;
|
328 | };
|
329 | ObservableQuery.prototype.isDifferentFromLastResult = function (newResult, variables) {
|
330 | if (!this.last) {
|
331 | return true;
|
332 | }
|
333 | var resultIsDifferent = this.queryManager.getDocumentInfo(this.query).hasNonreactiveDirective ?
|
334 | !equalByQuery(this.query, this.last.result, newResult, this.variables)
|
335 | : !equal.equal(this.last.result, newResult);
|
336 | return (resultIsDifferent || (variables && !equal.equal(this.last.variables, variables)));
|
337 | };
|
338 | ObservableQuery.prototype.getLast = function (key, variablesMustMatch) {
|
339 | var last = this.last;
|
340 | if (last &&
|
341 | last[key] &&
|
342 | (!variablesMustMatch || equal.equal(last.variables, this.variables))) {
|
343 | return last[key];
|
344 | }
|
345 | };
|
346 | ObservableQuery.prototype.getLastResult = function (variablesMustMatch) {
|
347 | return this.getLast("result", variablesMustMatch);
|
348 | };
|
349 | ObservableQuery.prototype.getLastError = function (variablesMustMatch) {
|
350 | return this.getLast("error", variablesMustMatch);
|
351 | };
|
352 | ObservableQuery.prototype.resetLastResults = function () {
|
353 | delete this.last;
|
354 | this.isTornDown = false;
|
355 | };
|
356 | ObservableQuery.prototype.resetQueryStoreErrors = function () {
|
357 | this.queryManager.resetErrors(this.queryId);
|
358 | };
|
359 | ObservableQuery.prototype.refetch = function (variables) {
|
360 | var _a;
|
361 | var reobserveOptions = {
|
362 | pollInterval: 0,
|
363 | };
|
364 | var fetchPolicy = this.options.fetchPolicy;
|
365 | if (fetchPolicy === "cache-and-network") {
|
366 | reobserveOptions.fetchPolicy = fetchPolicy;
|
367 | }
|
368 | else if (fetchPolicy === "no-cache") {
|
369 | reobserveOptions.fetchPolicy = "no-cache";
|
370 | }
|
371 | else {
|
372 | reobserveOptions.fetchPolicy = "network-only";
|
373 | }
|
374 | if (globalThis.__DEV__ !== false && variables && hasOwnProperty$1.call(variables, "variables")) {
|
375 | var queryDef = utilities.getQueryDefinition(this.query);
|
376 | var vars = queryDef.variableDefinitions;
|
377 | if (!vars || !vars.some(function (v) { return v.variable.name.value === "variables"; })) {
|
378 | globalThis.__DEV__ !== false && globals.invariant.warn(
|
379 | 20,
|
380 | variables,
|
381 | ((_a = queryDef.name) === null || _a === void 0 ? void 0 : _a.value) || queryDef
|
382 | );
|
383 | }
|
384 | }
|
385 | if (variables && !equal.equal(this.options.variables, variables)) {
|
386 | reobserveOptions.variables = this.options.variables = tslib.__assign(tslib.__assign({}, this.options.variables), variables);
|
387 | }
|
388 | this.queryInfo.resetLastWrite();
|
389 | return this.reobserve(reobserveOptions, exports.NetworkStatus.refetch);
|
390 | };
|
391 | ObservableQuery.prototype.fetchMore = function (fetchMoreOptions) {
|
392 | var _this = this;
|
393 | var combinedOptions = tslib.__assign(tslib.__assign({}, (fetchMoreOptions.query ? fetchMoreOptions : (tslib.__assign(tslib.__assign(tslib.__assign(tslib.__assign({}, this.options), { query: this.options.query }), fetchMoreOptions), { variables: tslib.__assign(tslib.__assign({}, this.options.variables), fetchMoreOptions.variables) })))), {
|
394 | fetchPolicy: "no-cache" });
|
395 | combinedOptions.query = this.transformDocument(combinedOptions.query);
|
396 | var qid = this.queryManager.generateQueryId();
|
397 | this.lastQuery =
|
398 | fetchMoreOptions.query ?
|
399 | this.transformDocument(this.options.query)
|
400 | : combinedOptions.query;
|
401 | var queryInfo = this.queryInfo;
|
402 | var originalNetworkStatus = queryInfo.networkStatus;
|
403 | queryInfo.networkStatus = exports.NetworkStatus.fetchMore;
|
404 | if (combinedOptions.notifyOnNetworkStatusChange) {
|
405 | this.observe();
|
406 | }
|
407 | var updatedQuerySet = new Set();
|
408 | return this.queryManager
|
409 | .fetchQuery(qid, combinedOptions, exports.NetworkStatus.fetchMore)
|
410 | .then(function (fetchMoreResult) {
|
411 | _this.queryManager.removeQuery(qid);
|
412 | if (queryInfo.networkStatus === exports.NetworkStatus.fetchMore) {
|
413 | queryInfo.networkStatus = originalNetworkStatus;
|
414 | }
|
415 | _this.queryManager.cache.batch({
|
416 | update: function (cache) {
|
417 | var updateQuery = fetchMoreOptions.updateQuery;
|
418 | if (updateQuery) {
|
419 | cache.updateQuery({
|
420 | query: _this.query,
|
421 | variables: _this.variables,
|
422 | returnPartialData: true,
|
423 | optimistic: false,
|
424 | }, function (previous) {
|
425 | return updateQuery(previous, {
|
426 | fetchMoreResult: fetchMoreResult.data,
|
427 | variables: combinedOptions.variables,
|
428 | });
|
429 | });
|
430 | }
|
431 | else {
|
432 | cache.writeQuery({
|
433 | query: combinedOptions.query,
|
434 | variables: combinedOptions.variables,
|
435 | data: fetchMoreResult.data,
|
436 | });
|
437 | }
|
438 | },
|
439 | onWatchUpdated: function (watch) {
|
440 | updatedQuerySet.add(watch.query);
|
441 | },
|
442 | });
|
443 | return fetchMoreResult;
|
444 | })
|
445 | .finally(function () {
|
446 | if (!updatedQuerySet.has(_this.query)) {
|
447 | reobserveCacheFirst(_this);
|
448 | }
|
449 | });
|
450 | };
|
451 | ObservableQuery.prototype.subscribeToMore = function (options) {
|
452 | var _this = this;
|
453 | var subscription = this.queryManager
|
454 | .startGraphQLSubscription({
|
455 | query: options.document,
|
456 | variables: options.variables,
|
457 | context: options.context,
|
458 | })
|
459 | .subscribe({
|
460 | next: function (subscriptionData) {
|
461 | var updateQuery = options.updateQuery;
|
462 | if (updateQuery) {
|
463 | _this.updateQuery(function (previous, _a) {
|
464 | var variables = _a.variables;
|
465 | return updateQuery(previous, {
|
466 | subscriptionData: subscriptionData,
|
467 | variables: variables,
|
468 | });
|
469 | });
|
470 | }
|
471 | },
|
472 | error: function (err) {
|
473 | if (options.onError) {
|
474 | options.onError(err);
|
475 | return;
|
476 | }
|
477 | globalThis.__DEV__ !== false && globals.invariant.error(21, err);
|
478 | },
|
479 | });
|
480 | this.subscriptions.add(subscription);
|
481 | return function () {
|
482 | if (_this.subscriptions.delete(subscription)) {
|
483 | subscription.unsubscribe();
|
484 | }
|
485 | };
|
486 | };
|
487 | ObservableQuery.prototype.setOptions = function (newOptions) {
|
488 | return this.reobserve(newOptions);
|
489 | };
|
490 | ObservableQuery.prototype.silentSetOptions = function (newOptions) {
|
491 | var mergedOptions = utilities.compact(this.options, newOptions || {});
|
492 | assign(this.options, mergedOptions);
|
493 | };
|
494 | ObservableQuery.prototype.setVariables = function (variables) {
|
495 | if (equal.equal(this.variables, variables)) {
|
496 | return this.observers.size ? this.result() : Promise.resolve();
|
497 | }
|
498 | this.options.variables = variables;
|
499 | if (!this.observers.size) {
|
500 | return Promise.resolve();
|
501 | }
|
502 | return this.reobserve({
|
503 | fetchPolicy: this.options.initialFetchPolicy,
|
504 | variables: variables,
|
505 | }, exports.NetworkStatus.setVariables);
|
506 | };
|
507 | ObservableQuery.prototype.updateQuery = function (mapFn) {
|
508 | var queryManager = this.queryManager;
|
509 | var result = queryManager.cache.diff({
|
510 | query: this.options.query,
|
511 | variables: this.variables,
|
512 | returnPartialData: true,
|
513 | optimistic: false,
|
514 | }).result;
|
515 | var newResult = mapFn(result, {
|
516 | variables: this.variables,
|
517 | });
|
518 | if (newResult) {
|
519 | queryManager.cache.writeQuery({
|
520 | query: this.options.query,
|
521 | data: newResult,
|
522 | variables: this.variables,
|
523 | });
|
524 | queryManager.broadcastQueries();
|
525 | }
|
526 | };
|
527 | ObservableQuery.prototype.startPolling = function (pollInterval) {
|
528 | this.options.pollInterval = pollInterval;
|
529 | this.updatePolling();
|
530 | };
|
531 | ObservableQuery.prototype.stopPolling = function () {
|
532 | this.options.pollInterval = 0;
|
533 | this.updatePolling();
|
534 | };
|
535 | ObservableQuery.prototype.applyNextFetchPolicy = function (reason,
|
536 | options) {
|
537 | if (options.nextFetchPolicy) {
|
538 | var _a = options.fetchPolicy, fetchPolicy = _a === void 0 ? "cache-first" : _a, _b = options.initialFetchPolicy, initialFetchPolicy = _b === void 0 ? fetchPolicy : _b;
|
539 | if (fetchPolicy === "standby") ;
|
540 | else if (typeof options.nextFetchPolicy === "function") {
|
541 | options.fetchPolicy = options.nextFetchPolicy(fetchPolicy, {
|
542 | reason: reason,
|
543 | options: options,
|
544 | observable: this,
|
545 | initialFetchPolicy: initialFetchPolicy,
|
546 | });
|
547 | }
|
548 | else if (reason === "variables-changed") {
|
549 | options.fetchPolicy = initialFetchPolicy;
|
550 | }
|
551 | else {
|
552 | options.fetchPolicy = options.nextFetchPolicy;
|
553 | }
|
554 | }
|
555 | return options.fetchPolicy;
|
556 | };
|
557 | ObservableQuery.prototype.fetch = function (options, newNetworkStatus, query) {
|
558 | this.queryManager.setObservableQuery(this);
|
559 | return this.queryManager["fetchConcastWithInfo"](this.queryId, options, newNetworkStatus, query);
|
560 | };
|
561 | ObservableQuery.prototype.updatePolling = function () {
|
562 | var _this = this;
|
563 | if (this.queryManager.ssrMode) {
|
564 | return;
|
565 | }
|
566 | var _a = this, pollingInfo = _a.pollingInfo, pollInterval = _a.options.pollInterval;
|
567 | if (!pollInterval) {
|
568 | if (pollingInfo) {
|
569 | clearTimeout(pollingInfo.timeout);
|
570 | delete this.pollingInfo;
|
571 | }
|
572 | return;
|
573 | }
|
574 | if (pollingInfo && pollingInfo.interval === pollInterval) {
|
575 | return;
|
576 | }
|
577 | globals.invariant(pollInterval, 22);
|
578 | var info = pollingInfo || (this.pollingInfo = {});
|
579 | info.interval = pollInterval;
|
580 | var maybeFetch = function () {
|
581 | var _a, _b;
|
582 | if (_this.pollingInfo) {
|
583 | if (!isNetworkRequestInFlight(_this.queryInfo.networkStatus) &&
|
584 | !((_b = (_a = _this.options).skipPollAttempt) === null || _b === void 0 ? void 0 : _b.call(_a))) {
|
585 | _this.reobserve({
|
586 | fetchPolicy: _this.options.initialFetchPolicy === "no-cache" ?
|
587 | "no-cache"
|
588 | : "network-only",
|
589 | }, exports.NetworkStatus.poll).then(poll, poll);
|
590 | }
|
591 | else {
|
592 | poll();
|
593 | }
|
594 | }
|
595 | };
|
596 | var poll = function () {
|
597 | var info = _this.pollingInfo;
|
598 | if (info) {
|
599 | clearTimeout(info.timeout);
|
600 | info.timeout = setTimeout(maybeFetch, info.interval);
|
601 | }
|
602 | };
|
603 | poll();
|
604 | };
|
605 | ObservableQuery.prototype.updateLastResult = function (newResult, variables) {
|
606 | if (variables === void 0) { variables = this.variables; }
|
607 | var error = this.getLastError();
|
608 | if (error && this.last && !equal.equal(variables, this.last.variables)) {
|
609 | error = void 0;
|
610 | }
|
611 | return (this.last = tslib.__assign({ result: this.queryManager.assumeImmutableResults ?
|
612 | newResult
|
613 | : utilities.cloneDeep(newResult), variables: variables }, (error ? { error: error } : null)));
|
614 | };
|
615 | ObservableQuery.prototype.reobserveAsConcast = function (newOptions, newNetworkStatus) {
|
616 | var _this = this;
|
617 | this.isTornDown = false;
|
618 | var useDisposableConcast =
|
619 | newNetworkStatus === exports.NetworkStatus.refetch ||
|
620 | newNetworkStatus === exports.NetworkStatus.fetchMore ||
|
621 | newNetworkStatus === exports.NetworkStatus.poll;
|
622 | var oldVariables = this.options.variables;
|
623 | var oldFetchPolicy = this.options.fetchPolicy;
|
624 | var mergedOptions = utilities.compact(this.options, newOptions || {});
|
625 | var options = useDisposableConcast ?
|
626 | mergedOptions
|
627 | : assign(this.options, mergedOptions);
|
628 | var query = this.transformDocument(options.query);
|
629 | this.lastQuery = query;
|
630 | if (!useDisposableConcast) {
|
631 | this.updatePolling();
|
632 | if (newOptions &&
|
633 | newOptions.variables &&
|
634 | !equal.equal(newOptions.variables, oldVariables) &&
|
635 | options.fetchPolicy !== "standby" &&
|
636 | options.fetchPolicy === oldFetchPolicy) {
|
637 | this.applyNextFetchPolicy("variables-changed", options);
|
638 | if (newNetworkStatus === void 0) {
|
639 | newNetworkStatus = exports.NetworkStatus.setVariables;
|
640 | }
|
641 | }
|
642 | }
|
643 | this.waitForOwnResult && (this.waitForOwnResult = skipCacheDataFor(options.fetchPolicy));
|
644 | var finishWaitingForOwnResult = function () {
|
645 | if (_this.concast === concast) {
|
646 | _this.waitForOwnResult = false;
|
647 | }
|
648 | };
|
649 | var variables = options.variables && tslib.__assign({}, options.variables);
|
650 | var _a = this.fetch(options, newNetworkStatus, query), concast = _a.concast, fromLink = _a.fromLink;
|
651 | var observer = {
|
652 | next: function (result) {
|
653 | if (equal.equal(_this.variables, variables)) {
|
654 | finishWaitingForOwnResult();
|
655 | _this.reportResult(result, variables);
|
656 | }
|
657 | },
|
658 | error: function (error) {
|
659 | if (equal.equal(_this.variables, variables)) {
|
660 | finishWaitingForOwnResult();
|
661 | _this.reportError(error, variables);
|
662 | }
|
663 | },
|
664 | };
|
665 | if (!useDisposableConcast && (fromLink || !this.concast)) {
|
666 | if (this.concast && this.observer) {
|
667 | this.concast.removeObserver(this.observer);
|
668 | }
|
669 | this.concast = concast;
|
670 | this.observer = observer;
|
671 | }
|
672 | concast.addObserver(observer);
|
673 | return concast;
|
674 | };
|
675 | ObservableQuery.prototype.reobserve = function (newOptions, newNetworkStatus) {
|
676 | return this.reobserveAsConcast(newOptions, newNetworkStatus)
|
677 | .promise;
|
678 | };
|
679 | ObservableQuery.prototype.resubscribeAfterError = function () {
|
680 | var args = [];
|
681 | for (var _i = 0; _i < arguments.length; _i++) {
|
682 | args[_i] = arguments[_i];
|
683 | }
|
684 | var last = this.last;
|
685 | this.resetLastResults();
|
686 | var subscription = this.subscribe.apply(this, args);
|
687 | this.last = last;
|
688 | return subscription;
|
689 | };
|
690 | ObservableQuery.prototype.observe = function () {
|
691 | this.reportResult(
|
692 | this.getCurrentResult(false), this.variables);
|
693 | };
|
694 | ObservableQuery.prototype.reportResult = function (result, variables) {
|
695 | var lastError = this.getLastError();
|
696 | var isDifferent = this.isDifferentFromLastResult(result, variables);
|
697 | if (lastError || !result.partial || this.options.returnPartialData) {
|
698 | this.updateLastResult(result, variables);
|
699 | }
|
700 | if (lastError || isDifferent) {
|
701 | utilities.iterateObserversSafely(this.observers, "next", result);
|
702 | }
|
703 | };
|
704 | ObservableQuery.prototype.reportError = function (error, variables) {
|
705 | var errorResult = tslib.__assign(tslib.__assign({}, this.getLastResult()), { error: error, errors: error.graphQLErrors, networkStatus: exports.NetworkStatus.error, loading: false });
|
706 | this.updateLastResult(errorResult, variables);
|
707 | utilities.iterateObserversSafely(this.observers, "error", (this.last.error = error));
|
708 | };
|
709 | ObservableQuery.prototype.hasObservers = function () {
|
710 | return this.observers.size > 0;
|
711 | };
|
712 | ObservableQuery.prototype.tearDownQuery = function () {
|
713 | if (this.isTornDown)
|
714 | return;
|
715 | if (this.concast && this.observer) {
|
716 | this.concast.removeObserver(this.observer);
|
717 | delete this.concast;
|
718 | delete this.observer;
|
719 | }
|
720 | this.stopPolling();
|
721 | this.subscriptions.forEach(function (sub) { return sub.unsubscribe(); });
|
722 | this.subscriptions.clear();
|
723 | this.queryManager.stopQuery(this.queryId);
|
724 | this.observers.clear();
|
725 | this.isTornDown = true;
|
726 | };
|
727 | ObservableQuery.prototype.transformDocument = function (document) {
|
728 | return this.queryManager.transform(document);
|
729 | };
|
730 | return ObservableQuery;
|
731 | }(utilities.Observable));
|
732 | utilities.fixObservableSubclass(ObservableQuery);
|
733 | function reobserveCacheFirst(obsQuery) {
|
734 | var _a = obsQuery.options, fetchPolicy = _a.fetchPolicy, nextFetchPolicy = _a.nextFetchPolicy;
|
735 | if (fetchPolicy === "cache-and-network" || fetchPolicy === "network-only") {
|
736 | return obsQuery.reobserve({
|
737 | fetchPolicy: "cache-first",
|
738 | nextFetchPolicy: function (currentFetchPolicy, context) {
|
739 | this.nextFetchPolicy = nextFetchPolicy;
|
740 | if (typeof this.nextFetchPolicy === "function") {
|
741 | return this.nextFetchPolicy(currentFetchPolicy, context);
|
742 | }
|
743 | return fetchPolicy;
|
744 | },
|
745 | });
|
746 | }
|
747 | return obsQuery.reobserve();
|
748 | }
|
749 | function defaultSubscriptionObserverErrorCallback(error) {
|
750 | globalThis.__DEV__ !== false && globals.invariant.error(23, error.message, error.stack);
|
751 | }
|
752 | function logMissingFieldErrors(missing) {
|
753 | if (globalThis.__DEV__ !== false && missing) {
|
754 | globalThis.__DEV__ !== false && globals.invariant.debug(24, missing);
|
755 | }
|
756 | }
|
757 | function skipCacheDataFor(fetchPolicy ) {
|
758 | return (fetchPolicy === "network-only" ||
|
759 | fetchPolicy === "no-cache" ||
|
760 | fetchPolicy === "standby");
|
761 | }
|
762 |
|
763 | var LocalState = (function () {
|
764 | function LocalState(_a) {
|
765 | var cache = _a.cache, client = _a.client, resolvers = _a.resolvers, fragmentMatcher = _a.fragmentMatcher;
|
766 | this.selectionsToResolveCache = new WeakMap();
|
767 | this.cache = cache;
|
768 | if (client) {
|
769 | this.client = client;
|
770 | }
|
771 | if (resolvers) {
|
772 | this.addResolvers(resolvers);
|
773 | }
|
774 | if (fragmentMatcher) {
|
775 | this.setFragmentMatcher(fragmentMatcher);
|
776 | }
|
777 | }
|
778 | LocalState.prototype.addResolvers = function (resolvers) {
|
779 | var _this = this;
|
780 | this.resolvers = this.resolvers || {};
|
781 | if (Array.isArray(resolvers)) {
|
782 | resolvers.forEach(function (resolverGroup) {
|
783 | _this.resolvers = utilities.mergeDeep(_this.resolvers, resolverGroup);
|
784 | });
|
785 | }
|
786 | else {
|
787 | this.resolvers = utilities.mergeDeep(this.resolvers, resolvers);
|
788 | }
|
789 | };
|
790 | LocalState.prototype.setResolvers = function (resolvers) {
|
791 | this.resolvers = {};
|
792 | this.addResolvers(resolvers);
|
793 | };
|
794 | LocalState.prototype.getResolvers = function () {
|
795 | return this.resolvers || {};
|
796 | };
|
797 | LocalState.prototype.runResolvers = function (_a) {
|
798 | return tslib.__awaiter(this, arguments, void 0, function (_b) {
|
799 | var document = _b.document, remoteResult = _b.remoteResult, context = _b.context, variables = _b.variables, _c = _b.onlyRunForcedResolvers, onlyRunForcedResolvers = _c === void 0 ? false : _c;
|
800 | return tslib.__generator(this, function (_d) {
|
801 | if (document) {
|
802 | return [2 , this.resolveDocument(document, remoteResult.data, context, variables, this.fragmentMatcher, onlyRunForcedResolvers).then(function (localResult) { return (tslib.__assign(tslib.__assign({}, remoteResult), { data: localResult.result })); })];
|
803 | }
|
804 | return [2 , remoteResult];
|
805 | });
|
806 | });
|
807 | };
|
808 | LocalState.prototype.setFragmentMatcher = function (fragmentMatcher) {
|
809 | this.fragmentMatcher = fragmentMatcher;
|
810 | };
|
811 | LocalState.prototype.getFragmentMatcher = function () {
|
812 | return this.fragmentMatcher;
|
813 | };
|
814 | LocalState.prototype.clientQuery = function (document) {
|
815 | if (utilities.hasDirectives(["client"], document)) {
|
816 | if (this.resolvers) {
|
817 | return document;
|
818 | }
|
819 | }
|
820 | return null;
|
821 | };
|
822 | LocalState.prototype.serverQuery = function (document) {
|
823 | return utilities.removeClientSetsFromDocument(document);
|
824 | };
|
825 | LocalState.prototype.prepareContext = function (context) {
|
826 | var cache = this.cache;
|
827 | return tslib.__assign(tslib.__assign({}, context), { cache: cache,
|
828 | getCacheKey: function (obj) {
|
829 | return cache.identify(obj);
|
830 | } });
|
831 | };
|
832 | LocalState.prototype.addExportedVariables = function (document_1) {
|
833 | return tslib.__awaiter(this, arguments, void 0, function (document, variables, context) {
|
834 | if (variables === void 0) { variables = {}; }
|
835 | if (context === void 0) { context = {}; }
|
836 | return tslib.__generator(this, function (_a) {
|
837 | if (document) {
|
838 | return [2 , this.resolveDocument(document, this.buildRootValueFromCache(document, variables) || {}, this.prepareContext(context), variables).then(function (data) { return (tslib.__assign(tslib.__assign({}, variables), data.exportedVariables)); })];
|
839 | }
|
840 | return [2 , tslib.__assign({}, variables)];
|
841 | });
|
842 | });
|
843 | };
|
844 | LocalState.prototype.shouldForceResolvers = function (document) {
|
845 | var forceResolvers = false;
|
846 | graphql.visit(document, {
|
847 | Directive: {
|
848 | enter: function (node) {
|
849 | if (node.name.value === "client" && node.arguments) {
|
850 | forceResolvers = node.arguments.some(function (arg) {
|
851 | return arg.name.value === "always" &&
|
852 | arg.value.kind === "BooleanValue" &&
|
853 | arg.value.value === true;
|
854 | });
|
855 | if (forceResolvers) {
|
856 | return graphql.BREAK;
|
857 | }
|
858 | }
|
859 | },
|
860 | },
|
861 | });
|
862 | return forceResolvers;
|
863 | };
|
864 | LocalState.prototype.buildRootValueFromCache = function (document, variables) {
|
865 | return this.cache.diff({
|
866 | query: utilities.buildQueryFromSelectionSet(document),
|
867 | variables: variables,
|
868 | returnPartialData: true,
|
869 | optimistic: false,
|
870 | }).result;
|
871 | };
|
872 | LocalState.prototype.resolveDocument = function (document_1, rootValue_1) {
|
873 | return tslib.__awaiter(this, arguments, void 0, function (document, rootValue, context, variables, fragmentMatcher, onlyRunForcedResolvers) {
|
874 | var mainDefinition, fragments, fragmentMap, selectionsToResolve, definitionOperation, defaultOperationType, _a, cache, client, execContext, isClientFieldDescendant;
|
875 | if (context === void 0) { context = {}; }
|
876 | if (variables === void 0) { variables = {}; }
|
877 | if (fragmentMatcher === void 0) { fragmentMatcher = function () { return true; }; }
|
878 | if (onlyRunForcedResolvers === void 0) { onlyRunForcedResolvers = false; }
|
879 | return tslib.__generator(this, function (_b) {
|
880 | mainDefinition = utilities.getMainDefinition(document);
|
881 | fragments = utilities.getFragmentDefinitions(document);
|
882 | fragmentMap = utilities.createFragmentMap(fragments);
|
883 | selectionsToResolve = this.collectSelectionsToResolve(mainDefinition, fragmentMap);
|
884 | definitionOperation = mainDefinition.operation;
|
885 | defaultOperationType = definitionOperation ?
|
886 | definitionOperation.charAt(0).toUpperCase() +
|
887 | definitionOperation.slice(1)
|
888 | : "Query";
|
889 | _a = this, cache = _a.cache, client = _a.client;
|
890 | execContext = {
|
891 | fragmentMap: fragmentMap,
|
892 | context: tslib.__assign(tslib.__assign({}, context), { cache: cache, client: client }),
|
893 | variables: variables,
|
894 | fragmentMatcher: fragmentMatcher,
|
895 | defaultOperationType: defaultOperationType,
|
896 | exportedVariables: {},
|
897 | selectionsToResolve: selectionsToResolve,
|
898 | onlyRunForcedResolvers: onlyRunForcedResolvers,
|
899 | };
|
900 | isClientFieldDescendant = false;
|
901 | return [2 , this.resolveSelectionSet(mainDefinition.selectionSet, isClientFieldDescendant, rootValue, execContext).then(function (result) { return ({
|
902 | result: result,
|
903 | exportedVariables: execContext.exportedVariables,
|
904 | }); })];
|
905 | });
|
906 | });
|
907 | };
|
908 | LocalState.prototype.resolveSelectionSet = function (selectionSet, isClientFieldDescendant, rootValue, execContext) {
|
909 | return tslib.__awaiter(this, void 0, void 0, function () {
|
910 | var fragmentMap, context, variables, resultsToMerge, execute;
|
911 | var _this = this;
|
912 | return tslib.__generator(this, function (_a) {
|
913 | fragmentMap = execContext.fragmentMap, context = execContext.context, variables = execContext.variables;
|
914 | resultsToMerge = [rootValue];
|
915 | execute = function (selection) { return tslib.__awaiter(_this, void 0, void 0, function () {
|
916 | var fragment, typeCondition;
|
917 | return tslib.__generator(this, function (_a) {
|
918 | if (!isClientFieldDescendant &&
|
919 | !execContext.selectionsToResolve.has(selection)) {
|
920 | return [2 ];
|
921 | }
|
922 | if (!utilities.shouldInclude(selection, variables)) {
|
923 | return [2 ];
|
924 | }
|
925 | if (utilities.isField(selection)) {
|
926 | return [2 , this.resolveField(selection, isClientFieldDescendant, rootValue, execContext).then(function (fieldResult) {
|
927 | var _a;
|
928 | if (typeof fieldResult !== "undefined") {
|
929 | resultsToMerge.push((_a = {},
|
930 | _a[utilities.resultKeyNameFromField(selection)] = fieldResult,
|
931 | _a));
|
932 | }
|
933 | })];
|
934 | }
|
935 | if (utilities.isInlineFragment(selection)) {
|
936 | fragment = selection;
|
937 | }
|
938 | else {
|
939 | fragment = fragmentMap[selection.name.value];
|
940 | globals.invariant(fragment, 18, selection.name.value);
|
941 | }
|
942 | if (fragment && fragment.typeCondition) {
|
943 | typeCondition = fragment.typeCondition.name.value;
|
944 | if (execContext.fragmentMatcher(rootValue, typeCondition, context)) {
|
945 | return [2 , this.resolveSelectionSet(fragment.selectionSet, isClientFieldDescendant, rootValue, execContext).then(function (fragmentResult) {
|
946 | resultsToMerge.push(fragmentResult);
|
947 | })];
|
948 | }
|
949 | }
|
950 | return [2 ];
|
951 | });
|
952 | }); };
|
953 | return [2 , Promise.all(selectionSet.selections.map(execute)).then(function () {
|
954 | return utilities.mergeDeepArray(resultsToMerge);
|
955 | })];
|
956 | });
|
957 | });
|
958 | };
|
959 | LocalState.prototype.resolveField = function (field, isClientFieldDescendant, rootValue, execContext) {
|
960 | return tslib.__awaiter(this, void 0, void 0, function () {
|
961 | var variables, fieldName, aliasedFieldName, aliasUsed, defaultResult, resultPromise, resolverType, resolverMap, resolve;
|
962 | var _this = this;
|
963 | return tslib.__generator(this, function (_a) {
|
964 | if (!rootValue) {
|
965 | return [2 , null];
|
966 | }
|
967 | variables = execContext.variables;
|
968 | fieldName = field.name.value;
|
969 | aliasedFieldName = utilities.resultKeyNameFromField(field);
|
970 | aliasUsed = fieldName !== aliasedFieldName;
|
971 | defaultResult = rootValue[aliasedFieldName] || rootValue[fieldName];
|
972 | resultPromise = Promise.resolve(defaultResult);
|
973 | if (!execContext.onlyRunForcedResolvers ||
|
974 | this.shouldForceResolvers(field)) {
|
975 | resolverType = rootValue.__typename || execContext.defaultOperationType;
|
976 | resolverMap = this.resolvers && this.resolvers[resolverType];
|
977 | if (resolverMap) {
|
978 | resolve = resolverMap[aliasUsed ? fieldName : aliasedFieldName];
|
979 | if (resolve) {
|
980 | resultPromise = Promise.resolve(
|
981 | cache.cacheSlot.withValue(this.cache, resolve, [
|
982 | rootValue,
|
983 | utilities.argumentsObjectFromField(field, variables),
|
984 | execContext.context,
|
985 | { field: field, fragmentMap: execContext.fragmentMap },
|
986 | ]));
|
987 | }
|
988 | }
|
989 | }
|
990 | return [2 , resultPromise.then(function (result) {
|
991 | var _a, _b;
|
992 | if (result === void 0) { result = defaultResult; }
|
993 | if (field.directives) {
|
994 | field.directives.forEach(function (directive) {
|
995 | if (directive.name.value === "export" && directive.arguments) {
|
996 | directive.arguments.forEach(function (arg) {
|
997 | if (arg.name.value === "as" && arg.value.kind === "StringValue") {
|
998 | execContext.exportedVariables[arg.value.value] = result;
|
999 | }
|
1000 | });
|
1001 | }
|
1002 | });
|
1003 | }
|
1004 | if (!field.selectionSet) {
|
1005 | return result;
|
1006 | }
|
1007 | if (result == null) {
|
1008 | return result;
|
1009 | }
|
1010 | var isClientField = (_b = (_a = field.directives) === null || _a === void 0 ? void 0 : _a.some(function (d) { return d.name.value === "client"; })) !== null && _b !== void 0 ? _b : false;
|
1011 | if (Array.isArray(result)) {
|
1012 | return _this.resolveSubSelectedArray(field, isClientFieldDescendant || isClientField, result, execContext);
|
1013 | }
|
1014 | if (field.selectionSet) {
|
1015 | return _this.resolveSelectionSet(field.selectionSet, isClientFieldDescendant || isClientField, result, execContext);
|
1016 | }
|
1017 | })];
|
1018 | });
|
1019 | });
|
1020 | };
|
1021 | LocalState.prototype.resolveSubSelectedArray = function (field, isClientFieldDescendant, result, execContext) {
|
1022 | var _this = this;
|
1023 | return Promise.all(result.map(function (item) {
|
1024 | if (item === null) {
|
1025 | return null;
|
1026 | }
|
1027 | if (Array.isArray(item)) {
|
1028 | return _this.resolveSubSelectedArray(field, isClientFieldDescendant, item, execContext);
|
1029 | }
|
1030 | if (field.selectionSet) {
|
1031 | return _this.resolveSelectionSet(field.selectionSet, isClientFieldDescendant, item, execContext);
|
1032 | }
|
1033 | }));
|
1034 | };
|
1035 | LocalState.prototype.collectSelectionsToResolve = function (mainDefinition, fragmentMap) {
|
1036 | var isSingleASTNode = function (node) { return !Array.isArray(node); };
|
1037 | var selectionsToResolveCache = this.selectionsToResolveCache;
|
1038 | function collectByDefinition(definitionNode) {
|
1039 | if (!selectionsToResolveCache.has(definitionNode)) {
|
1040 | var matches_1 = new Set();
|
1041 | selectionsToResolveCache.set(definitionNode, matches_1);
|
1042 | graphql.visit(definitionNode, {
|
1043 | Directive: function (node, _, __, ___, ancestors) {
|
1044 | if (node.name.value === "client") {
|
1045 | ancestors.forEach(function (node) {
|
1046 | if (isSingleASTNode(node) && graphql.isSelectionNode(node)) {
|
1047 | matches_1.add(node);
|
1048 | }
|
1049 | });
|
1050 | }
|
1051 | },
|
1052 | FragmentSpread: function (spread, _, __, ___, ancestors) {
|
1053 | var fragment = fragmentMap[spread.name.value];
|
1054 | globals.invariant(fragment, 19, spread.name.value);
|
1055 | var fragmentSelections = collectByDefinition(fragment);
|
1056 | if (fragmentSelections.size > 0) {
|
1057 | ancestors.forEach(function (node) {
|
1058 | if (isSingleASTNode(node) && graphql.isSelectionNode(node)) {
|
1059 | matches_1.add(node);
|
1060 | }
|
1061 | });
|
1062 | matches_1.add(spread);
|
1063 | fragmentSelections.forEach(function (selection) {
|
1064 | matches_1.add(selection);
|
1065 | });
|
1066 | }
|
1067 | },
|
1068 | });
|
1069 | }
|
1070 | return selectionsToResolveCache.get(definitionNode);
|
1071 | }
|
1072 | return collectByDefinition(mainDefinition);
|
1073 | };
|
1074 | return LocalState;
|
1075 | }());
|
1076 |
|
1077 | var destructiveMethodCounts = new (utilities.canUseWeakMap ? WeakMap : Map)();
|
1078 | function wrapDestructiveCacheMethod(cache, methodName) {
|
1079 | var original = cache[methodName];
|
1080 | if (typeof original === "function") {
|
1081 | cache[methodName] = function () {
|
1082 | destructiveMethodCounts.set(cache,
|
1083 | (destructiveMethodCounts.get(cache) + 1) % 1e15);
|
1084 | return original.apply(this, arguments);
|
1085 | };
|
1086 | }
|
1087 | }
|
1088 | function cancelNotifyTimeout(info) {
|
1089 | if (info["notifyTimeout"]) {
|
1090 | clearTimeout(info["notifyTimeout"]);
|
1091 | info["notifyTimeout"] = void 0;
|
1092 | }
|
1093 | }
|
1094 | var QueryInfo = (function () {
|
1095 | function QueryInfo(queryManager, queryId) {
|
1096 | if (queryId === void 0) { queryId = queryManager.generateQueryId(); }
|
1097 | this.queryId = queryId;
|
1098 | this.listeners = new Set();
|
1099 | this.document = null;
|
1100 | this.lastRequestId = 1;
|
1101 | this.stopped = false;
|
1102 | this.dirty = false;
|
1103 | this.observableQuery = null;
|
1104 | var cache = (this.cache = queryManager.cache);
|
1105 | if (!destructiveMethodCounts.has(cache)) {
|
1106 | destructiveMethodCounts.set(cache, 0);
|
1107 | wrapDestructiveCacheMethod(cache, "evict");
|
1108 | wrapDestructiveCacheMethod(cache, "modify");
|
1109 | wrapDestructiveCacheMethod(cache, "reset");
|
1110 | }
|
1111 | }
|
1112 | QueryInfo.prototype.init = function (query) {
|
1113 | var networkStatus = query.networkStatus || exports.NetworkStatus.loading;
|
1114 | if (this.variables &&
|
1115 | this.networkStatus !== exports.NetworkStatus.loading &&
|
1116 | !equal.equal(this.variables, query.variables)) {
|
1117 | networkStatus = exports.NetworkStatus.setVariables;
|
1118 | }
|
1119 | if (!equal.equal(query.variables, this.variables)) {
|
1120 | this.lastDiff = void 0;
|
1121 | }
|
1122 | Object.assign(this, {
|
1123 | document: query.document,
|
1124 | variables: query.variables,
|
1125 | networkError: null,
|
1126 | graphQLErrors: this.graphQLErrors || [],
|
1127 | networkStatus: networkStatus,
|
1128 | });
|
1129 | if (query.observableQuery) {
|
1130 | this.setObservableQuery(query.observableQuery);
|
1131 | }
|
1132 | if (query.lastRequestId) {
|
1133 | this.lastRequestId = query.lastRequestId;
|
1134 | }
|
1135 | return this;
|
1136 | };
|
1137 | QueryInfo.prototype.reset = function () {
|
1138 | cancelNotifyTimeout(this);
|
1139 | this.dirty = false;
|
1140 | };
|
1141 | QueryInfo.prototype.resetDiff = function () {
|
1142 | this.lastDiff = void 0;
|
1143 | };
|
1144 | QueryInfo.prototype.getDiff = function () {
|
1145 | var options = this.getDiffOptions();
|
1146 | if (this.lastDiff && equal.equal(options, this.lastDiff.options)) {
|
1147 | return this.lastDiff.diff;
|
1148 | }
|
1149 | this.updateWatch(this.variables);
|
1150 | var oq = this.observableQuery;
|
1151 | if (oq && oq.options.fetchPolicy === "no-cache") {
|
1152 | return { complete: false };
|
1153 | }
|
1154 | var diff = this.cache.diff(options);
|
1155 | this.updateLastDiff(diff, options);
|
1156 | return diff;
|
1157 | };
|
1158 | QueryInfo.prototype.updateLastDiff = function (diff, options) {
|
1159 | this.lastDiff =
|
1160 | diff ?
|
1161 | {
|
1162 | diff: diff,
|
1163 | options: options || this.getDiffOptions(),
|
1164 | }
|
1165 | : void 0;
|
1166 | };
|
1167 | QueryInfo.prototype.getDiffOptions = function (variables) {
|
1168 | var _a;
|
1169 | if (variables === void 0) { variables = this.variables; }
|
1170 | return {
|
1171 | query: this.document,
|
1172 | variables: variables,
|
1173 | returnPartialData: true,
|
1174 | optimistic: true,
|
1175 | canonizeResults: (_a = this.observableQuery) === null || _a === void 0 ? void 0 : _a.options.canonizeResults,
|
1176 | };
|
1177 | };
|
1178 | QueryInfo.prototype.setDiff = function (diff) {
|
1179 | var _this = this;
|
1180 | var _a;
|
1181 | var oldDiff = this.lastDiff && this.lastDiff.diff;
|
1182 | if (diff &&
|
1183 | !diff.complete &&
|
1184 | !((_a = this.observableQuery) === null || _a === void 0 ? void 0 : _a.options.returnPartialData) &&
|
1185 | !(oldDiff && oldDiff.complete)) {
|
1186 | return;
|
1187 | }
|
1188 | this.updateLastDiff(diff);
|
1189 | if (!this.dirty && !equal.equal(oldDiff && oldDiff.result, diff && diff.result)) {
|
1190 | this.dirty = true;
|
1191 | if (!this.notifyTimeout) {
|
1192 | this.notifyTimeout = setTimeout(function () { return _this.notify(); }, 0);
|
1193 | }
|
1194 | }
|
1195 | };
|
1196 | QueryInfo.prototype.setObservableQuery = function (oq) {
|
1197 | var _this = this;
|
1198 | if (oq === this.observableQuery)
|
1199 | return;
|
1200 | if (this.oqListener) {
|
1201 | this.listeners.delete(this.oqListener);
|
1202 | }
|
1203 | this.observableQuery = oq;
|
1204 | if (oq) {
|
1205 | oq["queryInfo"] = this;
|
1206 | this.listeners.add((this.oqListener = function () {
|
1207 | var diff = _this.getDiff();
|
1208 | if (diff.fromOptimisticTransaction) {
|
1209 | oq["observe"]();
|
1210 | }
|
1211 | else {
|
1212 | reobserveCacheFirst(oq);
|
1213 | }
|
1214 | }));
|
1215 | }
|
1216 | else {
|
1217 | delete this.oqListener;
|
1218 | }
|
1219 | };
|
1220 | QueryInfo.prototype.notify = function () {
|
1221 | var _this = this;
|
1222 | cancelNotifyTimeout(this);
|
1223 | if (this.shouldNotify()) {
|
1224 | this.listeners.forEach(function (listener) { return listener(_this); });
|
1225 | }
|
1226 | this.dirty = false;
|
1227 | };
|
1228 | QueryInfo.prototype.shouldNotify = function () {
|
1229 | if (!this.dirty || !this.listeners.size) {
|
1230 | return false;
|
1231 | }
|
1232 | if (isNetworkRequestInFlight(this.networkStatus) && this.observableQuery) {
|
1233 | var fetchPolicy = this.observableQuery.options.fetchPolicy;
|
1234 | if (fetchPolicy !== "cache-only" && fetchPolicy !== "cache-and-network") {
|
1235 | return false;
|
1236 | }
|
1237 | }
|
1238 | return true;
|
1239 | };
|
1240 | QueryInfo.prototype.stop = function () {
|
1241 | if (!this.stopped) {
|
1242 | this.stopped = true;
|
1243 | this.reset();
|
1244 | this.cancel();
|
1245 | this.cancel = QueryInfo.prototype.cancel;
|
1246 | var oq = this.observableQuery;
|
1247 | if (oq)
|
1248 | oq.stopPolling();
|
1249 | }
|
1250 | };
|
1251 | QueryInfo.prototype.cancel = function () { };
|
1252 | QueryInfo.prototype.updateWatch = function (variables) {
|
1253 | var _this = this;
|
1254 | if (variables === void 0) { variables = this.variables; }
|
1255 | var oq = this.observableQuery;
|
1256 | if (oq && oq.options.fetchPolicy === "no-cache") {
|
1257 | return;
|
1258 | }
|
1259 | var watchOptions = tslib.__assign(tslib.__assign({}, this.getDiffOptions(variables)), { watcher: this, callback: function (diff) { return _this.setDiff(diff); } });
|
1260 | if (!this.lastWatch || !equal.equal(watchOptions, this.lastWatch)) {
|
1261 | this.cancel();
|
1262 | this.cancel = this.cache.watch((this.lastWatch = watchOptions));
|
1263 | }
|
1264 | };
|
1265 | QueryInfo.prototype.resetLastWrite = function () {
|
1266 | this.lastWrite = void 0;
|
1267 | };
|
1268 | QueryInfo.prototype.shouldWrite = function (result, variables) {
|
1269 | var lastWrite = this.lastWrite;
|
1270 | return !(lastWrite &&
|
1271 | lastWrite.dmCount === destructiveMethodCounts.get(this.cache) &&
|
1272 | equal.equal(variables, lastWrite.variables) &&
|
1273 | equal.equal(result.data, lastWrite.result.data));
|
1274 | };
|
1275 | QueryInfo.prototype.markResult = function (result, document, options, cacheWriteBehavior) {
|
1276 | var _this = this;
|
1277 | var merger = new utilities.DeepMerger();
|
1278 | var graphQLErrors = utilities.isNonEmptyArray(result.errors) ? result.errors.slice(0) : [];
|
1279 | this.reset();
|
1280 | if ("incremental" in result && utilities.isNonEmptyArray(result.incremental)) {
|
1281 | var mergedData = utilities.mergeIncrementalData(this.getDiff().result, result);
|
1282 | result.data = mergedData;
|
1283 | }
|
1284 | else if ("hasNext" in result && result.hasNext) {
|
1285 | var diff = this.getDiff();
|
1286 | result.data = merger.merge(diff.result, result.data);
|
1287 | }
|
1288 | this.graphQLErrors = graphQLErrors;
|
1289 | if (options.fetchPolicy === "no-cache") {
|
1290 | this.updateLastDiff({ result: result.data, complete: true }, this.getDiffOptions(options.variables));
|
1291 | }
|
1292 | else if (cacheWriteBehavior !== 0 ) {
|
1293 | if (shouldWriteResult(result, options.errorPolicy)) {
|
1294 | this.cache.performTransaction(function (cache) {
|
1295 | if (_this.shouldWrite(result, options.variables)) {
|
1296 | cache.writeQuery({
|
1297 | query: document,
|
1298 | data: result.data,
|
1299 | variables: options.variables,
|
1300 | overwrite: cacheWriteBehavior === 1 ,
|
1301 | });
|
1302 | _this.lastWrite = {
|
1303 | result: result,
|
1304 | variables: options.variables,
|
1305 | dmCount: destructiveMethodCounts.get(_this.cache),
|
1306 | };
|
1307 | }
|
1308 | else {
|
1309 | if (_this.lastDiff && _this.lastDiff.diff.complete) {
|
1310 | result.data = _this.lastDiff.diff.result;
|
1311 | return;
|
1312 | }
|
1313 | }
|
1314 | var diffOptions = _this.getDiffOptions(options.variables);
|
1315 | var diff = cache.diff(diffOptions);
|
1316 | if (!_this.stopped && equal.equal(_this.variables, options.variables)) {
|
1317 | _this.updateWatch(options.variables);
|
1318 | }
|
1319 | _this.updateLastDiff(diff, diffOptions);
|
1320 | if (diff.complete) {
|
1321 | result.data = diff.result;
|
1322 | }
|
1323 | });
|
1324 | }
|
1325 | else {
|
1326 | this.lastWrite = void 0;
|
1327 | }
|
1328 | }
|
1329 | };
|
1330 | QueryInfo.prototype.markReady = function () {
|
1331 | this.networkError = null;
|
1332 | return (this.networkStatus = exports.NetworkStatus.ready);
|
1333 | };
|
1334 | QueryInfo.prototype.markError = function (error) {
|
1335 | this.networkStatus = exports.NetworkStatus.error;
|
1336 | this.lastWrite = void 0;
|
1337 | this.reset();
|
1338 | if (error.graphQLErrors) {
|
1339 | this.graphQLErrors = error.graphQLErrors;
|
1340 | }
|
1341 | if (error.networkError) {
|
1342 | this.networkError = error.networkError;
|
1343 | }
|
1344 | return error;
|
1345 | };
|
1346 | return QueryInfo;
|
1347 | }());
|
1348 | function shouldWriteResult(result, errorPolicy) {
|
1349 | if (errorPolicy === void 0) { errorPolicy = "none"; }
|
1350 | var ignoreErrors = errorPolicy === "ignore" || errorPolicy === "all";
|
1351 | var writeWithErrors = !utilities.graphQLResultHasError(result);
|
1352 | if (!writeWithErrors && ignoreErrors && result.data) {
|
1353 | writeWithErrors = true;
|
1354 | }
|
1355 | return writeWithErrors;
|
1356 | }
|
1357 |
|
1358 | var hasOwnProperty = Object.prototype.hasOwnProperty;
|
1359 | var IGNORE = Object.create(null);
|
1360 | var QueryManager = (function () {
|
1361 | function QueryManager(_a) {
|
1362 | var cache = _a.cache, link = _a.link, defaultOptions = _a.defaultOptions, documentTransform = _a.documentTransform, _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, _e = _a.assumeImmutableResults, assumeImmutableResults = _e === void 0 ? !!cache.assumeImmutableResults : _e, defaultContext = _a.defaultContext;
|
1363 | var _this = this;
|
1364 | this.clientAwareness = {};
|
1365 | this.queries = new Map();
|
1366 | this.fetchCancelFns = new Map();
|
1367 | this.transformCache = new utilities.AutoCleanedWeakCache(utilities.cacheSizes["queryManager.getDocumentInfo"] ||
|
1368 | 2000 );
|
1369 | this.queryIdCounter = 1;
|
1370 | this.requestIdCounter = 1;
|
1371 | this.mutationIdCounter = 1;
|
1372 | this.inFlightLinkObservables = new trie.Trie(false);
|
1373 | var defaultDocumentTransform = new utilities.DocumentTransform(function (document) { return _this.cache.transformDocument(document); },
|
1374 | { cache: false });
|
1375 | this.cache = cache;
|
1376 | this.link = link;
|
1377 | this.defaultOptions = defaultOptions || Object.create(null);
|
1378 | this.queryDeduplication = queryDeduplication;
|
1379 | this.clientAwareness = clientAwareness;
|
1380 | this.localState = localState || new LocalState({ cache: cache });
|
1381 | this.ssrMode = ssrMode;
|
1382 | this.assumeImmutableResults = assumeImmutableResults;
|
1383 | this.documentTransform =
|
1384 | documentTransform ?
|
1385 | defaultDocumentTransform
|
1386 | .concat(documentTransform)
|
1387 | .concat(defaultDocumentTransform)
|
1388 | : defaultDocumentTransform;
|
1389 | this.defaultContext = defaultContext || Object.create(null);
|
1390 | if ((this.onBroadcast = onBroadcast)) {
|
1391 | this.mutationStore = Object.create(null);
|
1392 | }
|
1393 | }
|
1394 | QueryManager.prototype.stop = function () {
|
1395 | var _this = this;
|
1396 | this.queries.forEach(function (_info, queryId) {
|
1397 | _this.stopQueryNoBroadcast(queryId);
|
1398 | });
|
1399 | this.cancelPendingFetches(globals.newInvariantError(25));
|
1400 | };
|
1401 | QueryManager.prototype.cancelPendingFetches = function (error) {
|
1402 | this.fetchCancelFns.forEach(function (cancel) { return cancel(error); });
|
1403 | this.fetchCancelFns.clear();
|
1404 | };
|
1405 | QueryManager.prototype.mutate = function (_a) {
|
1406 | return tslib.__awaiter(this, arguments, void 0, function (_b) {
|
1407 | var mutationId, hasClientExports, mutationStoreValue, isOptimistic, self;
|
1408 | var _c, _d;
|
1409 | var mutation = _b.mutation, variables = _b.variables, optimisticResponse = _b.optimisticResponse, updateQueries = _b.updateQueries, _e = _b.refetchQueries, refetchQueries = _e === void 0 ? [] : _e, _f = _b.awaitRefetchQueries, awaitRefetchQueries = _f === void 0 ? false : _f, updateWithProxyFn = _b.update, onQueryUpdated = _b.onQueryUpdated, _g = _b.fetchPolicy, fetchPolicy = _g === void 0 ? ((_c = this.defaultOptions.mutate) === null || _c === void 0 ? void 0 : _c.fetchPolicy) || "network-only" : _g, _h = _b.errorPolicy, errorPolicy = _h === void 0 ? ((_d = this.defaultOptions.mutate) === null || _d === void 0 ? void 0 : _d.errorPolicy) || "none" : _h, keepRootFields = _b.keepRootFields, context = _b.context;
|
1410 | return tslib.__generator(this, function (_j) {
|
1411 | switch (_j.label) {
|
1412 | case 0:
|
1413 | globals.invariant(mutation, 26);
|
1414 | globals.invariant(fetchPolicy === "network-only" || fetchPolicy === "no-cache", 27);
|
1415 | mutationId = this.generateMutationId();
|
1416 | mutation = this.cache.transformForLink(this.transform(mutation));
|
1417 | hasClientExports = this.getDocumentInfo(mutation).hasClientExports;
|
1418 | variables = this.getVariables(mutation, variables);
|
1419 | if (!hasClientExports) return [3 , 2];
|
1420 | return [4 , this.localState.addExportedVariables(mutation, variables, context)];
|
1421 | case 1:
|
1422 | variables = (_j.sent());
|
1423 | _j.label = 2;
|
1424 | case 2:
|
1425 | mutationStoreValue = this.mutationStore &&
|
1426 | (this.mutationStore[mutationId] = {
|
1427 | mutation: mutation,
|
1428 | variables: variables,
|
1429 | loading: true,
|
1430 | error: null,
|
1431 | });
|
1432 | isOptimistic = optimisticResponse &&
|
1433 | this.markMutationOptimistic(optimisticResponse, {
|
1434 | mutationId: mutationId,
|
1435 | document: mutation,
|
1436 | variables: variables,
|
1437 | fetchPolicy: fetchPolicy,
|
1438 | errorPolicy: errorPolicy,
|
1439 | context: context,
|
1440 | updateQueries: updateQueries,
|
1441 | update: updateWithProxyFn,
|
1442 | keepRootFields: keepRootFields,
|
1443 | });
|
1444 | this.broadcastQueries();
|
1445 | self = this;
|
1446 | return [2 , new Promise(function (resolve, reject) {
|
1447 | return utilities.asyncMap(self.getObservableFromLink(mutation, tslib.__assign(tslib.__assign({}, context), { optimisticResponse: isOptimistic ? optimisticResponse : void 0 }), variables, false), function (result) {
|
1448 | if (utilities.graphQLResultHasError(result) && errorPolicy === "none") {
|
1449 | throw new errors.ApolloError({
|
1450 | graphQLErrors: utilities.getGraphQLErrorsFromResult(result),
|
1451 | });
|
1452 | }
|
1453 | if (mutationStoreValue) {
|
1454 | mutationStoreValue.loading = false;
|
1455 | mutationStoreValue.error = null;
|
1456 | }
|
1457 | var storeResult = tslib.__assign({}, result);
|
1458 | if (typeof refetchQueries === "function") {
|
1459 | refetchQueries = refetchQueries(storeResult);
|
1460 | }
|
1461 | if (errorPolicy === "ignore" && utilities.graphQLResultHasError(storeResult)) {
|
1462 | delete storeResult.errors;
|
1463 | }
|
1464 | return self.markMutationResult({
|
1465 | mutationId: mutationId,
|
1466 | result: storeResult,
|
1467 | document: mutation,
|
1468 | variables: variables,
|
1469 | fetchPolicy: fetchPolicy,
|
1470 | errorPolicy: errorPolicy,
|
1471 | context: context,
|
1472 | update: updateWithProxyFn,
|
1473 | updateQueries: updateQueries,
|
1474 | awaitRefetchQueries: awaitRefetchQueries,
|
1475 | refetchQueries: refetchQueries,
|
1476 | removeOptimistic: isOptimistic ? mutationId : void 0,
|
1477 | onQueryUpdated: onQueryUpdated,
|
1478 | keepRootFields: keepRootFields,
|
1479 | });
|
1480 | }).subscribe({
|
1481 | next: function (storeResult) {
|
1482 | self.broadcastQueries();
|
1483 | if (!("hasNext" in storeResult) || storeResult.hasNext === false) {
|
1484 | resolve(storeResult);
|
1485 | }
|
1486 | },
|
1487 | error: function (err) {
|
1488 | if (mutationStoreValue) {
|
1489 | mutationStoreValue.loading = false;
|
1490 | mutationStoreValue.error = err;
|
1491 | }
|
1492 | if (isOptimistic) {
|
1493 | self.cache.removeOptimistic(mutationId);
|
1494 | }
|
1495 | self.broadcastQueries();
|
1496 | reject(err instanceof errors.ApolloError ? err : (new errors.ApolloError({
|
1497 | networkError: err,
|
1498 | })));
|
1499 | },
|
1500 | });
|
1501 | })];
|
1502 | }
|
1503 | });
|
1504 | });
|
1505 | };
|
1506 | QueryManager.prototype.markMutationResult = function (mutation, cache) {
|
1507 | var _this = this;
|
1508 | if (cache === void 0) { cache = this.cache; }
|
1509 | var result = mutation.result;
|
1510 | var cacheWrites = [];
|
1511 | var skipCache = mutation.fetchPolicy === "no-cache";
|
1512 | if (!skipCache && shouldWriteResult(result, mutation.errorPolicy)) {
|
1513 | if (!utilities.isExecutionPatchIncrementalResult(result)) {
|
1514 | cacheWrites.push({
|
1515 | result: result.data,
|
1516 | dataId: "ROOT_MUTATION",
|
1517 | query: mutation.document,
|
1518 | variables: mutation.variables,
|
1519 | });
|
1520 | }
|
1521 | if (utilities.isExecutionPatchIncrementalResult(result) &&
|
1522 | utilities.isNonEmptyArray(result.incremental)) {
|
1523 | var diff = cache.diff({
|
1524 | id: "ROOT_MUTATION",
|
1525 | query: this.getDocumentInfo(mutation.document).asQuery,
|
1526 | variables: mutation.variables,
|
1527 | optimistic: false,
|
1528 | returnPartialData: true,
|
1529 | });
|
1530 | var mergedData = void 0;
|
1531 | if (diff.result) {
|
1532 | mergedData = mergeIncrementalData(diff.result, result);
|
1533 | }
|
1534 | if (typeof mergedData !== "undefined") {
|
1535 | result.data = mergedData;
|
1536 | cacheWrites.push({
|
1537 | result: mergedData,
|
1538 | dataId: "ROOT_MUTATION",
|
1539 | query: mutation.document,
|
1540 | variables: mutation.variables,
|
1541 | });
|
1542 | }
|
1543 | }
|
1544 | var updateQueries_1 = mutation.updateQueries;
|
1545 | if (updateQueries_1) {
|
1546 | this.queries.forEach(function (_a, queryId) {
|
1547 | var observableQuery = _a.observableQuery;
|
1548 | var queryName = observableQuery && observableQuery.queryName;
|
1549 | if (!queryName || !hasOwnProperty.call(updateQueries_1, queryName)) {
|
1550 | return;
|
1551 | }
|
1552 | var updater = updateQueries_1[queryName];
|
1553 | var _b = _this.queries.get(queryId), document = _b.document, variables = _b.variables;
|
1554 | var _c = cache.diff({
|
1555 | query: document,
|
1556 | variables: variables,
|
1557 | returnPartialData: true,
|
1558 | optimistic: false,
|
1559 | }), currentQueryResult = _c.result, complete = _c.complete;
|
1560 | if (complete && currentQueryResult) {
|
1561 | var nextQueryResult = updater(currentQueryResult, {
|
1562 | mutationResult: result,
|
1563 | queryName: (document && utilities.getOperationName(document)) || void 0,
|
1564 | queryVariables: variables,
|
1565 | });
|
1566 | if (nextQueryResult) {
|
1567 | cacheWrites.push({
|
1568 | result: nextQueryResult,
|
1569 | dataId: "ROOT_QUERY",
|
1570 | query: document,
|
1571 | variables: variables,
|
1572 | });
|
1573 | }
|
1574 | }
|
1575 | });
|
1576 | }
|
1577 | }
|
1578 | if (cacheWrites.length > 0 ||
|
1579 | (mutation.refetchQueries || "").length > 0 ||
|
1580 | mutation.update ||
|
1581 | mutation.onQueryUpdated ||
|
1582 | mutation.removeOptimistic) {
|
1583 | var results_1 = [];
|
1584 | this.refetchQueries({
|
1585 | updateCache: function (cache) {
|
1586 | if (!skipCache) {
|
1587 | cacheWrites.forEach(function (write) { return cache.write(write); });
|
1588 | }
|
1589 | var update = mutation.update;
|
1590 | var isFinalResult = !utilities.isExecutionPatchResult(result) ||
|
1591 | (utilities.isExecutionPatchIncrementalResult(result) && !result.hasNext);
|
1592 | if (update) {
|
1593 | if (!skipCache) {
|
1594 | var diff = cache.diff({
|
1595 | id: "ROOT_MUTATION",
|
1596 | query: _this.getDocumentInfo(mutation.document).asQuery,
|
1597 | variables: mutation.variables,
|
1598 | optimistic: false,
|
1599 | returnPartialData: true,
|
1600 | });
|
1601 | if (diff.complete) {
|
1602 | result = tslib.__assign(tslib.__assign({}, result), { data: diff.result });
|
1603 | if ("incremental" in result) {
|
1604 | delete result.incremental;
|
1605 | }
|
1606 | if ("hasNext" in result) {
|
1607 | delete result.hasNext;
|
1608 | }
|
1609 | }
|
1610 | }
|
1611 | if (isFinalResult) {
|
1612 | update(cache, result, {
|
1613 | context: mutation.context,
|
1614 | variables: mutation.variables,
|
1615 | });
|
1616 | }
|
1617 | }
|
1618 | if (!skipCache && !mutation.keepRootFields && isFinalResult) {
|
1619 | cache.modify({
|
1620 | id: "ROOT_MUTATION",
|
1621 | fields: function (value, _a) {
|
1622 | var fieldName = _a.fieldName, DELETE = _a.DELETE;
|
1623 | return fieldName === "__typename" ? value : DELETE;
|
1624 | },
|
1625 | });
|
1626 | }
|
1627 | },
|
1628 | include: mutation.refetchQueries,
|
1629 | optimistic: false,
|
1630 | removeOptimistic: mutation.removeOptimistic,
|
1631 | onQueryUpdated: mutation.onQueryUpdated || null,
|
1632 | }).forEach(function (result) { return results_1.push(result); });
|
1633 | if (mutation.awaitRefetchQueries || mutation.onQueryUpdated) {
|
1634 | return Promise.all(results_1).then(function () { return result; });
|
1635 | }
|
1636 | }
|
1637 | return Promise.resolve(result);
|
1638 | };
|
1639 | QueryManager.prototype.markMutationOptimistic = function (optimisticResponse, mutation) {
|
1640 | var _this = this;
|
1641 | var data = typeof optimisticResponse === "function" ?
|
1642 | optimisticResponse(mutation.variables, { IGNORE: IGNORE })
|
1643 | : optimisticResponse;
|
1644 | if (data === IGNORE) {
|
1645 | return false;
|
1646 | }
|
1647 | this.cache.recordOptimisticTransaction(function (cache) {
|
1648 | try {
|
1649 | _this.markMutationResult(tslib.__assign(tslib.__assign({}, mutation), { result: { data: data } }), cache);
|
1650 | }
|
1651 | catch (error) {
|
1652 | globalThis.__DEV__ !== false && globals.invariant.error(error);
|
1653 | }
|
1654 | }, mutation.mutationId);
|
1655 | return true;
|
1656 | };
|
1657 | QueryManager.prototype.fetchQuery = function (queryId, options, networkStatus) {
|
1658 | return this.fetchConcastWithInfo(queryId, options, networkStatus).concast
|
1659 | .promise;
|
1660 | };
|
1661 | QueryManager.prototype.getQueryStore = function () {
|
1662 | var store = Object.create(null);
|
1663 | this.queries.forEach(function (info, queryId) {
|
1664 | store[queryId] = {
|
1665 | variables: info.variables,
|
1666 | networkStatus: info.networkStatus,
|
1667 | networkError: info.networkError,
|
1668 | graphQLErrors: info.graphQLErrors,
|
1669 | };
|
1670 | });
|
1671 | return store;
|
1672 | };
|
1673 | QueryManager.prototype.resetErrors = function (queryId) {
|
1674 | var queryInfo = this.queries.get(queryId);
|
1675 | if (queryInfo) {
|
1676 | queryInfo.networkError = undefined;
|
1677 | queryInfo.graphQLErrors = [];
|
1678 | }
|
1679 | };
|
1680 | QueryManager.prototype.transform = function (document) {
|
1681 | return this.documentTransform.transformDocument(document);
|
1682 | };
|
1683 | QueryManager.prototype.getDocumentInfo = function (document) {
|
1684 | var transformCache = this.transformCache;
|
1685 | if (!transformCache.has(document)) {
|
1686 | var cacheEntry = {
|
1687 | hasClientExports: utilities.hasClientExports(document),
|
1688 | hasForcedResolvers: this.localState.shouldForceResolvers(document),
|
1689 | hasNonreactiveDirective: utilities.hasDirectives(["nonreactive"], document),
|
1690 | clientQuery: this.localState.clientQuery(document),
|
1691 | serverQuery: utilities.removeDirectivesFromDocument([
|
1692 | { name: "client", remove: true },
|
1693 | { name: "connection" },
|
1694 | { name: "nonreactive" },
|
1695 | ], document),
|
1696 | defaultVars: utilities.getDefaultValues(utilities.getOperationDefinition(document)),
|
1697 | asQuery: tslib.__assign(tslib.__assign({}, document), { definitions: document.definitions.map(function (def) {
|
1698 | if (def.kind === "OperationDefinition" &&
|
1699 | def.operation !== "query") {
|
1700 | return tslib.__assign(tslib.__assign({}, def), { operation: "query" });
|
1701 | }
|
1702 | return def;
|
1703 | }) }),
|
1704 | };
|
1705 | transformCache.set(document, cacheEntry);
|
1706 | }
|
1707 | return transformCache.get(document);
|
1708 | };
|
1709 | QueryManager.prototype.getVariables = function (document, variables) {
|
1710 | return tslib.__assign(tslib.__assign({}, this.getDocumentInfo(document).defaultVars), variables);
|
1711 | };
|
1712 | QueryManager.prototype.watchQuery = function (options) {
|
1713 | var query = this.transform(options.query);
|
1714 | options = tslib.__assign(tslib.__assign({}, options), { variables: this.getVariables(query, options.variables) });
|
1715 | if (typeof options.notifyOnNetworkStatusChange === "undefined") {
|
1716 | options.notifyOnNetworkStatusChange = false;
|
1717 | }
|
1718 | var queryInfo = new QueryInfo(this);
|
1719 | var observable = new ObservableQuery({
|
1720 | queryManager: this,
|
1721 | queryInfo: queryInfo,
|
1722 | options: options,
|
1723 | });
|
1724 | observable["lastQuery"] = query;
|
1725 | this.queries.set(observable.queryId, queryInfo);
|
1726 | queryInfo.init({
|
1727 | document: query,
|
1728 | observableQuery: observable,
|
1729 | variables: observable.variables,
|
1730 | });
|
1731 | return observable;
|
1732 | };
|
1733 | QueryManager.prototype.query = function (options, queryId) {
|
1734 | var _this = this;
|
1735 | if (queryId === void 0) { queryId = this.generateQueryId(); }
|
1736 | globals.invariant(options.query, 28);
|
1737 | globals.invariant(options.query.kind === "Document", 29);
|
1738 | globals.invariant(!options.returnPartialData, 30);
|
1739 | globals.invariant(!options.pollInterval, 31);
|
1740 | return this.fetchQuery(queryId, tslib.__assign(tslib.__assign({}, options), { query: this.transform(options.query) })).finally(function () { return _this.stopQuery(queryId); });
|
1741 | };
|
1742 | QueryManager.prototype.generateQueryId = function () {
|
1743 | return String(this.queryIdCounter++);
|
1744 | };
|
1745 | QueryManager.prototype.generateRequestId = function () {
|
1746 | return this.requestIdCounter++;
|
1747 | };
|
1748 | QueryManager.prototype.generateMutationId = function () {
|
1749 | return String(this.mutationIdCounter++);
|
1750 | };
|
1751 | QueryManager.prototype.stopQueryInStore = function (queryId) {
|
1752 | this.stopQueryInStoreNoBroadcast(queryId);
|
1753 | this.broadcastQueries();
|
1754 | };
|
1755 | QueryManager.prototype.stopQueryInStoreNoBroadcast = function (queryId) {
|
1756 | var queryInfo = this.queries.get(queryId);
|
1757 | if (queryInfo)
|
1758 | queryInfo.stop();
|
1759 | };
|
1760 | QueryManager.prototype.clearStore = function (options) {
|
1761 | if (options === void 0) { options = {
|
1762 | discardWatches: true,
|
1763 | }; }
|
1764 | this.cancelPendingFetches(globals.newInvariantError(32));
|
1765 | this.queries.forEach(function (queryInfo) {
|
1766 | if (queryInfo.observableQuery) {
|
1767 | queryInfo.networkStatus = exports.NetworkStatus.loading;
|
1768 | }
|
1769 | else {
|
1770 | queryInfo.stop();
|
1771 | }
|
1772 | });
|
1773 | if (this.mutationStore) {
|
1774 | this.mutationStore = Object.create(null);
|
1775 | }
|
1776 | return this.cache.reset(options);
|
1777 | };
|
1778 | QueryManager.prototype.getObservableQueries = function (include) {
|
1779 | var _this = this;
|
1780 | if (include === void 0) { include = "active"; }
|
1781 | var queries = new Map();
|
1782 | var queryNamesAndDocs = new Map();
|
1783 | var legacyQueryOptions = new Set();
|
1784 | if (Array.isArray(include)) {
|
1785 | include.forEach(function (desc) {
|
1786 | if (typeof desc === "string") {
|
1787 | queryNamesAndDocs.set(desc, false);
|
1788 | }
|
1789 | else if (utilities.isDocumentNode(desc)) {
|
1790 | queryNamesAndDocs.set(_this.transform(desc), false);
|
1791 | }
|
1792 | else if (utilities.isNonNullObject(desc) && desc.query) {
|
1793 | legacyQueryOptions.add(desc);
|
1794 | }
|
1795 | });
|
1796 | }
|
1797 | this.queries.forEach(function (_a, queryId) {
|
1798 | var oq = _a.observableQuery, document = _a.document;
|
1799 | if (oq) {
|
1800 | if (include === "all") {
|
1801 | queries.set(queryId, oq);
|
1802 | return;
|
1803 | }
|
1804 | var queryName = oq.queryName, fetchPolicy = oq.options.fetchPolicy;
|
1805 | if (fetchPolicy === "standby" ||
|
1806 | (include === "active" && !oq.hasObservers())) {
|
1807 | return;
|
1808 | }
|
1809 | if (include === "active" ||
|
1810 | (queryName && queryNamesAndDocs.has(queryName)) ||
|
1811 | (document && queryNamesAndDocs.has(document))) {
|
1812 | queries.set(queryId, oq);
|
1813 | if (queryName)
|
1814 | queryNamesAndDocs.set(queryName, true);
|
1815 | if (document)
|
1816 | queryNamesAndDocs.set(document, true);
|
1817 | }
|
1818 | }
|
1819 | });
|
1820 | if (legacyQueryOptions.size) {
|
1821 | legacyQueryOptions.forEach(function (options) {
|
1822 | var queryId = utilities.makeUniqueId("legacyOneTimeQuery");
|
1823 | var queryInfo = _this.getQuery(queryId).init({
|
1824 | document: options.query,
|
1825 | variables: options.variables,
|
1826 | });
|
1827 | var oq = new ObservableQuery({
|
1828 | queryManager: _this,
|
1829 | queryInfo: queryInfo,
|
1830 | options: tslib.__assign(tslib.__assign({}, options), { fetchPolicy: "network-only" }),
|
1831 | });
|
1832 | globals.invariant(oq.queryId === queryId);
|
1833 | queryInfo.setObservableQuery(oq);
|
1834 | queries.set(queryId, oq);
|
1835 | });
|
1836 | }
|
1837 | if (globalThis.__DEV__ !== false && queryNamesAndDocs.size) {
|
1838 | queryNamesAndDocs.forEach(function (included, nameOrDoc) {
|
1839 | if (!included) {
|
1840 | globalThis.__DEV__ !== false && globals.invariant.warn(typeof nameOrDoc === "string" ? 33 : 34, nameOrDoc);
|
1841 | }
|
1842 | });
|
1843 | }
|
1844 | return queries;
|
1845 | };
|
1846 | QueryManager.prototype.reFetchObservableQueries = function (includeStandby) {
|
1847 | var _this = this;
|
1848 | if (includeStandby === void 0) { includeStandby = false; }
|
1849 | var observableQueryPromises = [];
|
1850 | this.getObservableQueries(includeStandby ? "all" : "active").forEach(function (observableQuery, queryId) {
|
1851 | var fetchPolicy = observableQuery.options.fetchPolicy;
|
1852 | observableQuery.resetLastResults();
|
1853 | if (includeStandby ||
|
1854 | (fetchPolicy !== "standby" && fetchPolicy !== "cache-only")) {
|
1855 | observableQueryPromises.push(observableQuery.refetch());
|
1856 | }
|
1857 | _this.getQuery(queryId).setDiff(null);
|
1858 | });
|
1859 | this.broadcastQueries();
|
1860 | return Promise.all(observableQueryPromises);
|
1861 | };
|
1862 | QueryManager.prototype.setObservableQuery = function (observableQuery) {
|
1863 | this.getQuery(observableQuery.queryId).setObservableQuery(observableQuery);
|
1864 | };
|
1865 | QueryManager.prototype.startGraphQLSubscription = function (_a) {
|
1866 | var _this = this;
|
1867 | var query = _a.query, fetchPolicy = _a.fetchPolicy, _b = _a.errorPolicy, errorPolicy = _b === void 0 ? "none" : _b, variables = _a.variables, _c = _a.context, context = _c === void 0 ? {} : _c;
|
1868 | query = this.transform(query);
|
1869 | variables = this.getVariables(query, variables);
|
1870 | var makeObservable = function (variables) {
|
1871 | return _this.getObservableFromLink(query, context, variables).map(function (result) {
|
1872 | if (fetchPolicy !== "no-cache") {
|
1873 | if (shouldWriteResult(result, errorPolicy)) {
|
1874 | _this.cache.write({
|
1875 | query: query,
|
1876 | result: result.data,
|
1877 | dataId: "ROOT_SUBSCRIPTION",
|
1878 | variables: variables,
|
1879 | });
|
1880 | }
|
1881 | _this.broadcastQueries();
|
1882 | }
|
1883 | var hasErrors = utilities.graphQLResultHasError(result);
|
1884 | var hasProtocolErrors = errors.graphQLResultHasProtocolErrors(result);
|
1885 | if (hasErrors || hasProtocolErrors) {
|
1886 | var errors$1 = {};
|
1887 | if (hasErrors) {
|
1888 | errors$1.graphQLErrors = result.errors;
|
1889 | }
|
1890 | if (hasProtocolErrors) {
|
1891 | errors$1.protocolErrors = result.extensions[errors.PROTOCOL_ERRORS_SYMBOL];
|
1892 | }
|
1893 | if (errorPolicy === "none" || hasProtocolErrors) {
|
1894 | throw new errors.ApolloError(errors$1);
|
1895 | }
|
1896 | }
|
1897 | if (errorPolicy === "ignore") {
|
1898 | delete result.errors;
|
1899 | }
|
1900 | return result;
|
1901 | });
|
1902 | };
|
1903 | if (this.getDocumentInfo(query).hasClientExports) {
|
1904 | var observablePromise_1 = this.localState
|
1905 | .addExportedVariables(query, variables, context)
|
1906 | .then(makeObservable);
|
1907 | return new utilities.Observable(function (observer) {
|
1908 | var sub = null;
|
1909 | observablePromise_1.then(function (observable) { return (sub = observable.subscribe(observer)); }, observer.error);
|
1910 | return function () { return sub && sub.unsubscribe(); };
|
1911 | });
|
1912 | }
|
1913 | return makeObservable(variables);
|
1914 | };
|
1915 | QueryManager.prototype.stopQuery = function (queryId) {
|
1916 | this.stopQueryNoBroadcast(queryId);
|
1917 | this.broadcastQueries();
|
1918 | };
|
1919 | QueryManager.prototype.stopQueryNoBroadcast = function (queryId) {
|
1920 | this.stopQueryInStoreNoBroadcast(queryId);
|
1921 | this.removeQuery(queryId);
|
1922 | };
|
1923 | QueryManager.prototype.removeQuery = function (queryId) {
|
1924 | this.fetchCancelFns.delete(queryId);
|
1925 | if (this.queries.has(queryId)) {
|
1926 | this.getQuery(queryId).stop();
|
1927 | this.queries.delete(queryId);
|
1928 | }
|
1929 | };
|
1930 | QueryManager.prototype.broadcastQueries = function () {
|
1931 | if (this.onBroadcast)
|
1932 | this.onBroadcast();
|
1933 | this.queries.forEach(function (info) { return info.notify(); });
|
1934 | };
|
1935 | QueryManager.prototype.getLocalState = function () {
|
1936 | return this.localState;
|
1937 | };
|
1938 | QueryManager.prototype.getObservableFromLink = function (query, context, variables,
|
1939 | deduplication) {
|
1940 | var _this = this;
|
1941 | var _a;
|
1942 | if (deduplication === void 0) { deduplication = (_a = context === null || context === void 0 ? void 0 : context.queryDeduplication) !== null && _a !== void 0 ? _a : this.queryDeduplication; }
|
1943 | var observable;
|
1944 | var _b = this.getDocumentInfo(query), serverQuery = _b.serverQuery, clientQuery = _b.clientQuery;
|
1945 | if (serverQuery) {
|
1946 | var _c = this, inFlightLinkObservables_1 = _c.inFlightLinkObservables, link = _c.link;
|
1947 | var operation = {
|
1948 | query: serverQuery,
|
1949 | variables: variables,
|
1950 | operationName: utilities.getOperationName(serverQuery) || void 0,
|
1951 | context: this.prepareContext(tslib.__assign(tslib.__assign({}, context), { forceFetch: !deduplication })),
|
1952 | };
|
1953 | context = operation.context;
|
1954 | if (deduplication) {
|
1955 | var printedServerQuery_1 = utilities.print(serverQuery);
|
1956 | var varJson_1 = cache.canonicalStringify(variables);
|
1957 | var entry = inFlightLinkObservables_1.lookup(printedServerQuery_1, varJson_1);
|
1958 | observable = entry.observable;
|
1959 | if (!observable) {
|
1960 | var concast = new utilities.Concast([
|
1961 | core.execute(link, operation),
|
1962 | ]);
|
1963 | observable = entry.observable = concast;
|
1964 | concast.beforeNext(function () {
|
1965 | inFlightLinkObservables_1.remove(printedServerQuery_1, varJson_1);
|
1966 | });
|
1967 | }
|
1968 | }
|
1969 | else {
|
1970 | observable = new utilities.Concast([
|
1971 | core.execute(link, operation),
|
1972 | ]);
|
1973 | }
|
1974 | }
|
1975 | else {
|
1976 | observable = new utilities.Concast([utilities.Observable.of({ data: {} })]);
|
1977 | context = this.prepareContext(context);
|
1978 | }
|
1979 | if (clientQuery) {
|
1980 | observable = utilities.asyncMap(observable, function (result) {
|
1981 | return _this.localState.runResolvers({
|
1982 | document: clientQuery,
|
1983 | remoteResult: result,
|
1984 | context: context,
|
1985 | variables: variables,
|
1986 | });
|
1987 | });
|
1988 | }
|
1989 | return observable;
|
1990 | };
|
1991 | QueryManager.prototype.getResultsFromLink = function (queryInfo, cacheWriteBehavior, options) {
|
1992 | var requestId = (queryInfo.lastRequestId = this.generateRequestId());
|
1993 | var linkDocument = this.cache.transformForLink(options.query);
|
1994 | return utilities.asyncMap(this.getObservableFromLink(linkDocument, options.context, options.variables), function (result) {
|
1995 | var graphQLErrors = utilities.getGraphQLErrorsFromResult(result);
|
1996 | var hasErrors = graphQLErrors.length > 0;
|
1997 | if (requestId >= queryInfo.lastRequestId) {
|
1998 | if (hasErrors && options.errorPolicy === "none") {
|
1999 | throw queryInfo.markError(new errors.ApolloError({
|
2000 | graphQLErrors: graphQLErrors,
|
2001 | }));
|
2002 | }
|
2003 | queryInfo.markResult(result, linkDocument, options, cacheWriteBehavior);
|
2004 | queryInfo.markReady();
|
2005 | }
|
2006 | var aqr = {
|
2007 | data: result.data,
|
2008 | loading: false,
|
2009 | networkStatus: exports.NetworkStatus.ready,
|
2010 | };
|
2011 | if (hasErrors && options.errorPolicy !== "ignore") {
|
2012 | aqr.errors = graphQLErrors;
|
2013 | aqr.networkStatus = exports.NetworkStatus.error;
|
2014 | }
|
2015 | return aqr;
|
2016 | }, function (networkError) {
|
2017 | var error = errors.isApolloError(networkError) ? networkError : (new errors.ApolloError({ networkError: networkError }));
|
2018 | if (requestId >= queryInfo.lastRequestId) {
|
2019 | queryInfo.markError(error);
|
2020 | }
|
2021 | throw error;
|
2022 | });
|
2023 | };
|
2024 | QueryManager.prototype.fetchConcastWithInfo = function (queryId, options,
|
2025 | networkStatus, query) {
|
2026 | var _this = this;
|
2027 | if (networkStatus === void 0) { networkStatus = exports.NetworkStatus.loading; }
|
2028 | if (query === void 0) { query = options.query; }
|
2029 | var variables = this.getVariables(query, options.variables);
|
2030 | var queryInfo = this.getQuery(queryId);
|
2031 | var defaults = this.defaultOptions.watchQuery;
|
2032 | 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;
|
2033 | var normalized = Object.assign({}, options, {
|
2034 | query: query,
|
2035 | variables: variables,
|
2036 | fetchPolicy: fetchPolicy,
|
2037 | errorPolicy: errorPolicy,
|
2038 | returnPartialData: returnPartialData,
|
2039 | notifyOnNetworkStatusChange: notifyOnNetworkStatusChange,
|
2040 | context: context,
|
2041 | });
|
2042 | var fromVariables = function (variables) {
|
2043 | normalized.variables = variables;
|
2044 | var sourcesWithInfo = _this.fetchQueryByPolicy(queryInfo, normalized, networkStatus);
|
2045 | if (
|
2046 | normalized.fetchPolicy !== "standby" &&
|
2047 | sourcesWithInfo.sources.length > 0 &&
|
2048 | queryInfo.observableQuery) {
|
2049 | queryInfo.observableQuery["applyNextFetchPolicy"]("after-fetch", options);
|
2050 | }
|
2051 | return sourcesWithInfo;
|
2052 | };
|
2053 | var cleanupCancelFn = function () { return _this.fetchCancelFns.delete(queryId); };
|
2054 | this.fetchCancelFns.set(queryId, function (reason) {
|
2055 | cleanupCancelFn();
|
2056 | setTimeout(function () { return concast.cancel(reason); });
|
2057 | });
|
2058 | var concast, containsDataFromLink;
|
2059 | if (this.getDocumentInfo(normalized.query).hasClientExports) {
|
2060 | concast = new utilities.Concast(this.localState
|
2061 | .addExportedVariables(normalized.query, normalized.variables, normalized.context)
|
2062 | .then(fromVariables)
|
2063 | .then(function (sourcesWithInfo) { return sourcesWithInfo.sources; }));
|
2064 | containsDataFromLink = true;
|
2065 | }
|
2066 | else {
|
2067 | var sourcesWithInfo = fromVariables(normalized.variables);
|
2068 | containsDataFromLink = sourcesWithInfo.fromLink;
|
2069 | concast = new utilities.Concast(sourcesWithInfo.sources);
|
2070 | }
|
2071 | concast.promise.then(cleanupCancelFn, cleanupCancelFn);
|
2072 | return {
|
2073 | concast: concast,
|
2074 | fromLink: containsDataFromLink,
|
2075 | };
|
2076 | };
|
2077 | QueryManager.prototype.refetchQueries = function (_a) {
|
2078 | var _this = this;
|
2079 | 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;
|
2080 | var includedQueriesById = new Map();
|
2081 | if (include) {
|
2082 | this.getObservableQueries(include).forEach(function (oq, queryId) {
|
2083 | includedQueriesById.set(queryId, {
|
2084 | oq: oq,
|
2085 | lastDiff: _this.getQuery(queryId).getDiff(),
|
2086 | });
|
2087 | });
|
2088 | }
|
2089 | var results = new Map();
|
2090 | if (updateCache) {
|
2091 | this.cache.batch({
|
2092 | update: updateCache,
|
2093 | optimistic: (optimistic && removeOptimistic) || false,
|
2094 | removeOptimistic: removeOptimistic,
|
2095 | onWatchUpdated: function (watch, diff, lastDiff) {
|
2096 | var oq = watch.watcher instanceof QueryInfo && watch.watcher.observableQuery;
|
2097 | if (oq) {
|
2098 | if (onQueryUpdated) {
|
2099 | includedQueriesById.delete(oq.queryId);
|
2100 | var result = onQueryUpdated(oq, diff, lastDiff);
|
2101 | if (result === true) {
|
2102 | result = oq.refetch();
|
2103 | }
|
2104 | if (result !== false) {
|
2105 | results.set(oq, result);
|
2106 | }
|
2107 | return result;
|
2108 | }
|
2109 | if (onQueryUpdated !== null) {
|
2110 | includedQueriesById.set(oq.queryId, { oq: oq, lastDiff: lastDiff, diff: diff });
|
2111 | }
|
2112 | }
|
2113 | },
|
2114 | });
|
2115 | }
|
2116 | if (includedQueriesById.size) {
|
2117 | includedQueriesById.forEach(function (_a, queryId) {
|
2118 | var oq = _a.oq, lastDiff = _a.lastDiff, diff = _a.diff;
|
2119 | var result;
|
2120 | if (onQueryUpdated) {
|
2121 | if (!diff) {
|
2122 | var info = oq["queryInfo"];
|
2123 | info.reset();
|
2124 | diff = info.getDiff();
|
2125 | }
|
2126 | result = onQueryUpdated(oq, diff, lastDiff);
|
2127 | }
|
2128 | if (!onQueryUpdated || result === true) {
|
2129 | result = oq.refetch();
|
2130 | }
|
2131 | if (result !== false) {
|
2132 | results.set(oq, result);
|
2133 | }
|
2134 | if (queryId.indexOf("legacyOneTimeQuery") >= 0) {
|
2135 | _this.stopQueryNoBroadcast(queryId);
|
2136 | }
|
2137 | });
|
2138 | }
|
2139 | if (removeOptimistic) {
|
2140 | this.cache.removeOptimistic(removeOptimistic);
|
2141 | }
|
2142 | return results;
|
2143 | };
|
2144 | QueryManager.prototype.fetchQueryByPolicy = function (queryInfo, _a,
|
2145 | networkStatus) {
|
2146 | var _this = this;
|
2147 | 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;
|
2148 | var oldNetworkStatus = queryInfo.networkStatus;
|
2149 | queryInfo.init({
|
2150 | document: query,
|
2151 | variables: variables,
|
2152 | networkStatus: networkStatus,
|
2153 | });
|
2154 | var readCache = function () { return queryInfo.getDiff(); };
|
2155 | var resultsFromCache = function (diff, networkStatus) {
|
2156 | if (networkStatus === void 0) { networkStatus = queryInfo.networkStatus || exports.NetworkStatus.loading; }
|
2157 | var data = diff.result;
|
2158 | if (globalThis.__DEV__ !== false && !returnPartialData && !equal.equal(data, {})) {
|
2159 | logMissingFieldErrors(diff.missing);
|
2160 | }
|
2161 | var fromData = function (data) {
|
2162 | return utilities.Observable.of(tslib.__assign({ data: data, loading: isNetworkRequestInFlight(networkStatus), networkStatus: networkStatus }, (diff.complete ? null : { partial: true })));
|
2163 | };
|
2164 | if (data && _this.getDocumentInfo(query).hasForcedResolvers) {
|
2165 | return _this.localState
|
2166 | .runResolvers({
|
2167 | document: query,
|
2168 | remoteResult: { data: data },
|
2169 | context: context,
|
2170 | variables: variables,
|
2171 | onlyRunForcedResolvers: true,
|
2172 | })
|
2173 | .then(function (resolved) { return fromData(resolved.data || void 0); });
|
2174 | }
|
2175 | if (errorPolicy === "none" &&
|
2176 | networkStatus === exports.NetworkStatus.refetch &&
|
2177 | Array.isArray(diff.missing)) {
|
2178 | return fromData(void 0);
|
2179 | }
|
2180 | return fromData(data);
|
2181 | };
|
2182 | var cacheWriteBehavior = fetchPolicy === "no-cache" ? 0
|
2183 | : (networkStatus === exports.NetworkStatus.refetch &&
|
2184 | refetchWritePolicy !== "merge") ?
|
2185 | 1
|
2186 | : 2 ;
|
2187 | var resultsFromLink = function () {
|
2188 | return _this.getResultsFromLink(queryInfo, cacheWriteBehavior, {
|
2189 | query: query,
|
2190 | variables: variables,
|
2191 | context: context,
|
2192 | fetchPolicy: fetchPolicy,
|
2193 | errorPolicy: errorPolicy,
|
2194 | });
|
2195 | };
|
2196 | var shouldNotify = notifyOnNetworkStatusChange &&
|
2197 | typeof oldNetworkStatus === "number" &&
|
2198 | oldNetworkStatus !== networkStatus &&
|
2199 | isNetworkRequestInFlight(networkStatus);
|
2200 | switch (fetchPolicy) {
|
2201 | default:
|
2202 | case "cache-first": {
|
2203 | var diff = readCache();
|
2204 | if (diff.complete) {
|
2205 | return {
|
2206 | fromLink: false,
|
2207 | sources: [resultsFromCache(diff, queryInfo.markReady())],
|
2208 | };
|
2209 | }
|
2210 | if (returnPartialData || shouldNotify) {
|
2211 | return {
|
2212 | fromLink: true,
|
2213 | sources: [resultsFromCache(diff), resultsFromLink()],
|
2214 | };
|
2215 | }
|
2216 | return { fromLink: true, sources: [resultsFromLink()] };
|
2217 | }
|
2218 | case "cache-and-network": {
|
2219 | var diff = readCache();
|
2220 | if (diff.complete || returnPartialData || shouldNotify) {
|
2221 | return {
|
2222 | fromLink: true,
|
2223 | sources: [resultsFromCache(diff), resultsFromLink()],
|
2224 | };
|
2225 | }
|
2226 | return { fromLink: true, sources: [resultsFromLink()] };
|
2227 | }
|
2228 | case "cache-only":
|
2229 | return {
|
2230 | fromLink: false,
|
2231 | sources: [resultsFromCache(readCache(), queryInfo.markReady())],
|
2232 | };
|
2233 | case "network-only":
|
2234 | if (shouldNotify) {
|
2235 | return {
|
2236 | fromLink: true,
|
2237 | sources: [resultsFromCache(readCache()), resultsFromLink()],
|
2238 | };
|
2239 | }
|
2240 | return { fromLink: true, sources: [resultsFromLink()] };
|
2241 | case "no-cache":
|
2242 | if (shouldNotify) {
|
2243 | return {
|
2244 | fromLink: true,
|
2245 | sources: [resultsFromCache(queryInfo.getDiff()), resultsFromLink()],
|
2246 | };
|
2247 | }
|
2248 | return { fromLink: true, sources: [resultsFromLink()] };
|
2249 | case "standby":
|
2250 | return { fromLink: false, sources: [] };
|
2251 | }
|
2252 | };
|
2253 | QueryManager.prototype.getQuery = function (queryId) {
|
2254 | if (queryId && !this.queries.has(queryId)) {
|
2255 | this.queries.set(queryId, new QueryInfo(this, queryId));
|
2256 | }
|
2257 | return this.queries.get(queryId);
|
2258 | };
|
2259 | QueryManager.prototype.prepareContext = function (context) {
|
2260 | if (context === void 0) { context = {}; }
|
2261 | var newContext = this.localState.prepareContext(context);
|
2262 | return tslib.__assign(tslib.__assign(tslib.__assign({}, this.defaultContext), newContext), { clientAwareness: this.clientAwareness });
|
2263 | };
|
2264 | return QueryManager;
|
2265 | }());
|
2266 |
|
2267 | var cacheSizeSymbol = Symbol.for("apollo.cacheSize");
|
2268 | var cacheSizes = tslib.__assign({}, globals.global[cacheSizeSymbol]);
|
2269 |
|
2270 | var globalCaches = {};
|
2271 | var getApolloClientMemoryInternals = globalThis.__DEV__ !== false ?
|
2272 | _getApolloClientMemoryInternals
|
2273 | : undefined;
|
2274 | function getCurrentCacheSizes() {
|
2275 | var defaults = {
|
2276 | parser: 1000 ,
|
2277 | canonicalStringify: 1000 ,
|
2278 | print: 2000 ,
|
2279 | "documentTransform.cache": 2000 ,
|
2280 | "queryManager.getDocumentInfo": 2000 ,
|
2281 | "PersistedQueryLink.persistedQueryHashes": 2000 ,
|
2282 | "fragmentRegistry.transform": 2000 ,
|
2283 | "fragmentRegistry.lookup": 1000 ,
|
2284 | "fragmentRegistry.findFragmentSpreads": 4000 ,
|
2285 | "cache.fragmentQueryDocuments": 1000 ,
|
2286 | "removeTypenameFromVariables.getVariableDefinitions": 2000 ,
|
2287 | "inMemoryCache.maybeBroadcastWatch": 5000 ,
|
2288 | "inMemoryCache.executeSelectionSet": 50000 ,
|
2289 | "inMemoryCache.executeSubSelectedArray": 10000 ,
|
2290 | };
|
2291 | return Object.fromEntries(Object.entries(defaults).map(function (_a) {
|
2292 | var k = _a[0], v = _a[1];
|
2293 | return [
|
2294 | k,
|
2295 | cacheSizes[k] || v,
|
2296 | ];
|
2297 | }));
|
2298 | }
|
2299 | function _getApolloClientMemoryInternals() {
|
2300 | var _a, _b, _c, _d, _e;
|
2301 | if (!(globalThis.__DEV__ !== false))
|
2302 | throw new Error("only supported in development mode");
|
2303 | return {
|
2304 | limits: getCurrentCacheSizes(),
|
2305 | sizes: tslib.__assign({ print: (_a = globalCaches.print) === null || _a === void 0 ? void 0 : _a.call(globalCaches), parser: (_b = globalCaches.parser) === null || _b === void 0 ? void 0 : _b.call(globalCaches), canonicalStringify: (_c = globalCaches.canonicalStringify) === null || _c === void 0 ? void 0 : _c.call(globalCaches), links: linkInfo(this.link), queryManager: {
|
2306 | getDocumentInfo: this["queryManager"]["transformCache"].size,
|
2307 | documentTransforms: transformInfo(this["queryManager"].documentTransform),
|
2308 | } }, (_e = (_d = this.cache).getMemoryInternals) === null || _e === void 0 ? void 0 : _e.call(_d)),
|
2309 | };
|
2310 | }
|
2311 | function isWrapper(f) {
|
2312 | return !!f && "dirtyKey" in f;
|
2313 | }
|
2314 | function getWrapperInformation(f) {
|
2315 | return isWrapper(f) ? f.size : undefined;
|
2316 | }
|
2317 | function isDefined(value) {
|
2318 | return value != null;
|
2319 | }
|
2320 | function transformInfo(transform) {
|
2321 | return recurseTransformInfo(transform).map(function (cache) { return ({ cache: cache }); });
|
2322 | }
|
2323 | function recurseTransformInfo(transform) {
|
2324 | return transform ?
|
2325 | tslib.__spreadArray(tslib.__spreadArray([
|
2326 | getWrapperInformation(transform === null || transform === void 0 ? void 0 : transform["performWork"])
|
2327 | ], recurseTransformInfo(transform === null || transform === void 0 ? void 0 : transform["left"]), true), recurseTransformInfo(transform === null || transform === void 0 ? void 0 : transform["right"]), true).filter(isDefined)
|
2328 | : [];
|
2329 | }
|
2330 | function linkInfo(link) {
|
2331 | var _a;
|
2332 | return link ?
|
2333 | tslib.__spreadArray(tslib.__spreadArray([
|
2334 | (_a = link === null || link === void 0 ? void 0 : link.getMemoryInternals) === null || _a === void 0 ? void 0 : _a.call(link)
|
2335 | ], linkInfo(link === null || link === void 0 ? void 0 : link.left), true), linkInfo(link === null || link === void 0 ? void 0 : link.right), true).filter(isDefined)
|
2336 | : [];
|
2337 | }
|
2338 |
|
2339 | var hasSuggestedDevtools = false;
|
2340 | var ApolloClient = (function () {
|
2341 | function ApolloClient(options) {
|
2342 | var _this = this;
|
2343 | this.resetStoreCallbacks = [];
|
2344 | this.clearStoreCallbacks = [];
|
2345 | if (!options.cache) {
|
2346 | throw globals.newInvariantError(15);
|
2347 | }
|
2348 | var uri = options.uri, credentials = options.credentials, headers = options.headers, cache = options.cache, documentTransform = options.documentTransform, _a = options.ssrMode, ssrMode = _a === void 0 ? false : _a, _b = options.ssrForceFetchDelay, ssrForceFetchDelay = _b === void 0 ? 0 : _b,
|
2349 | _c = options.connectToDevTools,
|
2350 | connectToDevTools = _c === void 0 ? typeof window === "object" &&
|
2351 | !window.__APOLLO_CLIENT__ &&
|
2352 | globalThis.__DEV__ !== false : _c, _d = options.queryDeduplication, queryDeduplication = _d === void 0 ? true : _d, defaultOptions = options.defaultOptions, defaultContext = options.defaultContext, _e = options.assumeImmutableResults, assumeImmutableResults = _e === void 0 ? cache.assumeImmutableResults : _e, resolvers = options.resolvers, typeDefs = options.typeDefs, fragmentMatcher = options.fragmentMatcher, clientAwarenessName = options.name, clientAwarenessVersion = options.version;
|
2353 | var link = options.link;
|
2354 | if (!link) {
|
2355 | link =
|
2356 | uri ? new http.HttpLink({ uri: uri, credentials: credentials, headers: headers }) : core.ApolloLink.empty();
|
2357 | }
|
2358 | this.link = link;
|
2359 | this.cache = cache;
|
2360 | this.disableNetworkFetches = ssrMode || ssrForceFetchDelay > 0;
|
2361 | this.queryDeduplication = queryDeduplication;
|
2362 | this.defaultOptions = defaultOptions || Object.create(null);
|
2363 | this.typeDefs = typeDefs;
|
2364 | if (ssrForceFetchDelay) {
|
2365 | setTimeout(function () { return (_this.disableNetworkFetches = false); }, ssrForceFetchDelay);
|
2366 | }
|
2367 | this.watchQuery = this.watchQuery.bind(this);
|
2368 | this.query = this.query.bind(this);
|
2369 | this.mutate = this.mutate.bind(this);
|
2370 | this.resetStore = this.resetStore.bind(this);
|
2371 | this.reFetchObservableQueries = this.reFetchObservableQueries.bind(this);
|
2372 | this.version = version;
|
2373 | this.localState = new LocalState({
|
2374 | cache: cache,
|
2375 | client: this,
|
2376 | resolvers: resolvers,
|
2377 | fragmentMatcher: fragmentMatcher,
|
2378 | });
|
2379 | this.queryManager = new QueryManager({
|
2380 | cache: this.cache,
|
2381 | link: this.link,
|
2382 | defaultOptions: this.defaultOptions,
|
2383 | defaultContext: defaultContext,
|
2384 | documentTransform: documentTransform,
|
2385 | queryDeduplication: queryDeduplication,
|
2386 | ssrMode: ssrMode,
|
2387 | clientAwareness: {
|
2388 | name: clientAwarenessName,
|
2389 | version: clientAwarenessVersion,
|
2390 | },
|
2391 | localState: this.localState,
|
2392 | assumeImmutableResults: assumeImmutableResults,
|
2393 | onBroadcast: connectToDevTools ?
|
2394 | function () {
|
2395 | if (_this.devToolsHookCb) {
|
2396 | _this.devToolsHookCb({
|
2397 | action: {},
|
2398 | state: {
|
2399 | queries: _this.queryManager.getQueryStore(),
|
2400 | mutations: _this.queryManager.mutationStore || {},
|
2401 | },
|
2402 | dataWithOptimisticResults: _this.cache.extract(true),
|
2403 | });
|
2404 | }
|
2405 | }
|
2406 | : void 0,
|
2407 | });
|
2408 | if (connectToDevTools)
|
2409 | this.connectToDevTools();
|
2410 | }
|
2411 | ApolloClient.prototype.connectToDevTools = function () {
|
2412 | if (typeof window === "object") {
|
2413 | var windowWithDevTools = window;
|
2414 | var devtoolsSymbol = Symbol.for("apollo.devtools");
|
2415 | (windowWithDevTools[devtoolsSymbol] =
|
2416 | windowWithDevTools[devtoolsSymbol] || []).push(this);
|
2417 | windowWithDevTools.__APOLLO_CLIENT__ = this;
|
2418 | }
|
2419 | if (!hasSuggestedDevtools && globalThis.__DEV__ !== false) {
|
2420 | hasSuggestedDevtools = true;
|
2421 | setTimeout(function () {
|
2422 | if (typeof window !== "undefined" &&
|
2423 | window.document &&
|
2424 | window.top === window.self &&
|
2425 | !window.__APOLLO_DEVTOOLS_GLOBAL_HOOK__) {
|
2426 | var nav = window.navigator;
|
2427 | var ua = nav && nav.userAgent;
|
2428 | var url = void 0;
|
2429 | if (typeof ua === "string") {
|
2430 | if (ua.indexOf("Chrome/") > -1) {
|
2431 | url =
|
2432 | "https://chrome.google.com/webstore/detail/" +
|
2433 | "apollo-client-developer-t/jdkknkkbebbapilgoeccciglkfbmbnfm";
|
2434 | }
|
2435 | else if (ua.indexOf("Firefox/") > -1) {
|
2436 | url =
|
2437 | "https://addons.mozilla.org/en-US/firefox/addon/apollo-developer-tools/";
|
2438 | }
|
2439 | }
|
2440 | if (url) {
|
2441 | globalThis.__DEV__ !== false && globals.invariant.log("Download the Apollo DevTools for a better development " +
|
2442 | "experience: %s", url);
|
2443 | }
|
2444 | }
|
2445 | }, 10000);
|
2446 | }
|
2447 | };
|
2448 | Object.defineProperty(ApolloClient.prototype, "documentTransform", {
|
2449 | get: function () {
|
2450 | return this.queryManager.documentTransform;
|
2451 | },
|
2452 | enumerable: false,
|
2453 | configurable: true
|
2454 | });
|
2455 | ApolloClient.prototype.stop = function () {
|
2456 | this.queryManager.stop();
|
2457 | };
|
2458 | ApolloClient.prototype.watchQuery = function (options) {
|
2459 | if (this.defaultOptions.watchQuery) {
|
2460 | options = utilities.mergeOptions(this.defaultOptions.watchQuery, options);
|
2461 | }
|
2462 | if (this.disableNetworkFetches &&
|
2463 | (options.fetchPolicy === "network-only" ||
|
2464 | options.fetchPolicy === "cache-and-network")) {
|
2465 | options = tslib.__assign(tslib.__assign({}, options), { fetchPolicy: "cache-first" });
|
2466 | }
|
2467 | return this.queryManager.watchQuery(options);
|
2468 | };
|
2469 | ApolloClient.prototype.query = function (options) {
|
2470 | if (this.defaultOptions.query) {
|
2471 | options = utilities.mergeOptions(this.defaultOptions.query, options);
|
2472 | }
|
2473 | globals.invariant(options.fetchPolicy !== "cache-and-network", 16);
|
2474 | if (this.disableNetworkFetches && options.fetchPolicy === "network-only") {
|
2475 | options = tslib.__assign(tslib.__assign({}, options), { fetchPolicy: "cache-first" });
|
2476 | }
|
2477 | return this.queryManager.query(options);
|
2478 | };
|
2479 | ApolloClient.prototype.mutate = function (options) {
|
2480 | if (this.defaultOptions.mutate) {
|
2481 | options = utilities.mergeOptions(this.defaultOptions.mutate, options);
|
2482 | }
|
2483 | return this.queryManager.mutate(options);
|
2484 | };
|
2485 | ApolloClient.prototype.subscribe = function (options) {
|
2486 | return this.queryManager.startGraphQLSubscription(options);
|
2487 | };
|
2488 | ApolloClient.prototype.readQuery = function (options, optimistic) {
|
2489 | if (optimistic === void 0) { optimistic = false; }
|
2490 | return this.cache.readQuery(options, optimistic);
|
2491 | };
|
2492 | ApolloClient.prototype.readFragment = function (options, optimistic) {
|
2493 | if (optimistic === void 0) { optimistic = false; }
|
2494 | return this.cache.readFragment(options, optimistic);
|
2495 | };
|
2496 | ApolloClient.prototype.writeQuery = function (options) {
|
2497 | var ref = this.cache.writeQuery(options);
|
2498 | if (options.broadcast !== false) {
|
2499 | this.queryManager.broadcastQueries();
|
2500 | }
|
2501 | return ref;
|
2502 | };
|
2503 | ApolloClient.prototype.writeFragment = function (options) {
|
2504 | var ref = this.cache.writeFragment(options);
|
2505 | if (options.broadcast !== false) {
|
2506 | this.queryManager.broadcastQueries();
|
2507 | }
|
2508 | return ref;
|
2509 | };
|
2510 | ApolloClient.prototype.__actionHookForDevTools = function (cb) {
|
2511 | this.devToolsHookCb = cb;
|
2512 | };
|
2513 | ApolloClient.prototype.__requestRaw = function (payload) {
|
2514 | return core.execute(this.link, payload);
|
2515 | };
|
2516 | ApolloClient.prototype.resetStore = function () {
|
2517 | var _this = this;
|
2518 | return Promise.resolve()
|
2519 | .then(function () {
|
2520 | return _this.queryManager.clearStore({
|
2521 | discardWatches: false,
|
2522 | });
|
2523 | })
|
2524 | .then(function () { return Promise.all(_this.resetStoreCallbacks.map(function (fn) { return fn(); })); })
|
2525 | .then(function () { return _this.reFetchObservableQueries(); });
|
2526 | };
|
2527 | ApolloClient.prototype.clearStore = function () {
|
2528 | var _this = this;
|
2529 | return Promise.resolve()
|
2530 | .then(function () {
|
2531 | return _this.queryManager.clearStore({
|
2532 | discardWatches: true,
|
2533 | });
|
2534 | })
|
2535 | .then(function () { return Promise.all(_this.clearStoreCallbacks.map(function (fn) { return fn(); })); });
|
2536 | };
|
2537 | ApolloClient.prototype.onResetStore = function (cb) {
|
2538 | var _this = this;
|
2539 | this.resetStoreCallbacks.push(cb);
|
2540 | return function () {
|
2541 | _this.resetStoreCallbacks = _this.resetStoreCallbacks.filter(function (c) { return c !== cb; });
|
2542 | };
|
2543 | };
|
2544 | ApolloClient.prototype.onClearStore = function (cb) {
|
2545 | var _this = this;
|
2546 | this.clearStoreCallbacks.push(cb);
|
2547 | return function () {
|
2548 | _this.clearStoreCallbacks = _this.clearStoreCallbacks.filter(function (c) { return c !== cb; });
|
2549 | };
|
2550 | };
|
2551 | ApolloClient.prototype.reFetchObservableQueries = function (includeStandby) {
|
2552 | return this.queryManager.reFetchObservableQueries(includeStandby);
|
2553 | };
|
2554 | ApolloClient.prototype.refetchQueries = function (options) {
|
2555 | var map = this.queryManager.refetchQueries(options);
|
2556 | var queries = [];
|
2557 | var results = [];
|
2558 | map.forEach(function (result, obsQuery) {
|
2559 | queries.push(obsQuery);
|
2560 | results.push(result);
|
2561 | });
|
2562 | var result = Promise.all(results);
|
2563 | result.queries = queries;
|
2564 | result.results = results;
|
2565 | result.catch(function (error) {
|
2566 | globalThis.__DEV__ !== false && globals.invariant.debug(17, error);
|
2567 | });
|
2568 | return result;
|
2569 | };
|
2570 | ApolloClient.prototype.getObservableQueries = function (include) {
|
2571 | if (include === void 0) { include = "active"; }
|
2572 | return this.queryManager.getObservableQueries(include);
|
2573 | };
|
2574 | ApolloClient.prototype.extract = function (optimistic) {
|
2575 | return this.cache.extract(optimistic);
|
2576 | };
|
2577 | ApolloClient.prototype.restore = function (serializedState) {
|
2578 | return this.cache.restore(serializedState);
|
2579 | };
|
2580 | ApolloClient.prototype.addResolvers = function (resolvers) {
|
2581 | this.localState.addResolvers(resolvers);
|
2582 | };
|
2583 | ApolloClient.prototype.setResolvers = function (resolvers) {
|
2584 | this.localState.setResolvers(resolvers);
|
2585 | };
|
2586 | ApolloClient.prototype.getResolvers = function () {
|
2587 | return this.localState.getResolvers();
|
2588 | };
|
2589 | ApolloClient.prototype.setLocalStateFragmentMatcher = function (fragmentMatcher) {
|
2590 | this.localState.setFragmentMatcher(fragmentMatcher);
|
2591 | };
|
2592 | ApolloClient.prototype.setLink = function (newLink) {
|
2593 | this.link = this.queryManager.link = newLink;
|
2594 | };
|
2595 | Object.defineProperty(ApolloClient.prototype, "defaultContext", {
|
2596 | get: function () {
|
2597 | return this.queryManager.defaultContext;
|
2598 | },
|
2599 | enumerable: false,
|
2600 | configurable: true
|
2601 | });
|
2602 | return ApolloClient;
|
2603 | }());
|
2604 | if (globalThis.__DEV__ !== false) {
|
2605 | ApolloClient.prototype.getMemoryInternals = getApolloClientMemoryInternals;
|
2606 | }
|
2607 |
|
2608 | tsInvariant.setVerbosity(globalThis.__DEV__ !== false ? "log" : "silent");
|
2609 |
|
2610 | exports.DocumentTransform = utilities.DocumentTransform;
|
2611 | exports.Observable = utilities.Observable;
|
2612 | exports.isReference = utilities.isReference;
|
2613 | exports.makeReference = utilities.makeReference;
|
2614 | exports.mergeOptions = utilities.mergeOptions;
|
2615 | exports.ApolloCache = cache.ApolloCache;
|
2616 | exports.Cache = cache.Cache;
|
2617 | exports.InMemoryCache = cache.InMemoryCache;
|
2618 | exports.MissingFieldError = cache.MissingFieldError;
|
2619 | exports.defaultDataIdFromObject = cache.defaultDataIdFromObject;
|
2620 | exports.makeVar = cache.makeVar;
|
2621 | exports.ApolloError = errors.ApolloError;
|
2622 | exports.isApolloError = errors.isApolloError;
|
2623 | exports.fromError = utils.fromError;
|
2624 | exports.fromPromise = utils.fromPromise;
|
2625 | exports.throwServerError = utils.throwServerError;
|
2626 | exports.toPromise = utils.toPromise;
|
2627 | exports.setLogVerbosity = tsInvariant.setVerbosity;
|
2628 | exports.disableExperimentalFragmentVariables = graphqlTag.disableExperimentalFragmentVariables;
|
2629 | exports.disableFragmentWarnings = graphqlTag.disableFragmentWarnings;
|
2630 | exports.enableExperimentalFragmentVariables = graphqlTag.enableExperimentalFragmentVariables;
|
2631 | exports.gql = graphqlTag.gql;
|
2632 | exports.resetCaches = graphqlTag.resetCaches;
|
2633 | exports.ApolloClient = ApolloClient;
|
2634 | exports.ObservableQuery = ObservableQuery;
|
2635 | exports.isNetworkRequestSettled = isNetworkRequestSettled;
|
2636 | for (var k in core) {
|
2637 | if (k !== 'default' && !exports.hasOwnProperty(k)) exports[k] = core[k];
|
2638 | }
|
2639 | for (var k in http) {
|
2640 | if (k !== 'default' && !exports.hasOwnProperty(k)) exports[k] = http[k];
|
2641 | }
|
2642 |
|