UNPKG

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