@apollo/client 3.11.0-rc.0 → 3.11.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.changeset/breezy-deers-dream.md +5 -0
- package/.changeset/curly-vans-draw.md +5 -0
- package/.changeset/early-tips-vanish.md +5 -0
- package/.changeset/good-suns-happen.md +5 -0
- package/.changeset/hungry-rings-help.md +5 -0
- package/.changeset/pink-flowers-switch.md +5 -0
- package/.changeset/pre.json +7 -0
- package/.changeset/proud-humans-begin.md +5 -0
- package/CHANGELOG.md +22 -0
- package/README.md +5 -5
- package/apollo-client.cjs +1393 -1405
- package/apollo-client.cjs.map +1 -1
- package/apollo-client.min.cjs +1 -1
- package/cache/cache.cjs +2 -7
- package/cache/cache.cjs.map +1 -1
- package/cache/cache.cjs.native.js +2 -7
- package/cache/core/cache.d.ts +0 -11
- package/cache/core/cache.js +2 -7
- package/cache/core/cache.js.map +1 -1
- package/config/jest/areApolloErrorsEqual.d.ts +3 -0
- package/config/jest/areApolloErrorsEqual.js +23 -0
- package/config/jest/areApolloErrorsEqual.js.map +1 -0
- package/config/jest/areGraphQlErrorsEqual.d.ts +3 -0
- package/config/jest/areGraphQlErrorsEqual.js +7 -0
- package/config/jest/areGraphQlErrorsEqual.js.map +1 -0
- package/config/jest/setup.js +4 -0
- package/config/jest/setup.js.map +1 -1
- package/core/ApolloClient.js +1 -1
- package/core/ApolloClient.js.map +1 -1
- package/core/QueryManager.d.ts +15 -14
- package/core/QueryManager.js +12 -13
- package/core/QueryManager.js.map +1 -1
- package/core/core.cjs +806 -806
- package/core/core.cjs.map +1 -1
- package/core/core.cjs.native.js +806 -806
- package/core/watchQueryOptions.d.ts +1 -1
- package/core/watchQueryOptions.js.map +1 -1
- package/dev/dev.cjs +1 -1
- package/dev/dev.cjs.map +1 -1
- package/dev/dev.cjs.native.js +1 -1
- package/package.json +8 -5
- package/react/hooks/hooks.cjs +26 -33
- package/react/hooks/hooks.cjs.map +1 -1
- package/react/hooks/hooks.cjs.native.js +26 -33
- package/react/hooks/useQuery.d.ts +2 -5
- package/react/hooks/useQuery.js +42 -53
- package/react/hooks/useQuery.js.map +1 -1
- package/react/internal/internal.cjs +1 -1
- package/react/internal/internal.cjs.map +1 -1
- package/react/internal/internal.cjs.native.js +1 -1
- package/react/types/types.d.ts +6 -1
- package/react/types/types.js.map +1 -1
- package/testing/core/mocking/mockQueryManager.d.ts +15 -0
- package/testing/core/mocking/mockQueryManager.js +5 -2
- package/testing/core/mocking/mockQueryManager.js.map +1 -1
- package/testing/experimental/createSchemaFetch.js +5 -12
- package/testing/experimental/createSchemaFetch.js.map +1 -1
- package/testing/experimental/experimental.cjs +3 -5
- package/testing/experimental/experimental.cjs.map +1 -1
- package/testing/experimental/experimental.cjs.native.js +3 -5
- package/utilities/globals/globals.cjs +1 -1
- package/utilities/globals/globals.cjs.map +1 -1
- package/utilities/globals/globals.cjs.native.js +1 -1
- package/version.js +1 -1
package/apollo-client.cjs
CHANGED
|
@@ -9,8 +9,8 @@ var caches = require('@wry/caches');
|
|
|
9
9
|
var graphql = require('graphql');
|
|
10
10
|
var zenObservableTs = require('zen-observable-ts');
|
|
11
11
|
require('symbol-observable');
|
|
12
|
-
var optimism = require('optimism');
|
|
13
12
|
var trie = require('@wry/trie');
|
|
13
|
+
var optimism = require('optimism');
|
|
14
14
|
var graphqlTag = require('graphql-tag');
|
|
15
15
|
var React = require('rehackt');
|
|
16
16
|
|
|
@@ -31,7 +31,7 @@ function _interopNamespace(e) {
|
|
|
31
31
|
var equal__default = /*#__PURE__*/_interopDefaultLegacy(equal);
|
|
32
32
|
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
33
33
|
|
|
34
|
-
var version = "3.11.0-rc.
|
|
34
|
+
var version = "3.11.0-rc.2";
|
|
35
35
|
|
|
36
36
|
function maybe(thunk) {
|
|
37
37
|
try {
|
|
@@ -2502,14 +2502,9 @@ var ApolloCache = (function () {
|
|
|
2502
2502
|
};
|
|
2503
2503
|
ApolloCache.prototype.watchFragment = function (options) {
|
|
2504
2504
|
var _this = this;
|
|
2505
|
-
var fragment = options.fragment, fragmentName = options.fragmentName, from = options.from, _a = options.optimistic, optimistic = _a === void 0 ? true : _a;
|
|
2505
|
+
var fragment = options.fragment, fragmentName = options.fragmentName, from = options.from, _a = options.optimistic, optimistic = _a === void 0 ? true : _a, otherOptions = tslib.__rest(options, ["fragment", "fragmentName", "from", "optimistic"]);
|
|
2506
2506
|
var query = this.getFragmentDoc(fragment, fragmentName);
|
|
2507
|
-
var diffOptions = {
|
|
2508
|
-
returnPartialData: true,
|
|
2509
|
-
id: typeof from === "string" ? from : this.identify(from),
|
|
2510
|
-
query: query,
|
|
2511
|
-
optimistic: optimistic,
|
|
2512
|
-
};
|
|
2507
|
+
var diffOptions = tslib.__assign(tslib.__assign({}, otherOptions), { returnPartialData: true, id: typeof from === "string" ? from : this.identify(from), query: query, optimistic: optimistic });
|
|
2513
2508
|
var latestDiff;
|
|
2514
2509
|
return new zenObservableTs.Observable(function (observer) {
|
|
2515
2510
|
return _this.watch(tslib.__assign(tslib.__assign({}, diffOptions), { immediate: true, callback: function (diff) {
|
|
@@ -5456,1506 +5451,1506 @@ function skipCacheDataFor(fetchPolicy ) {
|
|
|
5456
5451
|
fetchPolicy === "standby");
|
|
5457
5452
|
}
|
|
5458
5453
|
|
|
5459
|
-
var
|
|
5460
|
-
|
|
5461
|
-
|
|
5462
|
-
|
|
5463
|
-
|
|
5464
|
-
|
|
5465
|
-
|
|
5454
|
+
var destructiveMethodCounts = new (canUseWeakMap ? WeakMap : Map)();
|
|
5455
|
+
function wrapDestructiveCacheMethod(cache, methodName) {
|
|
5456
|
+
var original = cache[methodName];
|
|
5457
|
+
if (typeof original === "function") {
|
|
5458
|
+
cache[methodName] = function () {
|
|
5459
|
+
destructiveMethodCounts.set(cache,
|
|
5460
|
+
(destructiveMethodCounts.get(cache) + 1) % 1e15);
|
|
5461
|
+
return original.apply(this, arguments);
|
|
5462
|
+
};
|
|
5463
|
+
}
|
|
5464
|
+
}
|
|
5465
|
+
function cancelNotifyTimeout(info) {
|
|
5466
|
+
if (info["notifyTimeout"]) {
|
|
5467
|
+
clearTimeout(info["notifyTimeout"]);
|
|
5468
|
+
info["notifyTimeout"] = void 0;
|
|
5469
|
+
}
|
|
5470
|
+
}
|
|
5471
|
+
var QueryInfo = (function () {
|
|
5472
|
+
function QueryInfo(queryManager, queryId) {
|
|
5473
|
+
if (queryId === void 0) { queryId = queryManager.generateQueryId(); }
|
|
5474
|
+
this.queryId = queryId;
|
|
5475
|
+
this.listeners = new Set();
|
|
5476
|
+
this.document = null;
|
|
5477
|
+
this.lastRequestId = 1;
|
|
5478
|
+
this.stopped = false;
|
|
5479
|
+
this.dirty = false;
|
|
5480
|
+
this.observableQuery = null;
|
|
5481
|
+
var cache = (this.cache = queryManager.cache);
|
|
5482
|
+
if (!destructiveMethodCounts.has(cache)) {
|
|
5483
|
+
destructiveMethodCounts.set(cache, 0);
|
|
5484
|
+
wrapDestructiveCacheMethod(cache, "evict");
|
|
5485
|
+
wrapDestructiveCacheMethod(cache, "modify");
|
|
5486
|
+
wrapDestructiveCacheMethod(cache, "reset");
|
|
5466
5487
|
}
|
|
5467
|
-
|
|
5468
|
-
|
|
5488
|
+
}
|
|
5489
|
+
QueryInfo.prototype.init = function (query) {
|
|
5490
|
+
var networkStatus = query.networkStatus || exports.NetworkStatus.loading;
|
|
5491
|
+
if (this.variables &&
|
|
5492
|
+
this.networkStatus !== exports.NetworkStatus.loading &&
|
|
5493
|
+
!equal.equal(this.variables, query.variables)) {
|
|
5494
|
+
networkStatus = exports.NetworkStatus.setVariables;
|
|
5469
5495
|
}
|
|
5470
|
-
if (
|
|
5471
|
-
this.
|
|
5496
|
+
if (!equal.equal(query.variables, this.variables)) {
|
|
5497
|
+
this.lastDiff = void 0;
|
|
5472
5498
|
}
|
|
5473
|
-
|
|
5474
|
-
|
|
5475
|
-
|
|
5476
|
-
|
|
5477
|
-
|
|
5478
|
-
|
|
5479
|
-
|
|
5480
|
-
|
|
5499
|
+
Object.assign(this, {
|
|
5500
|
+
document: query.document,
|
|
5501
|
+
variables: query.variables,
|
|
5502
|
+
networkError: null,
|
|
5503
|
+
graphQLErrors: this.graphQLErrors || [],
|
|
5504
|
+
networkStatus: networkStatus,
|
|
5505
|
+
});
|
|
5506
|
+
if (query.observableQuery) {
|
|
5507
|
+
this.setObservableQuery(query.observableQuery);
|
|
5481
5508
|
}
|
|
5482
|
-
|
|
5483
|
-
this.
|
|
5509
|
+
if (query.lastRequestId) {
|
|
5510
|
+
this.lastRequestId = query.lastRequestId;
|
|
5484
5511
|
}
|
|
5512
|
+
return this;
|
|
5485
5513
|
};
|
|
5486
|
-
|
|
5487
|
-
this
|
|
5488
|
-
this.
|
|
5514
|
+
QueryInfo.prototype.reset = function () {
|
|
5515
|
+
cancelNotifyTimeout(this);
|
|
5516
|
+
this.dirty = false;
|
|
5489
5517
|
};
|
|
5490
|
-
|
|
5491
|
-
|
|
5518
|
+
QueryInfo.prototype.resetDiff = function () {
|
|
5519
|
+
this.lastDiff = void 0;
|
|
5492
5520
|
};
|
|
5493
|
-
|
|
5494
|
-
|
|
5495
|
-
|
|
5496
|
-
return
|
|
5497
|
-
|
|
5498
|
-
|
|
5499
|
-
|
|
5500
|
-
|
|
5501
|
-
}
|
|
5502
|
-
}
|
|
5521
|
+
QueryInfo.prototype.getDiff = function () {
|
|
5522
|
+
var options = this.getDiffOptions();
|
|
5523
|
+
if (this.lastDiff && equal.equal(options, this.lastDiff.options)) {
|
|
5524
|
+
return this.lastDiff.diff;
|
|
5525
|
+
}
|
|
5526
|
+
this.updateWatch(this.variables);
|
|
5527
|
+
var oq = this.observableQuery;
|
|
5528
|
+
if (oq && oq.options.fetchPolicy === "no-cache") {
|
|
5529
|
+
return { complete: false };
|
|
5530
|
+
}
|
|
5531
|
+
var diff = this.cache.diff(options);
|
|
5532
|
+
this.updateLastDiff(diff, options);
|
|
5533
|
+
return diff;
|
|
5503
5534
|
};
|
|
5504
|
-
|
|
5505
|
-
this.
|
|
5535
|
+
QueryInfo.prototype.updateLastDiff = function (diff, options) {
|
|
5536
|
+
this.lastDiff =
|
|
5537
|
+
diff ?
|
|
5538
|
+
{
|
|
5539
|
+
diff: diff,
|
|
5540
|
+
options: options || this.getDiffOptions(),
|
|
5541
|
+
}
|
|
5542
|
+
: void 0;
|
|
5506
5543
|
};
|
|
5507
|
-
|
|
5508
|
-
|
|
5544
|
+
QueryInfo.prototype.getDiffOptions = function (variables) {
|
|
5545
|
+
var _a;
|
|
5546
|
+
if (variables === void 0) { variables = this.variables; }
|
|
5547
|
+
return {
|
|
5548
|
+
query: this.document,
|
|
5549
|
+
variables: variables,
|
|
5550
|
+
returnPartialData: true,
|
|
5551
|
+
optimistic: true,
|
|
5552
|
+
canonizeResults: (_a = this.observableQuery) === null || _a === void 0 ? void 0 : _a.options.canonizeResults,
|
|
5553
|
+
};
|
|
5509
5554
|
};
|
|
5510
|
-
|
|
5511
|
-
|
|
5512
|
-
|
|
5513
|
-
|
|
5555
|
+
QueryInfo.prototype.setDiff = function (diff) {
|
|
5556
|
+
var _this = this;
|
|
5557
|
+
var _a;
|
|
5558
|
+
var oldDiff = this.lastDiff && this.lastDiff.diff;
|
|
5559
|
+
if (diff && !diff.complete && ((_a = this.observableQuery) === null || _a === void 0 ? void 0 : _a.getLastError())) {
|
|
5560
|
+
return;
|
|
5561
|
+
}
|
|
5562
|
+
this.updateLastDiff(diff);
|
|
5563
|
+
if (!this.dirty && !equal.equal(oldDiff && oldDiff.result, diff && diff.result)) {
|
|
5564
|
+
this.dirty = true;
|
|
5565
|
+
if (!this.notifyTimeout) {
|
|
5566
|
+
this.notifyTimeout = setTimeout(function () { return _this.notify(); }, 0);
|
|
5514
5567
|
}
|
|
5515
5568
|
}
|
|
5516
|
-
return null;
|
|
5517
|
-
};
|
|
5518
|
-
LocalState.prototype.serverQuery = function (document) {
|
|
5519
|
-
return removeClientSetsFromDocument(document);
|
|
5520
|
-
};
|
|
5521
|
-
LocalState.prototype.prepareContext = function (context) {
|
|
5522
|
-
var cache = this.cache;
|
|
5523
|
-
return tslib.__assign(tslib.__assign({}, context), { cache: cache,
|
|
5524
|
-
getCacheKey: function (obj) {
|
|
5525
|
-
return cache.identify(obj);
|
|
5526
|
-
} });
|
|
5527
5569
|
};
|
|
5528
|
-
|
|
5529
|
-
|
|
5530
|
-
|
|
5531
|
-
|
|
5532
|
-
|
|
5533
|
-
|
|
5534
|
-
|
|
5570
|
+
QueryInfo.prototype.setObservableQuery = function (oq) {
|
|
5571
|
+
var _this = this;
|
|
5572
|
+
if (oq === this.observableQuery)
|
|
5573
|
+
return;
|
|
5574
|
+
if (this.oqListener) {
|
|
5575
|
+
this.listeners.delete(this.oqListener);
|
|
5576
|
+
}
|
|
5577
|
+
this.observableQuery = oq;
|
|
5578
|
+
if (oq) {
|
|
5579
|
+
oq["queryInfo"] = this;
|
|
5580
|
+
this.listeners.add((this.oqListener = function () {
|
|
5581
|
+
var diff = _this.getDiff();
|
|
5582
|
+
if (diff.fromOptimisticTransaction) {
|
|
5583
|
+
oq["observe"]();
|
|
5535
5584
|
}
|
|
5536
|
-
|
|
5537
|
-
|
|
5538
|
-
|
|
5585
|
+
else {
|
|
5586
|
+
reobserveCacheFirst(oq);
|
|
5587
|
+
}
|
|
5588
|
+
}));
|
|
5589
|
+
}
|
|
5590
|
+
else {
|
|
5591
|
+
delete this.oqListener;
|
|
5592
|
+
}
|
|
5539
5593
|
};
|
|
5540
|
-
|
|
5541
|
-
var
|
|
5542
|
-
|
|
5543
|
-
|
|
5544
|
-
|
|
5545
|
-
|
|
5546
|
-
|
|
5547
|
-
return arg.name.value === "always" &&
|
|
5548
|
-
arg.value.kind === "BooleanValue" &&
|
|
5549
|
-
arg.value.value === true;
|
|
5550
|
-
});
|
|
5551
|
-
if (forceResolvers) {
|
|
5552
|
-
return graphql.BREAK;
|
|
5553
|
-
}
|
|
5554
|
-
}
|
|
5555
|
-
},
|
|
5556
|
-
},
|
|
5557
|
-
});
|
|
5558
|
-
return forceResolvers;
|
|
5594
|
+
QueryInfo.prototype.notify = function () {
|
|
5595
|
+
var _this = this;
|
|
5596
|
+
cancelNotifyTimeout(this);
|
|
5597
|
+
if (this.shouldNotify()) {
|
|
5598
|
+
this.listeners.forEach(function (listener) { return listener(_this); });
|
|
5599
|
+
}
|
|
5600
|
+
this.dirty = false;
|
|
5559
5601
|
};
|
|
5560
|
-
|
|
5561
|
-
|
|
5562
|
-
|
|
5563
|
-
|
|
5564
|
-
|
|
5565
|
-
|
|
5566
|
-
|
|
5602
|
+
QueryInfo.prototype.shouldNotify = function () {
|
|
5603
|
+
if (!this.dirty || !this.listeners.size) {
|
|
5604
|
+
return false;
|
|
5605
|
+
}
|
|
5606
|
+
if (isNetworkRequestInFlight(this.networkStatus) && this.observableQuery) {
|
|
5607
|
+
var fetchPolicy = this.observableQuery.options.fetchPolicy;
|
|
5608
|
+
if (fetchPolicy !== "cache-only" && fetchPolicy !== "cache-and-network") {
|
|
5609
|
+
return false;
|
|
5610
|
+
}
|
|
5611
|
+
}
|
|
5612
|
+
return true;
|
|
5567
5613
|
};
|
|
5568
|
-
|
|
5569
|
-
|
|
5570
|
-
|
|
5571
|
-
|
|
5572
|
-
|
|
5573
|
-
|
|
5574
|
-
|
|
5575
|
-
|
|
5576
|
-
|
|
5577
|
-
|
|
5578
|
-
fragmentMap = createFragmentMap(fragments);
|
|
5579
|
-
selectionsToResolve = this.collectSelectionsToResolve(mainDefinition, fragmentMap);
|
|
5580
|
-
definitionOperation = mainDefinition.operation;
|
|
5581
|
-
defaultOperationType = definitionOperation ?
|
|
5582
|
-
definitionOperation.charAt(0).toUpperCase() +
|
|
5583
|
-
definitionOperation.slice(1)
|
|
5584
|
-
: "Query";
|
|
5585
|
-
_a = this, cache = _a.cache, client = _a.client;
|
|
5586
|
-
execContext = {
|
|
5587
|
-
fragmentMap: fragmentMap,
|
|
5588
|
-
context: tslib.__assign(tslib.__assign({}, context), { cache: cache, client: client }),
|
|
5589
|
-
variables: variables,
|
|
5590
|
-
fragmentMatcher: fragmentMatcher,
|
|
5591
|
-
defaultOperationType: defaultOperationType,
|
|
5592
|
-
exportedVariables: {},
|
|
5593
|
-
selectionsToResolve: selectionsToResolve,
|
|
5594
|
-
onlyRunForcedResolvers: onlyRunForcedResolvers,
|
|
5595
|
-
};
|
|
5596
|
-
isClientFieldDescendant = false;
|
|
5597
|
-
return [2 , this.resolveSelectionSet(mainDefinition.selectionSet, isClientFieldDescendant, rootValue, execContext).then(function (result) { return ({
|
|
5598
|
-
result: result,
|
|
5599
|
-
exportedVariables: execContext.exportedVariables,
|
|
5600
|
-
}); })];
|
|
5601
|
-
});
|
|
5602
|
-
});
|
|
5614
|
+
QueryInfo.prototype.stop = function () {
|
|
5615
|
+
if (!this.stopped) {
|
|
5616
|
+
this.stopped = true;
|
|
5617
|
+
this.reset();
|
|
5618
|
+
this.cancel();
|
|
5619
|
+
this.cancel = QueryInfo.prototype.cancel;
|
|
5620
|
+
var oq = this.observableQuery;
|
|
5621
|
+
if (oq)
|
|
5622
|
+
oq.stopPolling();
|
|
5623
|
+
}
|
|
5603
5624
|
};
|
|
5604
|
-
|
|
5605
|
-
|
|
5606
|
-
|
|
5607
|
-
|
|
5608
|
-
|
|
5609
|
-
|
|
5610
|
-
|
|
5611
|
-
|
|
5612
|
-
|
|
5613
|
-
|
|
5614
|
-
|
|
5615
|
-
|
|
5616
|
-
|
|
5617
|
-
}
|
|
5618
|
-
if (!shouldInclude(selection, variables)) {
|
|
5619
|
-
return [2 ];
|
|
5620
|
-
}
|
|
5621
|
-
if (isField(selection)) {
|
|
5622
|
-
return [2 , this.resolveField(selection, isClientFieldDescendant, rootValue, execContext).then(function (fieldResult) {
|
|
5623
|
-
var _a;
|
|
5624
|
-
if (typeof fieldResult !== "undefined") {
|
|
5625
|
-
resultsToMerge.push((_a = {},
|
|
5626
|
-
_a[resultKeyNameFromField(selection)] = fieldResult,
|
|
5627
|
-
_a));
|
|
5628
|
-
}
|
|
5629
|
-
})];
|
|
5630
|
-
}
|
|
5631
|
-
if (isInlineFragment(selection)) {
|
|
5632
|
-
fragment = selection;
|
|
5633
|
-
}
|
|
5634
|
-
else {
|
|
5635
|
-
fragment = fragmentMap[selection.name.value];
|
|
5636
|
-
invariant(fragment, 18, selection.name.value);
|
|
5637
|
-
}
|
|
5638
|
-
if (fragment && fragment.typeCondition) {
|
|
5639
|
-
typeCondition = fragment.typeCondition.name.value;
|
|
5640
|
-
if (execContext.fragmentMatcher(rootValue, typeCondition, context)) {
|
|
5641
|
-
return [2 , this.resolveSelectionSet(fragment.selectionSet, isClientFieldDescendant, rootValue, execContext).then(function (fragmentResult) {
|
|
5642
|
-
resultsToMerge.push(fragmentResult);
|
|
5643
|
-
})];
|
|
5644
|
-
}
|
|
5645
|
-
}
|
|
5646
|
-
return [2 ];
|
|
5647
|
-
});
|
|
5648
|
-
}); };
|
|
5649
|
-
return [2 , Promise.all(selectionSet.selections.map(execute)).then(function () {
|
|
5650
|
-
return mergeDeepArray(resultsToMerge);
|
|
5651
|
-
})];
|
|
5652
|
-
});
|
|
5653
|
-
});
|
|
5625
|
+
QueryInfo.prototype.cancel = function () { };
|
|
5626
|
+
QueryInfo.prototype.updateWatch = function (variables) {
|
|
5627
|
+
var _this = this;
|
|
5628
|
+
if (variables === void 0) { variables = this.variables; }
|
|
5629
|
+
var oq = this.observableQuery;
|
|
5630
|
+
if (oq && oq.options.fetchPolicy === "no-cache") {
|
|
5631
|
+
return;
|
|
5632
|
+
}
|
|
5633
|
+
var watchOptions = tslib.__assign(tslib.__assign({}, this.getDiffOptions(variables)), { watcher: this, callback: function (diff) { return _this.setDiff(diff); } });
|
|
5634
|
+
if (!this.lastWatch || !equal.equal(watchOptions, this.lastWatch)) {
|
|
5635
|
+
this.cancel();
|
|
5636
|
+
this.cancel = this.cache.watch((this.lastWatch = watchOptions));
|
|
5637
|
+
}
|
|
5654
5638
|
};
|
|
5655
|
-
|
|
5656
|
-
|
|
5657
|
-
var variables, fieldName, aliasedFieldName, aliasUsed, defaultResult, resultPromise, resolverType, resolverMap, resolve;
|
|
5658
|
-
var _this = this;
|
|
5659
|
-
return tslib.__generator(this, function (_a) {
|
|
5660
|
-
if (!rootValue) {
|
|
5661
|
-
return [2 , null];
|
|
5662
|
-
}
|
|
5663
|
-
variables = execContext.variables;
|
|
5664
|
-
fieldName = field.name.value;
|
|
5665
|
-
aliasedFieldName = resultKeyNameFromField(field);
|
|
5666
|
-
aliasUsed = fieldName !== aliasedFieldName;
|
|
5667
|
-
defaultResult = rootValue[aliasedFieldName] || rootValue[fieldName];
|
|
5668
|
-
resultPromise = Promise.resolve(defaultResult);
|
|
5669
|
-
if (!execContext.onlyRunForcedResolvers ||
|
|
5670
|
-
this.shouldForceResolvers(field)) {
|
|
5671
|
-
resolverType = rootValue.__typename || execContext.defaultOperationType;
|
|
5672
|
-
resolverMap = this.resolvers && this.resolvers[resolverType];
|
|
5673
|
-
if (resolverMap) {
|
|
5674
|
-
resolve = resolverMap[aliasUsed ? fieldName : aliasedFieldName];
|
|
5675
|
-
if (resolve) {
|
|
5676
|
-
resultPromise = Promise.resolve(
|
|
5677
|
-
cacheSlot.withValue(this.cache, resolve, [
|
|
5678
|
-
rootValue,
|
|
5679
|
-
argumentsObjectFromField(field, variables),
|
|
5680
|
-
execContext.context,
|
|
5681
|
-
{ field: field, fragmentMap: execContext.fragmentMap },
|
|
5682
|
-
]));
|
|
5683
|
-
}
|
|
5684
|
-
}
|
|
5685
|
-
}
|
|
5686
|
-
return [2 , resultPromise.then(function (result) {
|
|
5687
|
-
var _a, _b;
|
|
5688
|
-
if (result === void 0) { result = defaultResult; }
|
|
5689
|
-
if (field.directives) {
|
|
5690
|
-
field.directives.forEach(function (directive) {
|
|
5691
|
-
if (directive.name.value === "export" && directive.arguments) {
|
|
5692
|
-
directive.arguments.forEach(function (arg) {
|
|
5693
|
-
if (arg.name.value === "as" && arg.value.kind === "StringValue") {
|
|
5694
|
-
execContext.exportedVariables[arg.value.value] = result;
|
|
5695
|
-
}
|
|
5696
|
-
});
|
|
5697
|
-
}
|
|
5698
|
-
});
|
|
5699
|
-
}
|
|
5700
|
-
if (!field.selectionSet) {
|
|
5701
|
-
return result;
|
|
5702
|
-
}
|
|
5703
|
-
if (result == null) {
|
|
5704
|
-
return result;
|
|
5705
|
-
}
|
|
5706
|
-
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;
|
|
5707
|
-
if (Array.isArray(result)) {
|
|
5708
|
-
return _this.resolveSubSelectedArray(field, isClientFieldDescendant || isClientField, result, execContext);
|
|
5709
|
-
}
|
|
5710
|
-
if (field.selectionSet) {
|
|
5711
|
-
return _this.resolveSelectionSet(field.selectionSet, isClientFieldDescendant || isClientField, result, execContext);
|
|
5712
|
-
}
|
|
5713
|
-
})];
|
|
5714
|
-
});
|
|
5715
|
-
});
|
|
5639
|
+
QueryInfo.prototype.resetLastWrite = function () {
|
|
5640
|
+
this.lastWrite = void 0;
|
|
5716
5641
|
};
|
|
5717
|
-
|
|
5718
|
-
var
|
|
5719
|
-
return
|
|
5720
|
-
|
|
5721
|
-
|
|
5722
|
-
|
|
5723
|
-
if (Array.isArray(item)) {
|
|
5724
|
-
return _this.resolveSubSelectedArray(field, isClientFieldDescendant, item, execContext);
|
|
5725
|
-
}
|
|
5726
|
-
if (field.selectionSet) {
|
|
5727
|
-
return _this.resolveSelectionSet(field.selectionSet, isClientFieldDescendant, item, execContext);
|
|
5728
|
-
}
|
|
5729
|
-
}));
|
|
5642
|
+
QueryInfo.prototype.shouldWrite = function (result, variables) {
|
|
5643
|
+
var lastWrite = this.lastWrite;
|
|
5644
|
+
return !(lastWrite &&
|
|
5645
|
+
lastWrite.dmCount === destructiveMethodCounts.get(this.cache) &&
|
|
5646
|
+
equal.equal(variables, lastWrite.variables) &&
|
|
5647
|
+
equal.equal(result.data, lastWrite.result.data));
|
|
5730
5648
|
};
|
|
5731
|
-
|
|
5732
|
-
var
|
|
5733
|
-
var
|
|
5734
|
-
|
|
5735
|
-
|
|
5736
|
-
|
|
5737
|
-
|
|
5738
|
-
|
|
5739
|
-
|
|
5740
|
-
|
|
5741
|
-
|
|
5742
|
-
|
|
5743
|
-
|
|
5744
|
-
|
|
5745
|
-
|
|
5746
|
-
|
|
5747
|
-
|
|
5748
|
-
|
|
5749
|
-
|
|
5750
|
-
|
|
5751
|
-
|
|
5752
|
-
|
|
5753
|
-
|
|
5754
|
-
|
|
5755
|
-
|
|
5756
|
-
|
|
5757
|
-
|
|
5758
|
-
|
|
5759
|
-
|
|
5760
|
-
|
|
5761
|
-
|
|
5649
|
+
QueryInfo.prototype.markResult = function (result, document, options, cacheWriteBehavior) {
|
|
5650
|
+
var _this = this;
|
|
5651
|
+
var merger = new DeepMerger();
|
|
5652
|
+
var graphQLErrors = isNonEmptyArray(result.errors) ? result.errors.slice(0) : [];
|
|
5653
|
+
this.reset();
|
|
5654
|
+
if ("incremental" in result && isNonEmptyArray(result.incremental)) {
|
|
5655
|
+
var mergedData = mergeIncrementalData(this.getDiff().result, result);
|
|
5656
|
+
result.data = mergedData;
|
|
5657
|
+
}
|
|
5658
|
+
else if ("hasNext" in result && result.hasNext) {
|
|
5659
|
+
var diff = this.getDiff();
|
|
5660
|
+
result.data = merger.merge(diff.result, result.data);
|
|
5661
|
+
}
|
|
5662
|
+
this.graphQLErrors = graphQLErrors;
|
|
5663
|
+
if (options.fetchPolicy === "no-cache") {
|
|
5664
|
+
this.updateLastDiff({ result: result.data, complete: true }, this.getDiffOptions(options.variables));
|
|
5665
|
+
}
|
|
5666
|
+
else if (cacheWriteBehavior !== 0 ) {
|
|
5667
|
+
if (shouldWriteResult(result, options.errorPolicy)) {
|
|
5668
|
+
this.cache.performTransaction(function (cache) {
|
|
5669
|
+
if (_this.shouldWrite(result, options.variables)) {
|
|
5670
|
+
cache.writeQuery({
|
|
5671
|
+
query: document,
|
|
5672
|
+
data: result.data,
|
|
5673
|
+
variables: options.variables,
|
|
5674
|
+
overwrite: cacheWriteBehavior === 1 ,
|
|
5675
|
+
});
|
|
5676
|
+
_this.lastWrite = {
|
|
5677
|
+
result: result,
|
|
5678
|
+
variables: options.variables,
|
|
5679
|
+
dmCount: destructiveMethodCounts.get(_this.cache),
|
|
5680
|
+
};
|
|
5681
|
+
}
|
|
5682
|
+
else {
|
|
5683
|
+
if (_this.lastDiff && _this.lastDiff.diff.complete) {
|
|
5684
|
+
result.data = _this.lastDiff.diff.result;
|
|
5685
|
+
return;
|
|
5762
5686
|
}
|
|
5763
|
-
}
|
|
5687
|
+
}
|
|
5688
|
+
var diffOptions = _this.getDiffOptions(options.variables);
|
|
5689
|
+
var diff = cache.diff(diffOptions);
|
|
5690
|
+
if (!_this.stopped && equal.equal(_this.variables, options.variables)) {
|
|
5691
|
+
_this.updateWatch(options.variables);
|
|
5692
|
+
}
|
|
5693
|
+
_this.updateLastDiff(diff, diffOptions);
|
|
5694
|
+
if (diff.complete) {
|
|
5695
|
+
result.data = diff.result;
|
|
5696
|
+
}
|
|
5764
5697
|
});
|
|
5765
5698
|
}
|
|
5766
|
-
|
|
5699
|
+
else {
|
|
5700
|
+
this.lastWrite = void 0;
|
|
5701
|
+
}
|
|
5767
5702
|
}
|
|
5768
|
-
return collectByDefinition(mainDefinition);
|
|
5769
5703
|
};
|
|
5770
|
-
|
|
5704
|
+
QueryInfo.prototype.markReady = function () {
|
|
5705
|
+
this.networkError = null;
|
|
5706
|
+
return (this.networkStatus = exports.NetworkStatus.ready);
|
|
5707
|
+
};
|
|
5708
|
+
QueryInfo.prototype.markError = function (error) {
|
|
5709
|
+
this.networkStatus = exports.NetworkStatus.error;
|
|
5710
|
+
this.lastWrite = void 0;
|
|
5711
|
+
this.reset();
|
|
5712
|
+
if (error.graphQLErrors) {
|
|
5713
|
+
this.graphQLErrors = error.graphQLErrors;
|
|
5714
|
+
}
|
|
5715
|
+
if (error.networkError) {
|
|
5716
|
+
this.networkError = error.networkError;
|
|
5717
|
+
}
|
|
5718
|
+
return error;
|
|
5719
|
+
};
|
|
5720
|
+
return QueryInfo;
|
|
5771
5721
|
}());
|
|
5772
|
-
|
|
5773
|
-
|
|
5774
|
-
|
|
5775
|
-
var
|
|
5776
|
-
if (
|
|
5777
|
-
|
|
5778
|
-
destructiveMethodCounts.set(cache,
|
|
5779
|
-
(destructiveMethodCounts.get(cache) + 1) % 1e15);
|
|
5780
|
-
return original.apply(this, arguments);
|
|
5781
|
-
};
|
|
5782
|
-
}
|
|
5783
|
-
}
|
|
5784
|
-
function cancelNotifyTimeout(info) {
|
|
5785
|
-
if (info["notifyTimeout"]) {
|
|
5786
|
-
clearTimeout(info["notifyTimeout"]);
|
|
5787
|
-
info["notifyTimeout"] = void 0;
|
|
5722
|
+
function shouldWriteResult(result, errorPolicy) {
|
|
5723
|
+
if (errorPolicy === void 0) { errorPolicy = "none"; }
|
|
5724
|
+
var ignoreErrors = errorPolicy === "ignore" || errorPolicy === "all";
|
|
5725
|
+
var writeWithErrors = !graphQLResultHasError(result);
|
|
5726
|
+
if (!writeWithErrors && ignoreErrors && result.data) {
|
|
5727
|
+
writeWithErrors = true;
|
|
5788
5728
|
}
|
|
5729
|
+
return writeWithErrors;
|
|
5789
5730
|
}
|
|
5790
|
-
|
|
5791
|
-
|
|
5792
|
-
|
|
5793
|
-
|
|
5794
|
-
|
|
5795
|
-
|
|
5796
|
-
this.
|
|
5797
|
-
this.
|
|
5798
|
-
this.
|
|
5799
|
-
this.
|
|
5800
|
-
|
|
5801
|
-
|
|
5802
|
-
|
|
5803
|
-
|
|
5804
|
-
|
|
5805
|
-
|
|
5731
|
+
|
|
5732
|
+
var hasOwnProperty$1 = Object.prototype.hasOwnProperty;
|
|
5733
|
+
var IGNORE = Object.create(null);
|
|
5734
|
+
var QueryManager = (function () {
|
|
5735
|
+
function QueryManager(options) {
|
|
5736
|
+
var _this = this;
|
|
5737
|
+
this.clientAwareness = {};
|
|
5738
|
+
this.queries = new Map();
|
|
5739
|
+
this.fetchCancelFns = new Map();
|
|
5740
|
+
this.transformCache = new AutoCleanedWeakCache(cacheSizes["queryManager.getDocumentInfo"] ||
|
|
5741
|
+
2000 );
|
|
5742
|
+
this.queryIdCounter = 1;
|
|
5743
|
+
this.requestIdCounter = 1;
|
|
5744
|
+
this.mutationIdCounter = 1;
|
|
5745
|
+
this.inFlightLinkObservables = new trie.Trie(false);
|
|
5746
|
+
var defaultDocumentTransform = new DocumentTransform(function (document) { return _this.cache.transformDocument(document); },
|
|
5747
|
+
{ cache: false });
|
|
5748
|
+
this.cache = options.cache;
|
|
5749
|
+
this.link = options.link;
|
|
5750
|
+
this.defaultOptions = options.defaultOptions;
|
|
5751
|
+
this.queryDeduplication = options.queryDeduplication;
|
|
5752
|
+
this.clientAwareness = options.clientAwareness;
|
|
5753
|
+
this.localState = options.localState;
|
|
5754
|
+
this.ssrMode = options.ssrMode;
|
|
5755
|
+
this.assumeImmutableResults = options.assumeImmutableResults;
|
|
5756
|
+
var documentTransform = options.documentTransform;
|
|
5757
|
+
this.documentTransform =
|
|
5758
|
+
documentTransform ?
|
|
5759
|
+
defaultDocumentTransform
|
|
5760
|
+
.concat(documentTransform)
|
|
5761
|
+
.concat(defaultDocumentTransform)
|
|
5762
|
+
: defaultDocumentTransform;
|
|
5763
|
+
this.defaultContext = options.defaultContext || Object.create(null);
|
|
5764
|
+
if ((this.onBroadcast = options.onBroadcast)) {
|
|
5765
|
+
this.mutationStore = Object.create(null);
|
|
5806
5766
|
}
|
|
5807
5767
|
}
|
|
5808
|
-
|
|
5809
|
-
var
|
|
5810
|
-
|
|
5811
|
-
|
|
5812
|
-
!equal.equal(this.variables, query.variables)) {
|
|
5813
|
-
networkStatus = exports.NetworkStatus.setVariables;
|
|
5814
|
-
}
|
|
5815
|
-
if (!equal.equal(query.variables, this.variables)) {
|
|
5816
|
-
this.lastDiff = void 0;
|
|
5817
|
-
}
|
|
5818
|
-
Object.assign(this, {
|
|
5819
|
-
document: query.document,
|
|
5820
|
-
variables: query.variables,
|
|
5821
|
-
networkError: null,
|
|
5822
|
-
graphQLErrors: this.graphQLErrors || [],
|
|
5823
|
-
networkStatus: networkStatus,
|
|
5768
|
+
QueryManager.prototype.stop = function () {
|
|
5769
|
+
var _this = this;
|
|
5770
|
+
this.queries.forEach(function (_info, queryId) {
|
|
5771
|
+
_this.stopQueryNoBroadcast(queryId);
|
|
5824
5772
|
});
|
|
5825
|
-
|
|
5826
|
-
this.setObservableQuery(query.observableQuery);
|
|
5827
|
-
}
|
|
5828
|
-
if (query.lastRequestId) {
|
|
5829
|
-
this.lastRequestId = query.lastRequestId;
|
|
5830
|
-
}
|
|
5831
|
-
return this;
|
|
5832
|
-
};
|
|
5833
|
-
QueryInfo.prototype.reset = function () {
|
|
5834
|
-
cancelNotifyTimeout(this);
|
|
5835
|
-
this.dirty = false;
|
|
5836
|
-
};
|
|
5837
|
-
QueryInfo.prototype.resetDiff = function () {
|
|
5838
|
-
this.lastDiff = void 0;
|
|
5773
|
+
this.cancelPendingFetches(newInvariantError(25));
|
|
5839
5774
|
};
|
|
5840
|
-
|
|
5841
|
-
|
|
5842
|
-
|
|
5843
|
-
return this.lastDiff.diff;
|
|
5844
|
-
}
|
|
5845
|
-
this.updateWatch(this.variables);
|
|
5846
|
-
var oq = this.observableQuery;
|
|
5847
|
-
if (oq && oq.options.fetchPolicy === "no-cache") {
|
|
5848
|
-
return { complete: false };
|
|
5849
|
-
}
|
|
5850
|
-
var diff = this.cache.diff(options);
|
|
5851
|
-
this.updateLastDiff(diff, options);
|
|
5852
|
-
return diff;
|
|
5775
|
+
QueryManager.prototype.cancelPendingFetches = function (error) {
|
|
5776
|
+
this.fetchCancelFns.forEach(function (cancel) { return cancel(error); });
|
|
5777
|
+
this.fetchCancelFns.clear();
|
|
5853
5778
|
};
|
|
5854
|
-
|
|
5855
|
-
this
|
|
5856
|
-
|
|
5857
|
-
|
|
5858
|
-
|
|
5859
|
-
|
|
5779
|
+
QueryManager.prototype.mutate = function (_a) {
|
|
5780
|
+
return tslib.__awaiter(this, arguments, void 0, function (_b) {
|
|
5781
|
+
var mutationId, hasClientExports, mutationStoreValue, isOptimistic, self;
|
|
5782
|
+
var _c, _d;
|
|
5783
|
+
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;
|
|
5784
|
+
return tslib.__generator(this, function (_j) {
|
|
5785
|
+
switch (_j.label) {
|
|
5786
|
+
case 0:
|
|
5787
|
+
invariant(mutation, 26);
|
|
5788
|
+
invariant(fetchPolicy === "network-only" || fetchPolicy === "no-cache", 27);
|
|
5789
|
+
mutationId = this.generateMutationId();
|
|
5790
|
+
mutation = this.cache.transformForLink(this.transform(mutation));
|
|
5791
|
+
hasClientExports = this.getDocumentInfo(mutation).hasClientExports;
|
|
5792
|
+
variables = this.getVariables(mutation, variables);
|
|
5793
|
+
if (!hasClientExports) return [3 , 2];
|
|
5794
|
+
return [4 , this.localState.addExportedVariables(mutation, variables, context)];
|
|
5795
|
+
case 1:
|
|
5796
|
+
variables = (_j.sent());
|
|
5797
|
+
_j.label = 2;
|
|
5798
|
+
case 2:
|
|
5799
|
+
mutationStoreValue = this.mutationStore &&
|
|
5800
|
+
(this.mutationStore[mutationId] = {
|
|
5801
|
+
mutation: mutation,
|
|
5802
|
+
variables: variables,
|
|
5803
|
+
loading: true,
|
|
5804
|
+
error: null,
|
|
5805
|
+
});
|
|
5806
|
+
isOptimistic = optimisticResponse &&
|
|
5807
|
+
this.markMutationOptimistic(optimisticResponse, {
|
|
5808
|
+
mutationId: mutationId,
|
|
5809
|
+
document: mutation,
|
|
5810
|
+
variables: variables,
|
|
5811
|
+
fetchPolicy: fetchPolicy,
|
|
5812
|
+
errorPolicy: errorPolicy,
|
|
5813
|
+
context: context,
|
|
5814
|
+
updateQueries: updateQueries,
|
|
5815
|
+
update: updateWithProxyFn,
|
|
5816
|
+
keepRootFields: keepRootFields,
|
|
5817
|
+
});
|
|
5818
|
+
this.broadcastQueries();
|
|
5819
|
+
self = this;
|
|
5820
|
+
return [2 , new Promise(function (resolve, reject) {
|
|
5821
|
+
return asyncMap(self.getObservableFromLink(mutation, tslib.__assign(tslib.__assign({}, context), { optimisticResponse: isOptimistic ? optimisticResponse : void 0 }), variables, {}, false), function (result) {
|
|
5822
|
+
if (graphQLResultHasError(result) && errorPolicy === "none") {
|
|
5823
|
+
throw new ApolloError({
|
|
5824
|
+
graphQLErrors: getGraphQLErrorsFromResult(result),
|
|
5825
|
+
});
|
|
5826
|
+
}
|
|
5827
|
+
if (mutationStoreValue) {
|
|
5828
|
+
mutationStoreValue.loading = false;
|
|
5829
|
+
mutationStoreValue.error = null;
|
|
5830
|
+
}
|
|
5831
|
+
var storeResult = tslib.__assign({}, result);
|
|
5832
|
+
if (typeof refetchQueries === "function") {
|
|
5833
|
+
refetchQueries = refetchQueries(storeResult);
|
|
5834
|
+
}
|
|
5835
|
+
if (errorPolicy === "ignore" && graphQLResultHasError(storeResult)) {
|
|
5836
|
+
delete storeResult.errors;
|
|
5837
|
+
}
|
|
5838
|
+
return self.markMutationResult({
|
|
5839
|
+
mutationId: mutationId,
|
|
5840
|
+
result: storeResult,
|
|
5841
|
+
document: mutation,
|
|
5842
|
+
variables: variables,
|
|
5843
|
+
fetchPolicy: fetchPolicy,
|
|
5844
|
+
errorPolicy: errorPolicy,
|
|
5845
|
+
context: context,
|
|
5846
|
+
update: updateWithProxyFn,
|
|
5847
|
+
updateQueries: updateQueries,
|
|
5848
|
+
awaitRefetchQueries: awaitRefetchQueries,
|
|
5849
|
+
refetchQueries: refetchQueries,
|
|
5850
|
+
removeOptimistic: isOptimistic ? mutationId : void 0,
|
|
5851
|
+
onQueryUpdated: onQueryUpdated,
|
|
5852
|
+
keepRootFields: keepRootFields,
|
|
5853
|
+
});
|
|
5854
|
+
}).subscribe({
|
|
5855
|
+
next: function (storeResult) {
|
|
5856
|
+
self.broadcastQueries();
|
|
5857
|
+
if (!("hasNext" in storeResult) || storeResult.hasNext === false) {
|
|
5858
|
+
resolve(storeResult);
|
|
5859
|
+
}
|
|
5860
|
+
},
|
|
5861
|
+
error: function (err) {
|
|
5862
|
+
if (mutationStoreValue) {
|
|
5863
|
+
mutationStoreValue.loading = false;
|
|
5864
|
+
mutationStoreValue.error = err;
|
|
5865
|
+
}
|
|
5866
|
+
if (isOptimistic) {
|
|
5867
|
+
self.cache.removeOptimistic(mutationId);
|
|
5868
|
+
}
|
|
5869
|
+
self.broadcastQueries();
|
|
5870
|
+
reject(err instanceof ApolloError ? err : (new ApolloError({
|
|
5871
|
+
networkError: err,
|
|
5872
|
+
})));
|
|
5873
|
+
},
|
|
5874
|
+
});
|
|
5875
|
+
})];
|
|
5860
5876
|
}
|
|
5861
|
-
|
|
5862
|
-
|
|
5863
|
-
QueryInfo.prototype.getDiffOptions = function (variables) {
|
|
5864
|
-
var _a;
|
|
5865
|
-
if (variables === void 0) { variables = this.variables; }
|
|
5866
|
-
return {
|
|
5867
|
-
query: this.document,
|
|
5868
|
-
variables: variables,
|
|
5869
|
-
returnPartialData: true,
|
|
5870
|
-
optimistic: true,
|
|
5871
|
-
canonizeResults: (_a = this.observableQuery) === null || _a === void 0 ? void 0 : _a.options.canonizeResults,
|
|
5872
|
-
};
|
|
5877
|
+
});
|
|
5878
|
+
});
|
|
5873
5879
|
};
|
|
5874
|
-
|
|
5880
|
+
QueryManager.prototype.markMutationResult = function (mutation, cache) {
|
|
5875
5881
|
var _this = this;
|
|
5876
|
-
|
|
5877
|
-
var
|
|
5878
|
-
|
|
5879
|
-
|
|
5880
|
-
|
|
5881
|
-
|
|
5882
|
-
|
|
5883
|
-
|
|
5884
|
-
|
|
5885
|
-
|
|
5882
|
+
if (cache === void 0) { cache = this.cache; }
|
|
5883
|
+
var result = mutation.result;
|
|
5884
|
+
var cacheWrites = [];
|
|
5885
|
+
var skipCache = mutation.fetchPolicy === "no-cache";
|
|
5886
|
+
if (!skipCache && shouldWriteResult(result, mutation.errorPolicy)) {
|
|
5887
|
+
if (!isExecutionPatchIncrementalResult(result)) {
|
|
5888
|
+
cacheWrites.push({
|
|
5889
|
+
result: result.data,
|
|
5890
|
+
dataId: "ROOT_MUTATION",
|
|
5891
|
+
query: mutation.document,
|
|
5892
|
+
variables: mutation.variables,
|
|
5893
|
+
});
|
|
5886
5894
|
}
|
|
5887
|
-
|
|
5888
|
-
|
|
5889
|
-
|
|
5890
|
-
|
|
5891
|
-
|
|
5892
|
-
|
|
5893
|
-
|
|
5894
|
-
|
|
5895
|
-
|
|
5896
|
-
|
|
5897
|
-
|
|
5898
|
-
|
|
5899
|
-
this.listeners.add((this.oqListener = function () {
|
|
5900
|
-
var diff = _this.getDiff();
|
|
5901
|
-
if (diff.fromOptimisticTransaction) {
|
|
5902
|
-
oq["observe"]();
|
|
5895
|
+
if (isExecutionPatchIncrementalResult(result) &&
|
|
5896
|
+
isNonEmptyArray(result.incremental)) {
|
|
5897
|
+
var diff = cache.diff({
|
|
5898
|
+
id: "ROOT_MUTATION",
|
|
5899
|
+
query: this.getDocumentInfo(mutation.document).asQuery,
|
|
5900
|
+
variables: mutation.variables,
|
|
5901
|
+
optimistic: false,
|
|
5902
|
+
returnPartialData: true,
|
|
5903
|
+
});
|
|
5904
|
+
var mergedData = void 0;
|
|
5905
|
+
if (diff.result) {
|
|
5906
|
+
mergedData = mergeIncrementalData(diff.result, result);
|
|
5903
5907
|
}
|
|
5904
|
-
|
|
5905
|
-
|
|
5908
|
+
if (typeof mergedData !== "undefined") {
|
|
5909
|
+
result.data = mergedData;
|
|
5910
|
+
cacheWrites.push({
|
|
5911
|
+
result: mergedData,
|
|
5912
|
+
dataId: "ROOT_MUTATION",
|
|
5913
|
+
query: mutation.document,
|
|
5914
|
+
variables: mutation.variables,
|
|
5915
|
+
});
|
|
5906
5916
|
}
|
|
5907
|
-
}
|
|
5908
|
-
|
|
5909
|
-
|
|
5910
|
-
|
|
5917
|
+
}
|
|
5918
|
+
var updateQueries_1 = mutation.updateQueries;
|
|
5919
|
+
if (updateQueries_1) {
|
|
5920
|
+
this.queries.forEach(function (_a, queryId) {
|
|
5921
|
+
var observableQuery = _a.observableQuery;
|
|
5922
|
+
var queryName = observableQuery && observableQuery.queryName;
|
|
5923
|
+
if (!queryName || !hasOwnProperty$1.call(updateQueries_1, queryName)) {
|
|
5924
|
+
return;
|
|
5925
|
+
}
|
|
5926
|
+
var updater = updateQueries_1[queryName];
|
|
5927
|
+
var _b = _this.queries.get(queryId), document = _b.document, variables = _b.variables;
|
|
5928
|
+
var _c = cache.diff({
|
|
5929
|
+
query: document,
|
|
5930
|
+
variables: variables,
|
|
5931
|
+
returnPartialData: true,
|
|
5932
|
+
optimistic: false,
|
|
5933
|
+
}), currentQueryResult = _c.result, complete = _c.complete;
|
|
5934
|
+
if (complete && currentQueryResult) {
|
|
5935
|
+
var nextQueryResult = updater(currentQueryResult, {
|
|
5936
|
+
mutationResult: result,
|
|
5937
|
+
queryName: (document && getOperationName(document)) || void 0,
|
|
5938
|
+
queryVariables: variables,
|
|
5939
|
+
});
|
|
5940
|
+
if (nextQueryResult) {
|
|
5941
|
+
cacheWrites.push({
|
|
5942
|
+
result: nextQueryResult,
|
|
5943
|
+
dataId: "ROOT_QUERY",
|
|
5944
|
+
query: document,
|
|
5945
|
+
variables: variables,
|
|
5946
|
+
});
|
|
5947
|
+
}
|
|
5948
|
+
}
|
|
5949
|
+
});
|
|
5950
|
+
}
|
|
5911
5951
|
}
|
|
5912
|
-
|
|
5913
|
-
|
|
5914
|
-
|
|
5915
|
-
|
|
5916
|
-
|
|
5917
|
-
|
|
5952
|
+
if (cacheWrites.length > 0 ||
|
|
5953
|
+
(mutation.refetchQueries || "").length > 0 ||
|
|
5954
|
+
mutation.update ||
|
|
5955
|
+
mutation.onQueryUpdated ||
|
|
5956
|
+
mutation.removeOptimistic) {
|
|
5957
|
+
var results_1 = [];
|
|
5958
|
+
this.refetchQueries({
|
|
5959
|
+
updateCache: function (cache) {
|
|
5960
|
+
if (!skipCache) {
|
|
5961
|
+
cacheWrites.forEach(function (write) { return cache.write(write); });
|
|
5962
|
+
}
|
|
5963
|
+
var update = mutation.update;
|
|
5964
|
+
var isFinalResult = !isExecutionPatchResult(result) ||
|
|
5965
|
+
(isExecutionPatchIncrementalResult(result) && !result.hasNext);
|
|
5966
|
+
if (update) {
|
|
5967
|
+
if (!skipCache) {
|
|
5968
|
+
var diff = cache.diff({
|
|
5969
|
+
id: "ROOT_MUTATION",
|
|
5970
|
+
query: _this.getDocumentInfo(mutation.document).asQuery,
|
|
5971
|
+
variables: mutation.variables,
|
|
5972
|
+
optimistic: false,
|
|
5973
|
+
returnPartialData: true,
|
|
5974
|
+
});
|
|
5975
|
+
if (diff.complete) {
|
|
5976
|
+
result = tslib.__assign(tslib.__assign({}, result), { data: diff.result });
|
|
5977
|
+
if ("incremental" in result) {
|
|
5978
|
+
delete result.incremental;
|
|
5979
|
+
}
|
|
5980
|
+
if ("hasNext" in result) {
|
|
5981
|
+
delete result.hasNext;
|
|
5982
|
+
}
|
|
5983
|
+
}
|
|
5984
|
+
}
|
|
5985
|
+
if (isFinalResult) {
|
|
5986
|
+
update(cache, result, {
|
|
5987
|
+
context: mutation.context,
|
|
5988
|
+
variables: mutation.variables,
|
|
5989
|
+
});
|
|
5990
|
+
}
|
|
5991
|
+
}
|
|
5992
|
+
if (!skipCache && !mutation.keepRootFields && isFinalResult) {
|
|
5993
|
+
cache.modify({
|
|
5994
|
+
id: "ROOT_MUTATION",
|
|
5995
|
+
fields: function (value, _a) {
|
|
5996
|
+
var fieldName = _a.fieldName, DELETE = _a.DELETE;
|
|
5997
|
+
return fieldName === "__typename" ? value : DELETE;
|
|
5998
|
+
},
|
|
5999
|
+
});
|
|
6000
|
+
}
|
|
6001
|
+
},
|
|
6002
|
+
include: mutation.refetchQueries,
|
|
6003
|
+
optimistic: false,
|
|
6004
|
+
removeOptimistic: mutation.removeOptimistic,
|
|
6005
|
+
onQueryUpdated: mutation.onQueryUpdated || null,
|
|
6006
|
+
}).forEach(function (result) { return results_1.push(result); });
|
|
6007
|
+
if (mutation.awaitRefetchQueries || mutation.onQueryUpdated) {
|
|
6008
|
+
return Promise.all(results_1).then(function () { return result; });
|
|
6009
|
+
}
|
|
5918
6010
|
}
|
|
5919
|
-
|
|
6011
|
+
return Promise.resolve(result);
|
|
5920
6012
|
};
|
|
5921
|
-
|
|
5922
|
-
|
|
6013
|
+
QueryManager.prototype.markMutationOptimistic = function (optimisticResponse, mutation) {
|
|
6014
|
+
var _this = this;
|
|
6015
|
+
var data = typeof optimisticResponse === "function" ?
|
|
6016
|
+
optimisticResponse(mutation.variables, { IGNORE: IGNORE })
|
|
6017
|
+
: optimisticResponse;
|
|
6018
|
+
if (data === IGNORE) {
|
|
5923
6019
|
return false;
|
|
5924
6020
|
}
|
|
5925
|
-
|
|
5926
|
-
|
|
5927
|
-
|
|
5928
|
-
return false;
|
|
6021
|
+
this.cache.recordOptimisticTransaction(function (cache) {
|
|
6022
|
+
try {
|
|
6023
|
+
_this.markMutationResult(tslib.__assign(tslib.__assign({}, mutation), { result: { data: data } }), cache);
|
|
5929
6024
|
}
|
|
5930
|
-
|
|
6025
|
+
catch (error) {
|
|
6026
|
+
globalThis.__DEV__ !== false && invariant.error(error);
|
|
6027
|
+
}
|
|
6028
|
+
}, mutation.mutationId);
|
|
5931
6029
|
return true;
|
|
5932
6030
|
};
|
|
5933
|
-
|
|
5934
|
-
|
|
5935
|
-
|
|
5936
|
-
this.reset();
|
|
5937
|
-
this.cancel();
|
|
5938
|
-
this.cancel = QueryInfo.prototype.cancel;
|
|
5939
|
-
var oq = this.observableQuery;
|
|
5940
|
-
if (oq)
|
|
5941
|
-
oq.stopPolling();
|
|
5942
|
-
}
|
|
6031
|
+
QueryManager.prototype.fetchQuery = function (queryId, options, networkStatus) {
|
|
6032
|
+
return this.fetchConcastWithInfo(queryId, options, networkStatus).concast
|
|
6033
|
+
.promise;
|
|
5943
6034
|
};
|
|
5944
|
-
|
|
5945
|
-
|
|
5946
|
-
|
|
5947
|
-
|
|
5948
|
-
|
|
5949
|
-
|
|
5950
|
-
|
|
5951
|
-
|
|
5952
|
-
|
|
5953
|
-
|
|
5954
|
-
|
|
5955
|
-
this.cancel = this.cache.watch((this.lastWatch = watchOptions));
|
|
5956
|
-
}
|
|
6035
|
+
QueryManager.prototype.getQueryStore = function () {
|
|
6036
|
+
var store = Object.create(null);
|
|
6037
|
+
this.queries.forEach(function (info, queryId) {
|
|
6038
|
+
store[queryId] = {
|
|
6039
|
+
variables: info.variables,
|
|
6040
|
+
networkStatus: info.networkStatus,
|
|
6041
|
+
networkError: info.networkError,
|
|
6042
|
+
graphQLErrors: info.graphQLErrors,
|
|
6043
|
+
};
|
|
6044
|
+
});
|
|
6045
|
+
return store;
|
|
5957
6046
|
};
|
|
5958
|
-
|
|
5959
|
-
|
|
6047
|
+
QueryManager.prototype.resetErrors = function (queryId) {
|
|
6048
|
+
var queryInfo = this.queries.get(queryId);
|
|
6049
|
+
if (queryInfo) {
|
|
6050
|
+
queryInfo.networkError = undefined;
|
|
6051
|
+
queryInfo.graphQLErrors = [];
|
|
6052
|
+
}
|
|
5960
6053
|
};
|
|
5961
|
-
|
|
5962
|
-
|
|
5963
|
-
return !(lastWrite &&
|
|
5964
|
-
lastWrite.dmCount === destructiveMethodCounts.get(this.cache) &&
|
|
5965
|
-
equal.equal(variables, lastWrite.variables) &&
|
|
5966
|
-
equal.equal(result.data, lastWrite.result.data));
|
|
6054
|
+
QueryManager.prototype.transform = function (document) {
|
|
6055
|
+
return this.documentTransform.transformDocument(document);
|
|
5967
6056
|
};
|
|
5968
|
-
|
|
5969
|
-
var
|
|
5970
|
-
|
|
5971
|
-
|
|
5972
|
-
|
|
5973
|
-
|
|
5974
|
-
|
|
5975
|
-
|
|
5976
|
-
|
|
5977
|
-
|
|
5978
|
-
|
|
5979
|
-
|
|
5980
|
-
|
|
5981
|
-
|
|
5982
|
-
|
|
5983
|
-
|
|
5984
|
-
|
|
5985
|
-
|
|
5986
|
-
if (shouldWriteResult(result, options.errorPolicy)) {
|
|
5987
|
-
this.cache.performTransaction(function (cache) {
|
|
5988
|
-
if (_this.shouldWrite(result, options.variables)) {
|
|
5989
|
-
cache.writeQuery({
|
|
5990
|
-
query: document,
|
|
5991
|
-
data: result.data,
|
|
5992
|
-
variables: options.variables,
|
|
5993
|
-
overwrite: cacheWriteBehavior === 1 ,
|
|
5994
|
-
});
|
|
5995
|
-
_this.lastWrite = {
|
|
5996
|
-
result: result,
|
|
5997
|
-
variables: options.variables,
|
|
5998
|
-
dmCount: destructiveMethodCounts.get(_this.cache),
|
|
5999
|
-
};
|
|
6000
|
-
}
|
|
6001
|
-
else {
|
|
6002
|
-
if (_this.lastDiff && _this.lastDiff.diff.complete) {
|
|
6003
|
-
result.data = _this.lastDiff.diff.result;
|
|
6004
|
-
return;
|
|
6057
|
+
QueryManager.prototype.getDocumentInfo = function (document) {
|
|
6058
|
+
var transformCache = this.transformCache;
|
|
6059
|
+
if (!transformCache.has(document)) {
|
|
6060
|
+
var cacheEntry = {
|
|
6061
|
+
hasClientExports: hasClientExports(document),
|
|
6062
|
+
hasForcedResolvers: this.localState.shouldForceResolvers(document),
|
|
6063
|
+
hasNonreactiveDirective: hasDirectives(["nonreactive"], document),
|
|
6064
|
+
clientQuery: this.localState.clientQuery(document),
|
|
6065
|
+
serverQuery: removeDirectivesFromDocument([
|
|
6066
|
+
{ name: "client", remove: true },
|
|
6067
|
+
{ name: "connection" },
|
|
6068
|
+
{ name: "nonreactive" },
|
|
6069
|
+
], document),
|
|
6070
|
+
defaultVars: getDefaultValues(getOperationDefinition(document)),
|
|
6071
|
+
asQuery: tslib.__assign(tslib.__assign({}, document), { definitions: document.definitions.map(function (def) {
|
|
6072
|
+
if (def.kind === "OperationDefinition" &&
|
|
6073
|
+
def.operation !== "query") {
|
|
6074
|
+
return tslib.__assign(tslib.__assign({}, def), { operation: "query" });
|
|
6005
6075
|
}
|
|
6006
|
-
|
|
6007
|
-
|
|
6008
|
-
|
|
6009
|
-
|
|
6010
|
-
_this.updateWatch(options.variables);
|
|
6011
|
-
}
|
|
6012
|
-
_this.updateLastDiff(diff, diffOptions);
|
|
6013
|
-
if (diff.complete) {
|
|
6014
|
-
result.data = diff.result;
|
|
6015
|
-
}
|
|
6016
|
-
});
|
|
6017
|
-
}
|
|
6018
|
-
else {
|
|
6019
|
-
this.lastWrite = void 0;
|
|
6020
|
-
}
|
|
6076
|
+
return def;
|
|
6077
|
+
}) }),
|
|
6078
|
+
};
|
|
6079
|
+
transformCache.set(document, cacheEntry);
|
|
6021
6080
|
}
|
|
6081
|
+
return transformCache.get(document);
|
|
6022
6082
|
};
|
|
6023
|
-
|
|
6024
|
-
this.
|
|
6025
|
-
return (this.networkStatus = exports.NetworkStatus.ready);
|
|
6083
|
+
QueryManager.prototype.getVariables = function (document, variables) {
|
|
6084
|
+
return tslib.__assign(tslib.__assign({}, this.getDocumentInfo(document).defaultVars), variables);
|
|
6026
6085
|
};
|
|
6027
|
-
|
|
6028
|
-
|
|
6029
|
-
this.
|
|
6030
|
-
|
|
6031
|
-
|
|
6032
|
-
this.graphQLErrors = error.graphQLErrors;
|
|
6033
|
-
}
|
|
6034
|
-
if (error.networkError) {
|
|
6035
|
-
this.networkError = error.networkError;
|
|
6086
|
+
QueryManager.prototype.watchQuery = function (options) {
|
|
6087
|
+
var query = this.transform(options.query);
|
|
6088
|
+
options = tslib.__assign(tslib.__assign({}, options), { variables: this.getVariables(query, options.variables) });
|
|
6089
|
+
if (typeof options.notifyOnNetworkStatusChange === "undefined") {
|
|
6090
|
+
options.notifyOnNetworkStatusChange = false;
|
|
6036
6091
|
}
|
|
6037
|
-
|
|
6092
|
+
var queryInfo = new QueryInfo(this);
|
|
6093
|
+
var observable = new ObservableQuery({
|
|
6094
|
+
queryManager: this,
|
|
6095
|
+
queryInfo: queryInfo,
|
|
6096
|
+
options: options,
|
|
6097
|
+
});
|
|
6098
|
+
observable["lastQuery"] = query;
|
|
6099
|
+
this.queries.set(observable.queryId, queryInfo);
|
|
6100
|
+
queryInfo.init({
|
|
6101
|
+
document: query,
|
|
6102
|
+
observableQuery: observable,
|
|
6103
|
+
variables: observable.variables,
|
|
6104
|
+
});
|
|
6105
|
+
return observable;
|
|
6038
6106
|
};
|
|
6039
|
-
|
|
6040
|
-
}());
|
|
6041
|
-
function shouldWriteResult(result, errorPolicy) {
|
|
6042
|
-
if (errorPolicy === void 0) { errorPolicy = "none"; }
|
|
6043
|
-
var ignoreErrors = errorPolicy === "ignore" || errorPolicy === "all";
|
|
6044
|
-
var writeWithErrors = !graphQLResultHasError(result);
|
|
6045
|
-
if (!writeWithErrors && ignoreErrors && result.data) {
|
|
6046
|
-
writeWithErrors = true;
|
|
6047
|
-
}
|
|
6048
|
-
return writeWithErrors;
|
|
6049
|
-
}
|
|
6050
|
-
|
|
6051
|
-
var hasOwnProperty$1 = Object.prototype.hasOwnProperty;
|
|
6052
|
-
var IGNORE = Object.create(null);
|
|
6053
|
-
var QueryManager = (function () {
|
|
6054
|
-
function QueryManager(_a) {
|
|
6055
|
-
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;
|
|
6107
|
+
QueryManager.prototype.query = function (options, queryId) {
|
|
6056
6108
|
var _this = this;
|
|
6057
|
-
this.
|
|
6058
|
-
|
|
6059
|
-
|
|
6060
|
-
|
|
6061
|
-
|
|
6062
|
-
this.
|
|
6063
|
-
|
|
6064
|
-
|
|
6065
|
-
this.
|
|
6066
|
-
|
|
6067
|
-
|
|
6068
|
-
this.
|
|
6069
|
-
|
|
6070
|
-
|
|
6071
|
-
this.
|
|
6072
|
-
|
|
6073
|
-
|
|
6074
|
-
this.
|
|
6075
|
-
this.
|
|
6076
|
-
|
|
6077
|
-
|
|
6078
|
-
|
|
6079
|
-
|
|
6080
|
-
|
|
6081
|
-
|
|
6082
|
-
|
|
6083
|
-
if (
|
|
6109
|
+
if (queryId === void 0) { queryId = this.generateQueryId(); }
|
|
6110
|
+
invariant(options.query, 28);
|
|
6111
|
+
invariant(options.query.kind === "Document", 29);
|
|
6112
|
+
invariant(!options.returnPartialData, 30);
|
|
6113
|
+
invariant(!options.pollInterval, 31);
|
|
6114
|
+
return this.fetchQuery(queryId, tslib.__assign(tslib.__assign({}, options), { query: this.transform(options.query) })).finally(function () { return _this.stopQuery(queryId); });
|
|
6115
|
+
};
|
|
6116
|
+
QueryManager.prototype.generateQueryId = function () {
|
|
6117
|
+
return String(this.queryIdCounter++);
|
|
6118
|
+
};
|
|
6119
|
+
QueryManager.prototype.generateRequestId = function () {
|
|
6120
|
+
return this.requestIdCounter++;
|
|
6121
|
+
};
|
|
6122
|
+
QueryManager.prototype.generateMutationId = function () {
|
|
6123
|
+
return String(this.mutationIdCounter++);
|
|
6124
|
+
};
|
|
6125
|
+
QueryManager.prototype.stopQueryInStore = function (queryId) {
|
|
6126
|
+
this.stopQueryInStoreNoBroadcast(queryId);
|
|
6127
|
+
this.broadcastQueries();
|
|
6128
|
+
};
|
|
6129
|
+
QueryManager.prototype.stopQueryInStoreNoBroadcast = function (queryId) {
|
|
6130
|
+
var queryInfo = this.queries.get(queryId);
|
|
6131
|
+
if (queryInfo)
|
|
6132
|
+
queryInfo.stop();
|
|
6133
|
+
};
|
|
6134
|
+
QueryManager.prototype.clearStore = function (options) {
|
|
6135
|
+
if (options === void 0) { options = {
|
|
6136
|
+
discardWatches: true,
|
|
6137
|
+
}; }
|
|
6138
|
+
this.cancelPendingFetches(newInvariantError(32));
|
|
6139
|
+
this.queries.forEach(function (queryInfo) {
|
|
6140
|
+
if (queryInfo.observableQuery) {
|
|
6141
|
+
queryInfo.networkStatus = exports.NetworkStatus.loading;
|
|
6142
|
+
}
|
|
6143
|
+
else {
|
|
6144
|
+
queryInfo.stop();
|
|
6145
|
+
}
|
|
6146
|
+
});
|
|
6147
|
+
if (this.mutationStore) {
|
|
6084
6148
|
this.mutationStore = Object.create(null);
|
|
6085
6149
|
}
|
|
6086
|
-
|
|
6087
|
-
QueryManager.prototype.stop = function () {
|
|
6088
|
-
var _this = this;
|
|
6089
|
-
this.queries.forEach(function (_info, queryId) {
|
|
6090
|
-
_this.stopQueryNoBroadcast(queryId);
|
|
6091
|
-
});
|
|
6092
|
-
this.cancelPendingFetches(newInvariantError(25));
|
|
6093
|
-
};
|
|
6094
|
-
QueryManager.prototype.cancelPendingFetches = function (error) {
|
|
6095
|
-
this.fetchCancelFns.forEach(function (cancel) { return cancel(error); });
|
|
6096
|
-
this.fetchCancelFns.clear();
|
|
6150
|
+
return this.cache.reset(options);
|
|
6097
6151
|
};
|
|
6098
|
-
QueryManager.prototype.
|
|
6099
|
-
|
|
6100
|
-
|
|
6101
|
-
|
|
6102
|
-
|
|
6103
|
-
|
|
6104
|
-
|
|
6105
|
-
|
|
6106
|
-
|
|
6107
|
-
|
|
6108
|
-
|
|
6109
|
-
|
|
6110
|
-
|
|
6111
|
-
|
|
6112
|
-
|
|
6113
|
-
|
|
6114
|
-
case 1:
|
|
6115
|
-
variables = (_j.sent());
|
|
6116
|
-
_j.label = 2;
|
|
6117
|
-
case 2:
|
|
6118
|
-
mutationStoreValue = this.mutationStore &&
|
|
6119
|
-
(this.mutationStore[mutationId] = {
|
|
6120
|
-
mutation: mutation,
|
|
6121
|
-
variables: variables,
|
|
6122
|
-
loading: true,
|
|
6123
|
-
error: null,
|
|
6124
|
-
});
|
|
6125
|
-
isOptimistic = optimisticResponse &&
|
|
6126
|
-
this.markMutationOptimistic(optimisticResponse, {
|
|
6127
|
-
mutationId: mutationId,
|
|
6128
|
-
document: mutation,
|
|
6129
|
-
variables: variables,
|
|
6130
|
-
fetchPolicy: fetchPolicy,
|
|
6131
|
-
errorPolicy: errorPolicy,
|
|
6132
|
-
context: context,
|
|
6133
|
-
updateQueries: updateQueries,
|
|
6134
|
-
update: updateWithProxyFn,
|
|
6135
|
-
keepRootFields: keepRootFields,
|
|
6136
|
-
});
|
|
6137
|
-
this.broadcastQueries();
|
|
6138
|
-
self = this;
|
|
6139
|
-
return [2 , new Promise(function (resolve, reject) {
|
|
6140
|
-
return asyncMap(self.getObservableFromLink(mutation, tslib.__assign(tslib.__assign({}, context), { optimisticResponse: isOptimistic ? optimisticResponse : void 0 }), variables, {}, false), function (result) {
|
|
6141
|
-
if (graphQLResultHasError(result) && errorPolicy === "none") {
|
|
6142
|
-
throw new ApolloError({
|
|
6143
|
-
graphQLErrors: getGraphQLErrorsFromResult(result),
|
|
6144
|
-
});
|
|
6145
|
-
}
|
|
6146
|
-
if (mutationStoreValue) {
|
|
6147
|
-
mutationStoreValue.loading = false;
|
|
6148
|
-
mutationStoreValue.error = null;
|
|
6149
|
-
}
|
|
6150
|
-
var storeResult = tslib.__assign({}, result);
|
|
6151
|
-
if (typeof refetchQueries === "function") {
|
|
6152
|
-
refetchQueries = refetchQueries(storeResult);
|
|
6153
|
-
}
|
|
6154
|
-
if (errorPolicy === "ignore" && graphQLResultHasError(storeResult)) {
|
|
6155
|
-
delete storeResult.errors;
|
|
6156
|
-
}
|
|
6157
|
-
return self.markMutationResult({
|
|
6158
|
-
mutationId: mutationId,
|
|
6159
|
-
result: storeResult,
|
|
6160
|
-
document: mutation,
|
|
6161
|
-
variables: variables,
|
|
6162
|
-
fetchPolicy: fetchPolicy,
|
|
6163
|
-
errorPolicy: errorPolicy,
|
|
6164
|
-
context: context,
|
|
6165
|
-
update: updateWithProxyFn,
|
|
6166
|
-
updateQueries: updateQueries,
|
|
6167
|
-
awaitRefetchQueries: awaitRefetchQueries,
|
|
6168
|
-
refetchQueries: refetchQueries,
|
|
6169
|
-
removeOptimistic: isOptimistic ? mutationId : void 0,
|
|
6170
|
-
onQueryUpdated: onQueryUpdated,
|
|
6171
|
-
keepRootFields: keepRootFields,
|
|
6172
|
-
});
|
|
6173
|
-
}).subscribe({
|
|
6174
|
-
next: function (storeResult) {
|
|
6175
|
-
self.broadcastQueries();
|
|
6176
|
-
if (!("hasNext" in storeResult) || storeResult.hasNext === false) {
|
|
6177
|
-
resolve(storeResult);
|
|
6178
|
-
}
|
|
6179
|
-
},
|
|
6180
|
-
error: function (err) {
|
|
6181
|
-
if (mutationStoreValue) {
|
|
6182
|
-
mutationStoreValue.loading = false;
|
|
6183
|
-
mutationStoreValue.error = err;
|
|
6184
|
-
}
|
|
6185
|
-
if (isOptimistic) {
|
|
6186
|
-
self.cache.removeOptimistic(mutationId);
|
|
6187
|
-
}
|
|
6188
|
-
self.broadcastQueries();
|
|
6189
|
-
reject(err instanceof ApolloError ? err : (new ApolloError({
|
|
6190
|
-
networkError: err,
|
|
6191
|
-
})));
|
|
6192
|
-
},
|
|
6193
|
-
});
|
|
6194
|
-
})];
|
|
6152
|
+
QueryManager.prototype.getObservableQueries = function (include) {
|
|
6153
|
+
var _this = this;
|
|
6154
|
+
if (include === void 0) { include = "active"; }
|
|
6155
|
+
var queries = new Map();
|
|
6156
|
+
var queryNamesAndDocs = new Map();
|
|
6157
|
+
var legacyQueryOptions = new Set();
|
|
6158
|
+
if (Array.isArray(include)) {
|
|
6159
|
+
include.forEach(function (desc) {
|
|
6160
|
+
if (typeof desc === "string") {
|
|
6161
|
+
queryNamesAndDocs.set(desc, false);
|
|
6162
|
+
}
|
|
6163
|
+
else if (isDocumentNode(desc)) {
|
|
6164
|
+
queryNamesAndDocs.set(_this.transform(desc), false);
|
|
6165
|
+
}
|
|
6166
|
+
else if (isNonNullObject(desc) && desc.query) {
|
|
6167
|
+
legacyQueryOptions.add(desc);
|
|
6195
6168
|
}
|
|
6196
6169
|
});
|
|
6170
|
+
}
|
|
6171
|
+
this.queries.forEach(function (_a, queryId) {
|
|
6172
|
+
var oq = _a.observableQuery, document = _a.document;
|
|
6173
|
+
if (oq) {
|
|
6174
|
+
if (include === "all") {
|
|
6175
|
+
queries.set(queryId, oq);
|
|
6176
|
+
return;
|
|
6177
|
+
}
|
|
6178
|
+
var queryName = oq.queryName, fetchPolicy = oq.options.fetchPolicy;
|
|
6179
|
+
if (fetchPolicy === "standby" ||
|
|
6180
|
+
(include === "active" && !oq.hasObservers())) {
|
|
6181
|
+
return;
|
|
6182
|
+
}
|
|
6183
|
+
if (include === "active" ||
|
|
6184
|
+
(queryName && queryNamesAndDocs.has(queryName)) ||
|
|
6185
|
+
(document && queryNamesAndDocs.has(document))) {
|
|
6186
|
+
queries.set(queryId, oq);
|
|
6187
|
+
if (queryName)
|
|
6188
|
+
queryNamesAndDocs.set(queryName, true);
|
|
6189
|
+
if (document)
|
|
6190
|
+
queryNamesAndDocs.set(document, true);
|
|
6191
|
+
}
|
|
6192
|
+
}
|
|
6197
6193
|
});
|
|
6198
|
-
|
|
6199
|
-
|
|
6200
|
-
|
|
6201
|
-
|
|
6202
|
-
|
|
6203
|
-
|
|
6204
|
-
var skipCache = mutation.fetchPolicy === "no-cache";
|
|
6205
|
-
if (!skipCache && shouldWriteResult(result, mutation.errorPolicy)) {
|
|
6206
|
-
if (!isExecutionPatchIncrementalResult(result)) {
|
|
6207
|
-
cacheWrites.push({
|
|
6208
|
-
result: result.data,
|
|
6209
|
-
dataId: "ROOT_MUTATION",
|
|
6210
|
-
query: mutation.document,
|
|
6211
|
-
variables: mutation.variables,
|
|
6194
|
+
if (legacyQueryOptions.size) {
|
|
6195
|
+
legacyQueryOptions.forEach(function (options) {
|
|
6196
|
+
var queryId = makeUniqueId("legacyOneTimeQuery");
|
|
6197
|
+
var queryInfo = _this.getQuery(queryId).init({
|
|
6198
|
+
document: options.query,
|
|
6199
|
+
variables: options.variables,
|
|
6212
6200
|
});
|
|
6213
|
-
|
|
6214
|
-
|
|
6215
|
-
|
|
6216
|
-
|
|
6217
|
-
id: "ROOT_MUTATION",
|
|
6218
|
-
query: this.getDocumentInfo(mutation.document).asQuery,
|
|
6219
|
-
variables: mutation.variables,
|
|
6220
|
-
optimistic: false,
|
|
6221
|
-
returnPartialData: true,
|
|
6201
|
+
var oq = new ObservableQuery({
|
|
6202
|
+
queryManager: _this,
|
|
6203
|
+
queryInfo: queryInfo,
|
|
6204
|
+
options: tslib.__assign(tslib.__assign({}, options), { fetchPolicy: "network-only" }),
|
|
6222
6205
|
});
|
|
6223
|
-
|
|
6224
|
-
|
|
6225
|
-
|
|
6226
|
-
|
|
6227
|
-
|
|
6228
|
-
|
|
6229
|
-
|
|
6230
|
-
|
|
6231
|
-
|
|
6232
|
-
query: mutation.document,
|
|
6233
|
-
variables: mutation.variables,
|
|
6234
|
-
});
|
|
6206
|
+
invariant(oq.queryId === queryId);
|
|
6207
|
+
queryInfo.setObservableQuery(oq);
|
|
6208
|
+
queries.set(queryId, oq);
|
|
6209
|
+
});
|
|
6210
|
+
}
|
|
6211
|
+
if (globalThis.__DEV__ !== false && queryNamesAndDocs.size) {
|
|
6212
|
+
queryNamesAndDocs.forEach(function (included, nameOrDoc) {
|
|
6213
|
+
if (!included) {
|
|
6214
|
+
globalThis.__DEV__ !== false && invariant.warn(typeof nameOrDoc === "string" ? 33 : 34, nameOrDoc);
|
|
6235
6215
|
}
|
|
6216
|
+
});
|
|
6217
|
+
}
|
|
6218
|
+
return queries;
|
|
6219
|
+
};
|
|
6220
|
+
QueryManager.prototype.reFetchObservableQueries = function (includeStandby) {
|
|
6221
|
+
var _this = this;
|
|
6222
|
+
if (includeStandby === void 0) { includeStandby = false; }
|
|
6223
|
+
var observableQueryPromises = [];
|
|
6224
|
+
this.getObservableQueries(includeStandby ? "all" : "active").forEach(function (observableQuery, queryId) {
|
|
6225
|
+
var fetchPolicy = observableQuery.options.fetchPolicy;
|
|
6226
|
+
observableQuery.resetLastResults();
|
|
6227
|
+
if (includeStandby ||
|
|
6228
|
+
(fetchPolicy !== "standby" && fetchPolicy !== "cache-only")) {
|
|
6229
|
+
observableQueryPromises.push(observableQuery.refetch());
|
|
6236
6230
|
}
|
|
6237
|
-
|
|
6238
|
-
|
|
6239
|
-
|
|
6240
|
-
|
|
6241
|
-
|
|
6242
|
-
|
|
6243
|
-
|
|
6244
|
-
|
|
6245
|
-
|
|
6246
|
-
|
|
6247
|
-
|
|
6248
|
-
|
|
6249
|
-
|
|
6250
|
-
|
|
6251
|
-
|
|
6252
|
-
|
|
6253
|
-
if (
|
|
6254
|
-
|
|
6255
|
-
|
|
6256
|
-
|
|
6257
|
-
|
|
6231
|
+
_this.getQuery(queryId).setDiff(null);
|
|
6232
|
+
});
|
|
6233
|
+
this.broadcastQueries();
|
|
6234
|
+
return Promise.all(observableQueryPromises);
|
|
6235
|
+
};
|
|
6236
|
+
QueryManager.prototype.setObservableQuery = function (observableQuery) {
|
|
6237
|
+
this.getQuery(observableQuery.queryId).setObservableQuery(observableQuery);
|
|
6238
|
+
};
|
|
6239
|
+
QueryManager.prototype.startGraphQLSubscription = function (_a) {
|
|
6240
|
+
var _this = this;
|
|
6241
|
+
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, _d = _a.extensions, extensions = _d === void 0 ? {} : _d;
|
|
6242
|
+
query = this.transform(query);
|
|
6243
|
+
variables = this.getVariables(query, variables);
|
|
6244
|
+
var makeObservable = function (variables) {
|
|
6245
|
+
return _this.getObservableFromLink(query, context, variables, extensions).map(function (result) {
|
|
6246
|
+
if (fetchPolicy !== "no-cache") {
|
|
6247
|
+
if (shouldWriteResult(result, errorPolicy)) {
|
|
6248
|
+
_this.cache.write({
|
|
6249
|
+
query: query,
|
|
6250
|
+
result: result.data,
|
|
6251
|
+
dataId: "ROOT_SUBSCRIPTION",
|
|
6252
|
+
variables: variables,
|
|
6258
6253
|
});
|
|
6259
|
-
if (nextQueryResult) {
|
|
6260
|
-
cacheWrites.push({
|
|
6261
|
-
result: nextQueryResult,
|
|
6262
|
-
dataId: "ROOT_QUERY",
|
|
6263
|
-
query: document,
|
|
6264
|
-
variables: variables,
|
|
6265
|
-
});
|
|
6266
|
-
}
|
|
6267
6254
|
}
|
|
6268
|
-
|
|
6269
|
-
|
|
6270
|
-
|
|
6271
|
-
|
|
6272
|
-
|
|
6273
|
-
|
|
6274
|
-
|
|
6275
|
-
|
|
6276
|
-
var results_1 = [];
|
|
6277
|
-
this.refetchQueries({
|
|
6278
|
-
updateCache: function (cache) {
|
|
6279
|
-
if (!skipCache) {
|
|
6280
|
-
cacheWrites.forEach(function (write) { return cache.write(write); });
|
|
6255
|
+
_this.broadcastQueries();
|
|
6256
|
+
}
|
|
6257
|
+
var hasErrors = graphQLResultHasError(result);
|
|
6258
|
+
var hasProtocolErrors = graphQLResultHasProtocolErrors(result);
|
|
6259
|
+
if (hasErrors || hasProtocolErrors) {
|
|
6260
|
+
var errors = {};
|
|
6261
|
+
if (hasErrors) {
|
|
6262
|
+
errors.graphQLErrors = result.errors;
|
|
6281
6263
|
}
|
|
6282
|
-
|
|
6283
|
-
|
|
6284
|
-
(isExecutionPatchIncrementalResult(result) && !result.hasNext);
|
|
6285
|
-
if (update) {
|
|
6286
|
-
if (!skipCache) {
|
|
6287
|
-
var diff = cache.diff({
|
|
6288
|
-
id: "ROOT_MUTATION",
|
|
6289
|
-
query: _this.getDocumentInfo(mutation.document).asQuery,
|
|
6290
|
-
variables: mutation.variables,
|
|
6291
|
-
optimistic: false,
|
|
6292
|
-
returnPartialData: true,
|
|
6293
|
-
});
|
|
6294
|
-
if (diff.complete) {
|
|
6295
|
-
result = tslib.__assign(tslib.__assign({}, result), { data: diff.result });
|
|
6296
|
-
if ("incremental" in result) {
|
|
6297
|
-
delete result.incremental;
|
|
6298
|
-
}
|
|
6299
|
-
if ("hasNext" in result) {
|
|
6300
|
-
delete result.hasNext;
|
|
6301
|
-
}
|
|
6302
|
-
}
|
|
6303
|
-
}
|
|
6304
|
-
if (isFinalResult) {
|
|
6305
|
-
update(cache, result, {
|
|
6306
|
-
context: mutation.context,
|
|
6307
|
-
variables: mutation.variables,
|
|
6308
|
-
});
|
|
6309
|
-
}
|
|
6264
|
+
if (hasProtocolErrors) {
|
|
6265
|
+
errors.protocolErrors = result.extensions[PROTOCOL_ERRORS_SYMBOL];
|
|
6310
6266
|
}
|
|
6311
|
-
if (
|
|
6312
|
-
|
|
6313
|
-
id: "ROOT_MUTATION",
|
|
6314
|
-
fields: function (value, _a) {
|
|
6315
|
-
var fieldName = _a.fieldName, DELETE = _a.DELETE;
|
|
6316
|
-
return fieldName === "__typename" ? value : DELETE;
|
|
6317
|
-
},
|
|
6318
|
-
});
|
|
6267
|
+
if (errorPolicy === "none" || hasProtocolErrors) {
|
|
6268
|
+
throw new ApolloError(errors);
|
|
6319
6269
|
}
|
|
6320
|
-
}
|
|
6321
|
-
|
|
6322
|
-
|
|
6323
|
-
|
|
6324
|
-
|
|
6325
|
-
})
|
|
6326
|
-
|
|
6327
|
-
|
|
6328
|
-
|
|
6329
|
-
|
|
6330
|
-
|
|
6331
|
-
|
|
6332
|
-
|
|
6333
|
-
|
|
6334
|
-
|
|
6335
|
-
|
|
6336
|
-
: optimisticResponse;
|
|
6337
|
-
if (data === IGNORE) {
|
|
6338
|
-
return false;
|
|
6270
|
+
}
|
|
6271
|
+
if (errorPolicy === "ignore") {
|
|
6272
|
+
delete result.errors;
|
|
6273
|
+
}
|
|
6274
|
+
return result;
|
|
6275
|
+
});
|
|
6276
|
+
};
|
|
6277
|
+
if (this.getDocumentInfo(query).hasClientExports) {
|
|
6278
|
+
var observablePromise_1 = this.localState
|
|
6279
|
+
.addExportedVariables(query, variables, context)
|
|
6280
|
+
.then(makeObservable);
|
|
6281
|
+
return new zenObservableTs.Observable(function (observer) {
|
|
6282
|
+
var sub = null;
|
|
6283
|
+
observablePromise_1.then(function (observable) { return (sub = observable.subscribe(observer)); }, observer.error);
|
|
6284
|
+
return function () { return sub && sub.unsubscribe(); };
|
|
6285
|
+
});
|
|
6339
6286
|
}
|
|
6340
|
-
|
|
6341
|
-
try {
|
|
6342
|
-
_this.markMutationResult(tslib.__assign(tslib.__assign({}, mutation), { result: { data: data } }), cache);
|
|
6343
|
-
}
|
|
6344
|
-
catch (error) {
|
|
6345
|
-
globalThis.__DEV__ !== false && invariant.error(error);
|
|
6346
|
-
}
|
|
6347
|
-
}, mutation.mutationId);
|
|
6348
|
-
return true;
|
|
6287
|
+
return makeObservable(variables);
|
|
6349
6288
|
};
|
|
6350
|
-
QueryManager.prototype.
|
|
6351
|
-
|
|
6352
|
-
|
|
6289
|
+
QueryManager.prototype.stopQuery = function (queryId) {
|
|
6290
|
+
this.stopQueryNoBroadcast(queryId);
|
|
6291
|
+
this.broadcastQueries();
|
|
6353
6292
|
};
|
|
6354
|
-
QueryManager.prototype.
|
|
6355
|
-
|
|
6356
|
-
this.
|
|
6357
|
-
store[queryId] = {
|
|
6358
|
-
variables: info.variables,
|
|
6359
|
-
networkStatus: info.networkStatus,
|
|
6360
|
-
networkError: info.networkError,
|
|
6361
|
-
graphQLErrors: info.graphQLErrors,
|
|
6362
|
-
};
|
|
6363
|
-
});
|
|
6364
|
-
return store;
|
|
6293
|
+
QueryManager.prototype.stopQueryNoBroadcast = function (queryId) {
|
|
6294
|
+
this.stopQueryInStoreNoBroadcast(queryId);
|
|
6295
|
+
this.removeQuery(queryId);
|
|
6365
6296
|
};
|
|
6366
|
-
QueryManager.prototype.
|
|
6367
|
-
|
|
6368
|
-
if (
|
|
6369
|
-
|
|
6370
|
-
|
|
6297
|
+
QueryManager.prototype.removeQuery = function (queryId) {
|
|
6298
|
+
this.fetchCancelFns.delete(queryId);
|
|
6299
|
+
if (this.queries.has(queryId)) {
|
|
6300
|
+
this.getQuery(queryId).stop();
|
|
6301
|
+
this.queries.delete(queryId);
|
|
6371
6302
|
}
|
|
6372
6303
|
};
|
|
6373
|
-
QueryManager.prototype.
|
|
6374
|
-
|
|
6304
|
+
QueryManager.prototype.broadcastQueries = function () {
|
|
6305
|
+
if (this.onBroadcast)
|
|
6306
|
+
this.onBroadcast();
|
|
6307
|
+
this.queries.forEach(function (info) { return info.notify(); });
|
|
6375
6308
|
};
|
|
6376
|
-
QueryManager.prototype.
|
|
6377
|
-
|
|
6378
|
-
|
|
6379
|
-
|
|
6380
|
-
|
|
6381
|
-
|
|
6382
|
-
|
|
6383
|
-
|
|
6384
|
-
|
|
6385
|
-
|
|
6386
|
-
|
|
6387
|
-
|
|
6388
|
-
|
|
6389
|
-
|
|
6390
|
-
|
|
6391
|
-
|
|
6392
|
-
|
|
6393
|
-
|
|
6394
|
-
}
|
|
6395
|
-
return def;
|
|
6396
|
-
}) }),
|
|
6309
|
+
QueryManager.prototype.getLocalState = function () {
|
|
6310
|
+
return this.localState;
|
|
6311
|
+
};
|
|
6312
|
+
QueryManager.prototype.getObservableFromLink = function (query, context, variables, extensions,
|
|
6313
|
+
deduplication) {
|
|
6314
|
+
var _this = this;
|
|
6315
|
+
var _a;
|
|
6316
|
+
if (deduplication === void 0) { deduplication = (_a = context === null || context === void 0 ? void 0 : context.queryDeduplication) !== null && _a !== void 0 ? _a : this.queryDeduplication; }
|
|
6317
|
+
var observable;
|
|
6318
|
+
var _b = this.getDocumentInfo(query), serverQuery = _b.serverQuery, clientQuery = _b.clientQuery;
|
|
6319
|
+
if (serverQuery) {
|
|
6320
|
+
var _c = this, inFlightLinkObservables_1 = _c.inFlightLinkObservables, link = _c.link;
|
|
6321
|
+
var operation = {
|
|
6322
|
+
query: serverQuery,
|
|
6323
|
+
variables: variables,
|
|
6324
|
+
operationName: getOperationName(serverQuery) || void 0,
|
|
6325
|
+
context: this.prepareContext(tslib.__assign(tslib.__assign({}, context), { forceFetch: !deduplication })),
|
|
6326
|
+
extensions: extensions,
|
|
6397
6327
|
};
|
|
6398
|
-
|
|
6328
|
+
context = operation.context;
|
|
6329
|
+
if (deduplication) {
|
|
6330
|
+
var printedServerQuery_1 = print(serverQuery);
|
|
6331
|
+
var varJson_1 = canonicalStringify(variables);
|
|
6332
|
+
var entry = inFlightLinkObservables_1.lookup(printedServerQuery_1, varJson_1);
|
|
6333
|
+
observable = entry.observable;
|
|
6334
|
+
if (!observable) {
|
|
6335
|
+
var concast = new Concast([
|
|
6336
|
+
execute(link, operation),
|
|
6337
|
+
]);
|
|
6338
|
+
observable = entry.observable = concast;
|
|
6339
|
+
concast.beforeNext(function () {
|
|
6340
|
+
inFlightLinkObservables_1.remove(printedServerQuery_1, varJson_1);
|
|
6341
|
+
});
|
|
6342
|
+
}
|
|
6343
|
+
}
|
|
6344
|
+
else {
|
|
6345
|
+
observable = new Concast([
|
|
6346
|
+
execute(link, operation),
|
|
6347
|
+
]);
|
|
6348
|
+
}
|
|
6399
6349
|
}
|
|
6400
|
-
|
|
6401
|
-
|
|
6402
|
-
|
|
6403
|
-
return tslib.__assign(tslib.__assign({}, this.getDocumentInfo(document).defaultVars), variables);
|
|
6404
|
-
};
|
|
6405
|
-
QueryManager.prototype.watchQuery = function (options) {
|
|
6406
|
-
var query = this.transform(options.query);
|
|
6407
|
-
options = tslib.__assign(tslib.__assign({}, options), { variables: this.getVariables(query, options.variables) });
|
|
6408
|
-
if (typeof options.notifyOnNetworkStatusChange === "undefined") {
|
|
6409
|
-
options.notifyOnNetworkStatusChange = false;
|
|
6350
|
+
else {
|
|
6351
|
+
observable = new Concast([zenObservableTs.Observable.of({ data: {} })]);
|
|
6352
|
+
context = this.prepareContext(context);
|
|
6410
6353
|
}
|
|
6411
|
-
|
|
6412
|
-
|
|
6413
|
-
|
|
6414
|
-
|
|
6415
|
-
|
|
6416
|
-
|
|
6417
|
-
|
|
6418
|
-
|
|
6419
|
-
|
|
6420
|
-
|
|
6421
|
-
|
|
6422
|
-
|
|
6354
|
+
if (clientQuery) {
|
|
6355
|
+
observable = asyncMap(observable, function (result) {
|
|
6356
|
+
return _this.localState.runResolvers({
|
|
6357
|
+
document: clientQuery,
|
|
6358
|
+
remoteResult: result,
|
|
6359
|
+
context: context,
|
|
6360
|
+
variables: variables,
|
|
6361
|
+
});
|
|
6362
|
+
});
|
|
6363
|
+
}
|
|
6364
|
+
return observable;
|
|
6365
|
+
};
|
|
6366
|
+
QueryManager.prototype.getResultsFromLink = function (queryInfo, cacheWriteBehavior, options) {
|
|
6367
|
+
var requestId = (queryInfo.lastRequestId = this.generateRequestId());
|
|
6368
|
+
var linkDocument = this.cache.transformForLink(options.query);
|
|
6369
|
+
return asyncMap(this.getObservableFromLink(linkDocument, options.context, options.variables), function (result) {
|
|
6370
|
+
var graphQLErrors = getGraphQLErrorsFromResult(result);
|
|
6371
|
+
var hasErrors = graphQLErrors.length > 0;
|
|
6372
|
+
if (requestId >= queryInfo.lastRequestId) {
|
|
6373
|
+
if (hasErrors && options.errorPolicy === "none") {
|
|
6374
|
+
throw queryInfo.markError(new ApolloError({
|
|
6375
|
+
graphQLErrors: graphQLErrors,
|
|
6376
|
+
}));
|
|
6377
|
+
}
|
|
6378
|
+
queryInfo.markResult(result, linkDocument, options, cacheWriteBehavior);
|
|
6379
|
+
queryInfo.markReady();
|
|
6380
|
+
}
|
|
6381
|
+
var aqr = {
|
|
6382
|
+
data: result.data,
|
|
6383
|
+
loading: false,
|
|
6384
|
+
networkStatus: exports.NetworkStatus.ready,
|
|
6385
|
+
};
|
|
6386
|
+
if (hasErrors && options.errorPolicy !== "ignore") {
|
|
6387
|
+
aqr.errors = graphQLErrors;
|
|
6388
|
+
aqr.networkStatus = exports.NetworkStatus.error;
|
|
6389
|
+
}
|
|
6390
|
+
return aqr;
|
|
6391
|
+
}, function (networkError) {
|
|
6392
|
+
var error = isApolloError(networkError) ? networkError : (new ApolloError({ networkError: networkError }));
|
|
6393
|
+
if (requestId >= queryInfo.lastRequestId) {
|
|
6394
|
+
queryInfo.markError(error);
|
|
6395
|
+
}
|
|
6396
|
+
throw error;
|
|
6423
6397
|
});
|
|
6424
|
-
return observable;
|
|
6425
6398
|
};
|
|
6426
|
-
QueryManager.prototype.
|
|
6399
|
+
QueryManager.prototype.fetchConcastWithInfo = function (queryId, options,
|
|
6400
|
+
networkStatus, query) {
|
|
6427
6401
|
var _this = this;
|
|
6428
|
-
if (
|
|
6429
|
-
|
|
6430
|
-
|
|
6431
|
-
|
|
6432
|
-
|
|
6433
|
-
|
|
6434
|
-
|
|
6435
|
-
|
|
6436
|
-
|
|
6437
|
-
|
|
6438
|
-
|
|
6439
|
-
|
|
6440
|
-
|
|
6441
|
-
|
|
6442
|
-
|
|
6443
|
-
|
|
6444
|
-
|
|
6445
|
-
|
|
6446
|
-
|
|
6447
|
-
|
|
6448
|
-
|
|
6449
|
-
|
|
6450
|
-
|
|
6451
|
-
queryInfo.stop();
|
|
6452
|
-
};
|
|
6453
|
-
QueryManager.prototype.clearStore = function (options) {
|
|
6454
|
-
if (options === void 0) { options = {
|
|
6455
|
-
discardWatches: true,
|
|
6456
|
-
}; }
|
|
6457
|
-
this.cancelPendingFetches(newInvariantError(32));
|
|
6458
|
-
this.queries.forEach(function (queryInfo) {
|
|
6459
|
-
if (queryInfo.observableQuery) {
|
|
6460
|
-
queryInfo.networkStatus = exports.NetworkStatus.loading;
|
|
6461
|
-
}
|
|
6462
|
-
else {
|
|
6463
|
-
queryInfo.stop();
|
|
6402
|
+
if (networkStatus === void 0) { networkStatus = exports.NetworkStatus.loading; }
|
|
6403
|
+
if (query === void 0) { query = options.query; }
|
|
6404
|
+
var variables = this.getVariables(query, options.variables);
|
|
6405
|
+
var queryInfo = this.getQuery(queryId);
|
|
6406
|
+
var defaults = this.defaultOptions.watchQuery;
|
|
6407
|
+
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;
|
|
6408
|
+
var normalized = Object.assign({}, options, {
|
|
6409
|
+
query: query,
|
|
6410
|
+
variables: variables,
|
|
6411
|
+
fetchPolicy: fetchPolicy,
|
|
6412
|
+
errorPolicy: errorPolicy,
|
|
6413
|
+
returnPartialData: returnPartialData,
|
|
6414
|
+
notifyOnNetworkStatusChange: notifyOnNetworkStatusChange,
|
|
6415
|
+
context: context,
|
|
6416
|
+
});
|
|
6417
|
+
var fromVariables = function (variables) {
|
|
6418
|
+
normalized.variables = variables;
|
|
6419
|
+
var sourcesWithInfo = _this.fetchQueryByPolicy(queryInfo, normalized, networkStatus);
|
|
6420
|
+
if (
|
|
6421
|
+
normalized.fetchPolicy !== "standby" &&
|
|
6422
|
+
sourcesWithInfo.sources.length > 0 &&
|
|
6423
|
+
queryInfo.observableQuery) {
|
|
6424
|
+
queryInfo.observableQuery["applyNextFetchPolicy"]("after-fetch", options);
|
|
6464
6425
|
}
|
|
6426
|
+
return sourcesWithInfo;
|
|
6427
|
+
};
|
|
6428
|
+
var cleanupCancelFn = function () { return _this.fetchCancelFns.delete(queryId); };
|
|
6429
|
+
this.fetchCancelFns.set(queryId, function (reason) {
|
|
6430
|
+
cleanupCancelFn();
|
|
6431
|
+
setTimeout(function () { return concast.cancel(reason); });
|
|
6465
6432
|
});
|
|
6466
|
-
|
|
6467
|
-
|
|
6433
|
+
var concast, containsDataFromLink;
|
|
6434
|
+
if (this.getDocumentInfo(normalized.query).hasClientExports) {
|
|
6435
|
+
concast = new Concast(this.localState
|
|
6436
|
+
.addExportedVariables(normalized.query, normalized.variables, normalized.context)
|
|
6437
|
+
.then(fromVariables)
|
|
6438
|
+
.then(function (sourcesWithInfo) { return sourcesWithInfo.sources; }));
|
|
6439
|
+
containsDataFromLink = true;
|
|
6468
6440
|
}
|
|
6469
|
-
|
|
6441
|
+
else {
|
|
6442
|
+
var sourcesWithInfo = fromVariables(normalized.variables);
|
|
6443
|
+
containsDataFromLink = sourcesWithInfo.fromLink;
|
|
6444
|
+
concast = new Concast(sourcesWithInfo.sources);
|
|
6445
|
+
}
|
|
6446
|
+
concast.promise.then(cleanupCancelFn, cleanupCancelFn);
|
|
6447
|
+
return {
|
|
6448
|
+
concast: concast,
|
|
6449
|
+
fromLink: containsDataFromLink,
|
|
6450
|
+
};
|
|
6470
6451
|
};
|
|
6471
|
-
QueryManager.prototype.
|
|
6452
|
+
QueryManager.prototype.refetchQueries = function (_a) {
|
|
6472
6453
|
var _this = this;
|
|
6473
|
-
|
|
6474
|
-
var
|
|
6475
|
-
|
|
6476
|
-
|
|
6477
|
-
|
|
6478
|
-
|
|
6479
|
-
|
|
6480
|
-
|
|
6454
|
+
var updateCache = _a.updateCache, include = _a.include, _b = _a.optimistic, optimistic = _b === void 0 ? false : _b, _c = _a.removeOptimistic, removeOptimistic = _c === void 0 ? optimistic ? makeUniqueId("refetchQueries") : void 0 : _c, onQueryUpdated = _a.onQueryUpdated;
|
|
6455
|
+
var includedQueriesById = new Map();
|
|
6456
|
+
if (include) {
|
|
6457
|
+
this.getObservableQueries(include).forEach(function (oq, queryId) {
|
|
6458
|
+
includedQueriesById.set(queryId, {
|
|
6459
|
+
oq: oq,
|
|
6460
|
+
lastDiff: _this.getQuery(queryId).getDiff(),
|
|
6461
|
+
});
|
|
6462
|
+
});
|
|
6463
|
+
}
|
|
6464
|
+
var results = new Map();
|
|
6465
|
+
if (updateCache) {
|
|
6466
|
+
this.cache.batch({
|
|
6467
|
+
update: updateCache,
|
|
6468
|
+
optimistic: (optimistic && removeOptimistic) || false,
|
|
6469
|
+
removeOptimistic: removeOptimistic,
|
|
6470
|
+
onWatchUpdated: function (watch, diff, lastDiff) {
|
|
6471
|
+
var oq = watch.watcher instanceof QueryInfo && watch.watcher.observableQuery;
|
|
6472
|
+
if (oq) {
|
|
6473
|
+
if (onQueryUpdated) {
|
|
6474
|
+
includedQueriesById.delete(oq.queryId);
|
|
6475
|
+
var result = onQueryUpdated(oq, diff, lastDiff);
|
|
6476
|
+
if (result === true) {
|
|
6477
|
+
result = oq.refetch();
|
|
6478
|
+
}
|
|
6479
|
+
if (result !== false) {
|
|
6480
|
+
results.set(oq, result);
|
|
6481
|
+
}
|
|
6482
|
+
return result;
|
|
6483
|
+
}
|
|
6484
|
+
if (onQueryUpdated !== null) {
|
|
6485
|
+
includedQueriesById.set(oq.queryId, { oq: oq, lastDiff: lastDiff, diff: diff });
|
|
6486
|
+
}
|
|
6487
|
+
}
|
|
6488
|
+
},
|
|
6489
|
+
});
|
|
6490
|
+
}
|
|
6491
|
+
if (includedQueriesById.size) {
|
|
6492
|
+
includedQueriesById.forEach(function (_a, queryId) {
|
|
6493
|
+
var oq = _a.oq, lastDiff = _a.lastDiff, diff = _a.diff;
|
|
6494
|
+
var result;
|
|
6495
|
+
if (onQueryUpdated) {
|
|
6496
|
+
if (!diff) {
|
|
6497
|
+
var info = oq["queryInfo"];
|
|
6498
|
+
info.reset();
|
|
6499
|
+
diff = info.getDiff();
|
|
6500
|
+
}
|
|
6501
|
+
result = onQueryUpdated(oq, diff, lastDiff);
|
|
6481
6502
|
}
|
|
6482
|
-
|
|
6483
|
-
|
|
6503
|
+
if (!onQueryUpdated || result === true) {
|
|
6504
|
+
result = oq.refetch();
|
|
6484
6505
|
}
|
|
6485
|
-
|
|
6486
|
-
|
|
6506
|
+
if (result !== false) {
|
|
6507
|
+
results.set(oq, result);
|
|
6508
|
+
}
|
|
6509
|
+
if (queryId.indexOf("legacyOneTimeQuery") >= 0) {
|
|
6510
|
+
_this.stopQueryNoBroadcast(queryId);
|
|
6487
6511
|
}
|
|
6488
6512
|
});
|
|
6489
6513
|
}
|
|
6490
|
-
|
|
6491
|
-
|
|
6492
|
-
|
|
6493
|
-
|
|
6494
|
-
|
|
6495
|
-
|
|
6514
|
+
if (removeOptimistic) {
|
|
6515
|
+
this.cache.removeOptimistic(removeOptimistic);
|
|
6516
|
+
}
|
|
6517
|
+
return results;
|
|
6518
|
+
};
|
|
6519
|
+
QueryManager.prototype.fetchQueryByPolicy = function (queryInfo, _a,
|
|
6520
|
+
networkStatus) {
|
|
6521
|
+
var _this = this;
|
|
6522
|
+
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;
|
|
6523
|
+
var oldNetworkStatus = queryInfo.networkStatus;
|
|
6524
|
+
queryInfo.init({
|
|
6525
|
+
document: query,
|
|
6526
|
+
variables: variables,
|
|
6527
|
+
networkStatus: networkStatus,
|
|
6528
|
+
});
|
|
6529
|
+
var readCache = function () { return queryInfo.getDiff(); };
|
|
6530
|
+
var resultsFromCache = function (diff, networkStatus) {
|
|
6531
|
+
if (networkStatus === void 0) { networkStatus = queryInfo.networkStatus || exports.NetworkStatus.loading; }
|
|
6532
|
+
var data = diff.result;
|
|
6533
|
+
if (globalThis.__DEV__ !== false && !returnPartialData && !equal.equal(data, {})) {
|
|
6534
|
+
logMissingFieldErrors(diff.missing);
|
|
6535
|
+
}
|
|
6536
|
+
var fromData = function (data) {
|
|
6537
|
+
return zenObservableTs.Observable.of(tslib.__assign({ data: data, loading: isNetworkRequestInFlight(networkStatus), networkStatus: networkStatus }, (diff.complete ? null : { partial: true })));
|
|
6538
|
+
};
|
|
6539
|
+
if (data && _this.getDocumentInfo(query).hasForcedResolvers) {
|
|
6540
|
+
return _this.localState
|
|
6541
|
+
.runResolvers({
|
|
6542
|
+
document: query,
|
|
6543
|
+
remoteResult: { data: data },
|
|
6544
|
+
context: context,
|
|
6545
|
+
variables: variables,
|
|
6546
|
+
onlyRunForcedResolvers: true,
|
|
6547
|
+
})
|
|
6548
|
+
.then(function (resolved) { return fromData(resolved.data || void 0); });
|
|
6549
|
+
}
|
|
6550
|
+
if (errorPolicy === "none" &&
|
|
6551
|
+
networkStatus === exports.NetworkStatus.refetch &&
|
|
6552
|
+
Array.isArray(diff.missing)) {
|
|
6553
|
+
return fromData(void 0);
|
|
6554
|
+
}
|
|
6555
|
+
return fromData(data);
|
|
6556
|
+
};
|
|
6557
|
+
var cacheWriteBehavior = fetchPolicy === "no-cache" ? 0
|
|
6558
|
+
: (networkStatus === exports.NetworkStatus.refetch &&
|
|
6559
|
+
refetchWritePolicy !== "merge") ?
|
|
6560
|
+
1
|
|
6561
|
+
: 2 ;
|
|
6562
|
+
var resultsFromLink = function () {
|
|
6563
|
+
return _this.getResultsFromLink(queryInfo, cacheWriteBehavior, {
|
|
6564
|
+
query: query,
|
|
6565
|
+
variables: variables,
|
|
6566
|
+
context: context,
|
|
6567
|
+
fetchPolicy: fetchPolicy,
|
|
6568
|
+
errorPolicy: errorPolicy,
|
|
6569
|
+
});
|
|
6570
|
+
};
|
|
6571
|
+
var shouldNotify = notifyOnNetworkStatusChange &&
|
|
6572
|
+
typeof oldNetworkStatus === "number" &&
|
|
6573
|
+
oldNetworkStatus !== networkStatus &&
|
|
6574
|
+
isNetworkRequestInFlight(networkStatus);
|
|
6575
|
+
switch (fetchPolicy) {
|
|
6576
|
+
default:
|
|
6577
|
+
case "cache-first": {
|
|
6578
|
+
var diff = readCache();
|
|
6579
|
+
if (diff.complete) {
|
|
6580
|
+
return {
|
|
6581
|
+
fromLink: false,
|
|
6582
|
+
sources: [resultsFromCache(diff, queryInfo.markReady())],
|
|
6583
|
+
};
|
|
6496
6584
|
}
|
|
6497
|
-
|
|
6498
|
-
|
|
6499
|
-
|
|
6500
|
-
|
|
6585
|
+
if (returnPartialData || shouldNotify) {
|
|
6586
|
+
return {
|
|
6587
|
+
fromLink: true,
|
|
6588
|
+
sources: [resultsFromCache(diff), resultsFromLink()],
|
|
6589
|
+
};
|
|
6501
6590
|
}
|
|
6502
|
-
|
|
6503
|
-
|
|
6504
|
-
|
|
6505
|
-
|
|
6506
|
-
|
|
6507
|
-
|
|
6508
|
-
|
|
6509
|
-
|
|
6591
|
+
return { fromLink: true, sources: [resultsFromLink()] };
|
|
6592
|
+
}
|
|
6593
|
+
case "cache-and-network": {
|
|
6594
|
+
var diff = readCache();
|
|
6595
|
+
if (diff.complete || returnPartialData || shouldNotify) {
|
|
6596
|
+
return {
|
|
6597
|
+
fromLink: true,
|
|
6598
|
+
sources: [resultsFromCache(diff), resultsFromLink()],
|
|
6599
|
+
};
|
|
6510
6600
|
}
|
|
6601
|
+
return { fromLink: true, sources: [resultsFromLink()] };
|
|
6511
6602
|
}
|
|
6512
|
-
|
|
6513
|
-
|
|
6514
|
-
|
|
6515
|
-
|
|
6516
|
-
|
|
6517
|
-
|
|
6518
|
-
|
|
6519
|
-
|
|
6520
|
-
|
|
6521
|
-
|
|
6522
|
-
|
|
6523
|
-
options: tslib.__assign(tslib.__assign({}, options), { fetchPolicy: "network-only" }),
|
|
6524
|
-
});
|
|
6525
|
-
invariant(oq.queryId === queryId);
|
|
6526
|
-
queryInfo.setObservableQuery(oq);
|
|
6527
|
-
queries.set(queryId, oq);
|
|
6528
|
-
});
|
|
6529
|
-
}
|
|
6530
|
-
if (globalThis.__DEV__ !== false && queryNamesAndDocs.size) {
|
|
6531
|
-
queryNamesAndDocs.forEach(function (included, nameOrDoc) {
|
|
6532
|
-
if (!included) {
|
|
6533
|
-
globalThis.__DEV__ !== false && invariant.warn(typeof nameOrDoc === "string" ? 33 : 34, nameOrDoc);
|
|
6603
|
+
case "cache-only":
|
|
6604
|
+
return {
|
|
6605
|
+
fromLink: false,
|
|
6606
|
+
sources: [resultsFromCache(readCache(), queryInfo.markReady())],
|
|
6607
|
+
};
|
|
6608
|
+
case "network-only":
|
|
6609
|
+
if (shouldNotify) {
|
|
6610
|
+
return {
|
|
6611
|
+
fromLink: true,
|
|
6612
|
+
sources: [resultsFromCache(readCache()), resultsFromLink()],
|
|
6613
|
+
};
|
|
6534
6614
|
}
|
|
6535
|
-
|
|
6615
|
+
return { fromLink: true, sources: [resultsFromLink()] };
|
|
6616
|
+
case "no-cache":
|
|
6617
|
+
if (shouldNotify) {
|
|
6618
|
+
return {
|
|
6619
|
+
fromLink: true,
|
|
6620
|
+
sources: [resultsFromCache(queryInfo.getDiff()), resultsFromLink()],
|
|
6621
|
+
};
|
|
6622
|
+
}
|
|
6623
|
+
return { fromLink: true, sources: [resultsFromLink()] };
|
|
6624
|
+
case "standby":
|
|
6625
|
+
return { fromLink: false, sources: [] };
|
|
6536
6626
|
}
|
|
6537
|
-
return queries;
|
|
6538
6627
|
};
|
|
6539
|
-
QueryManager.prototype.
|
|
6540
|
-
|
|
6541
|
-
|
|
6542
|
-
|
|
6543
|
-
this.
|
|
6544
|
-
var fetchPolicy = observableQuery.options.fetchPolicy;
|
|
6545
|
-
observableQuery.resetLastResults();
|
|
6546
|
-
if (includeStandby ||
|
|
6547
|
-
(fetchPolicy !== "standby" && fetchPolicy !== "cache-only")) {
|
|
6548
|
-
observableQueryPromises.push(observableQuery.refetch());
|
|
6549
|
-
}
|
|
6550
|
-
_this.getQuery(queryId).setDiff(null);
|
|
6551
|
-
});
|
|
6552
|
-
this.broadcastQueries();
|
|
6553
|
-
return Promise.all(observableQueryPromises);
|
|
6628
|
+
QueryManager.prototype.getQuery = function (queryId) {
|
|
6629
|
+
if (queryId && !this.queries.has(queryId)) {
|
|
6630
|
+
this.queries.set(queryId, new QueryInfo(this, queryId));
|
|
6631
|
+
}
|
|
6632
|
+
return this.queries.get(queryId);
|
|
6554
6633
|
};
|
|
6555
|
-
QueryManager.prototype.
|
|
6556
|
-
|
|
6634
|
+
QueryManager.prototype.prepareContext = function (context) {
|
|
6635
|
+
if (context === void 0) { context = {}; }
|
|
6636
|
+
var newContext = this.localState.prepareContext(context);
|
|
6637
|
+
return tslib.__assign(tslib.__assign(tslib.__assign({}, this.defaultContext), newContext), { clientAwareness: this.clientAwareness });
|
|
6557
6638
|
};
|
|
6558
|
-
QueryManager
|
|
6639
|
+
return QueryManager;
|
|
6640
|
+
}());
|
|
6641
|
+
|
|
6642
|
+
var LocalState = (function () {
|
|
6643
|
+
function LocalState(_a) {
|
|
6644
|
+
var cache = _a.cache, client = _a.client, resolvers = _a.resolvers, fragmentMatcher = _a.fragmentMatcher;
|
|
6645
|
+
this.selectionsToResolveCache = new WeakMap();
|
|
6646
|
+
this.cache = cache;
|
|
6647
|
+
if (client) {
|
|
6648
|
+
this.client = client;
|
|
6649
|
+
}
|
|
6650
|
+
if (resolvers) {
|
|
6651
|
+
this.addResolvers(resolvers);
|
|
6652
|
+
}
|
|
6653
|
+
if (fragmentMatcher) {
|
|
6654
|
+
this.setFragmentMatcher(fragmentMatcher);
|
|
6655
|
+
}
|
|
6656
|
+
}
|
|
6657
|
+
LocalState.prototype.addResolvers = function (resolvers) {
|
|
6559
6658
|
var _this = this;
|
|
6560
|
-
|
|
6561
|
-
|
|
6562
|
-
|
|
6563
|
-
|
|
6564
|
-
return _this.getObservableFromLink(query, context, variables, extensions).map(function (result) {
|
|
6565
|
-
if (fetchPolicy !== "no-cache") {
|
|
6566
|
-
if (shouldWriteResult(result, errorPolicy)) {
|
|
6567
|
-
_this.cache.write({
|
|
6568
|
-
query: query,
|
|
6569
|
-
result: result.data,
|
|
6570
|
-
dataId: "ROOT_SUBSCRIPTION",
|
|
6571
|
-
variables: variables,
|
|
6572
|
-
});
|
|
6573
|
-
}
|
|
6574
|
-
_this.broadcastQueries();
|
|
6575
|
-
}
|
|
6576
|
-
var hasErrors = graphQLResultHasError(result);
|
|
6577
|
-
var hasProtocolErrors = graphQLResultHasProtocolErrors(result);
|
|
6578
|
-
if (hasErrors || hasProtocolErrors) {
|
|
6579
|
-
var errors = {};
|
|
6580
|
-
if (hasErrors) {
|
|
6581
|
-
errors.graphQLErrors = result.errors;
|
|
6582
|
-
}
|
|
6583
|
-
if (hasProtocolErrors) {
|
|
6584
|
-
errors.protocolErrors = result.extensions[PROTOCOL_ERRORS_SYMBOL];
|
|
6585
|
-
}
|
|
6586
|
-
if (errorPolicy === "none" || hasProtocolErrors) {
|
|
6587
|
-
throw new ApolloError(errors);
|
|
6588
|
-
}
|
|
6589
|
-
}
|
|
6590
|
-
if (errorPolicy === "ignore") {
|
|
6591
|
-
delete result.errors;
|
|
6592
|
-
}
|
|
6593
|
-
return result;
|
|
6594
|
-
});
|
|
6595
|
-
};
|
|
6596
|
-
if (this.getDocumentInfo(query).hasClientExports) {
|
|
6597
|
-
var observablePromise_1 = this.localState
|
|
6598
|
-
.addExportedVariables(query, variables, context)
|
|
6599
|
-
.then(makeObservable);
|
|
6600
|
-
return new zenObservableTs.Observable(function (observer) {
|
|
6601
|
-
var sub = null;
|
|
6602
|
-
observablePromise_1.then(function (observable) { return (sub = observable.subscribe(observer)); }, observer.error);
|
|
6603
|
-
return function () { return sub && sub.unsubscribe(); };
|
|
6659
|
+
this.resolvers = this.resolvers || {};
|
|
6660
|
+
if (Array.isArray(resolvers)) {
|
|
6661
|
+
resolvers.forEach(function (resolverGroup) {
|
|
6662
|
+
_this.resolvers = mergeDeep(_this.resolvers, resolverGroup);
|
|
6604
6663
|
});
|
|
6605
6664
|
}
|
|
6606
|
-
|
|
6607
|
-
|
|
6608
|
-
QueryManager.prototype.stopQuery = function (queryId) {
|
|
6609
|
-
this.stopQueryNoBroadcast(queryId);
|
|
6610
|
-
this.broadcastQueries();
|
|
6611
|
-
};
|
|
6612
|
-
QueryManager.prototype.stopQueryNoBroadcast = function (queryId) {
|
|
6613
|
-
this.stopQueryInStoreNoBroadcast(queryId);
|
|
6614
|
-
this.removeQuery(queryId);
|
|
6615
|
-
};
|
|
6616
|
-
QueryManager.prototype.removeQuery = function (queryId) {
|
|
6617
|
-
this.fetchCancelFns.delete(queryId);
|
|
6618
|
-
if (this.queries.has(queryId)) {
|
|
6619
|
-
this.getQuery(queryId).stop();
|
|
6620
|
-
this.queries.delete(queryId);
|
|
6665
|
+
else {
|
|
6666
|
+
this.resolvers = mergeDeep(this.resolvers, resolvers);
|
|
6621
6667
|
}
|
|
6622
6668
|
};
|
|
6623
|
-
|
|
6624
|
-
|
|
6625
|
-
|
|
6626
|
-
this.queries.forEach(function (info) { return info.notify(); });
|
|
6669
|
+
LocalState.prototype.setResolvers = function (resolvers) {
|
|
6670
|
+
this.resolvers = {};
|
|
6671
|
+
this.addResolvers(resolvers);
|
|
6627
6672
|
};
|
|
6628
|
-
|
|
6629
|
-
return this.
|
|
6673
|
+
LocalState.prototype.getResolvers = function () {
|
|
6674
|
+
return this.resolvers || {};
|
|
6630
6675
|
};
|
|
6631
|
-
|
|
6632
|
-
|
|
6633
|
-
|
|
6634
|
-
|
|
6635
|
-
|
|
6636
|
-
|
|
6637
|
-
var _b = this.getDocumentInfo(query), serverQuery = _b.serverQuery, clientQuery = _b.clientQuery;
|
|
6638
|
-
if (serverQuery) {
|
|
6639
|
-
var _c = this, inFlightLinkObservables_1 = _c.inFlightLinkObservables, link = _c.link;
|
|
6640
|
-
var operation = {
|
|
6641
|
-
query: serverQuery,
|
|
6642
|
-
variables: variables,
|
|
6643
|
-
operationName: getOperationName(serverQuery) || void 0,
|
|
6644
|
-
context: this.prepareContext(tslib.__assign(tslib.__assign({}, context), { forceFetch: !deduplication })),
|
|
6645
|
-
extensions: extensions,
|
|
6646
|
-
};
|
|
6647
|
-
context = operation.context;
|
|
6648
|
-
if (deduplication) {
|
|
6649
|
-
var printedServerQuery_1 = print(serverQuery);
|
|
6650
|
-
var varJson_1 = canonicalStringify(variables);
|
|
6651
|
-
var entry = inFlightLinkObservables_1.lookup(printedServerQuery_1, varJson_1);
|
|
6652
|
-
observable = entry.observable;
|
|
6653
|
-
if (!observable) {
|
|
6654
|
-
var concast = new Concast([
|
|
6655
|
-
execute(link, operation),
|
|
6656
|
-
]);
|
|
6657
|
-
observable = entry.observable = concast;
|
|
6658
|
-
concast.beforeNext(function () {
|
|
6659
|
-
inFlightLinkObservables_1.remove(printedServerQuery_1, varJson_1);
|
|
6660
|
-
});
|
|
6676
|
+
LocalState.prototype.runResolvers = function (_a) {
|
|
6677
|
+
return tslib.__awaiter(this, arguments, void 0, function (_b) {
|
|
6678
|
+
var document = _b.document, remoteResult = _b.remoteResult, context = _b.context, variables = _b.variables, _c = _b.onlyRunForcedResolvers, onlyRunForcedResolvers = _c === void 0 ? false : _c;
|
|
6679
|
+
return tslib.__generator(this, function (_d) {
|
|
6680
|
+
if (document) {
|
|
6681
|
+
return [2 , this.resolveDocument(document, remoteResult.data, context, variables, this.fragmentMatcher, onlyRunForcedResolvers).then(function (localResult) { return (tslib.__assign(tslib.__assign({}, remoteResult), { data: localResult.result })); })];
|
|
6661
6682
|
}
|
|
6662
|
-
|
|
6663
|
-
else {
|
|
6664
|
-
observable = new Concast([
|
|
6665
|
-
execute(link, operation),
|
|
6666
|
-
]);
|
|
6667
|
-
}
|
|
6668
|
-
}
|
|
6669
|
-
else {
|
|
6670
|
-
observable = new Concast([zenObservableTs.Observable.of({ data: {} })]);
|
|
6671
|
-
context = this.prepareContext(context);
|
|
6672
|
-
}
|
|
6673
|
-
if (clientQuery) {
|
|
6674
|
-
observable = asyncMap(observable, function (result) {
|
|
6675
|
-
return _this.localState.runResolvers({
|
|
6676
|
-
document: clientQuery,
|
|
6677
|
-
remoteResult: result,
|
|
6678
|
-
context: context,
|
|
6679
|
-
variables: variables,
|
|
6680
|
-
});
|
|
6683
|
+
return [2 , remoteResult];
|
|
6681
6684
|
});
|
|
6685
|
+
});
|
|
6686
|
+
};
|
|
6687
|
+
LocalState.prototype.setFragmentMatcher = function (fragmentMatcher) {
|
|
6688
|
+
this.fragmentMatcher = fragmentMatcher;
|
|
6689
|
+
};
|
|
6690
|
+
LocalState.prototype.getFragmentMatcher = function () {
|
|
6691
|
+
return this.fragmentMatcher;
|
|
6692
|
+
};
|
|
6693
|
+
LocalState.prototype.clientQuery = function (document) {
|
|
6694
|
+
if (hasDirectives(["client"], document)) {
|
|
6695
|
+
if (this.resolvers) {
|
|
6696
|
+
return document;
|
|
6697
|
+
}
|
|
6682
6698
|
}
|
|
6683
|
-
return
|
|
6699
|
+
return null;
|
|
6684
6700
|
};
|
|
6685
|
-
|
|
6686
|
-
|
|
6687
|
-
|
|
6688
|
-
|
|
6689
|
-
|
|
6690
|
-
|
|
6691
|
-
|
|
6692
|
-
|
|
6693
|
-
|
|
6694
|
-
|
|
6695
|
-
|
|
6701
|
+
LocalState.prototype.serverQuery = function (document) {
|
|
6702
|
+
return removeClientSetsFromDocument(document);
|
|
6703
|
+
};
|
|
6704
|
+
LocalState.prototype.prepareContext = function (context) {
|
|
6705
|
+
var cache = this.cache;
|
|
6706
|
+
return tslib.__assign(tslib.__assign({}, context), { cache: cache,
|
|
6707
|
+
getCacheKey: function (obj) {
|
|
6708
|
+
return cache.identify(obj);
|
|
6709
|
+
} });
|
|
6710
|
+
};
|
|
6711
|
+
LocalState.prototype.addExportedVariables = function (document_1) {
|
|
6712
|
+
return tslib.__awaiter(this, arguments, void 0, function (document, variables, context) {
|
|
6713
|
+
if (variables === void 0) { variables = {}; }
|
|
6714
|
+
if (context === void 0) { context = {}; }
|
|
6715
|
+
return tslib.__generator(this, function (_a) {
|
|
6716
|
+
if (document) {
|
|
6717
|
+
return [2 , this.resolveDocument(document, this.buildRootValueFromCache(document, variables) || {}, this.prepareContext(context), variables).then(function (data) { return (tslib.__assign(tslib.__assign({}, variables), data.exportedVariables)); })];
|
|
6696
6718
|
}
|
|
6697
|
-
|
|
6698
|
-
|
|
6699
|
-
}
|
|
6700
|
-
var aqr = {
|
|
6701
|
-
data: result.data,
|
|
6702
|
-
loading: false,
|
|
6703
|
-
networkStatus: exports.NetworkStatus.ready,
|
|
6704
|
-
};
|
|
6705
|
-
if (hasErrors && options.errorPolicy !== "ignore") {
|
|
6706
|
-
aqr.errors = graphQLErrors;
|
|
6707
|
-
aqr.networkStatus = exports.NetworkStatus.error;
|
|
6708
|
-
}
|
|
6709
|
-
return aqr;
|
|
6710
|
-
}, function (networkError) {
|
|
6711
|
-
var error = isApolloError(networkError) ? networkError : (new ApolloError({ networkError: networkError }));
|
|
6712
|
-
if (requestId >= queryInfo.lastRequestId) {
|
|
6713
|
-
queryInfo.markError(error);
|
|
6714
|
-
}
|
|
6715
|
-
throw error;
|
|
6719
|
+
return [2 , tslib.__assign({}, variables)];
|
|
6720
|
+
});
|
|
6716
6721
|
});
|
|
6717
6722
|
};
|
|
6718
|
-
|
|
6719
|
-
|
|
6720
|
-
|
|
6721
|
-
|
|
6722
|
-
|
|
6723
|
-
|
|
6724
|
-
|
|
6725
|
-
|
|
6726
|
-
|
|
6727
|
-
|
|
6728
|
-
|
|
6729
|
-
|
|
6730
|
-
|
|
6731
|
-
|
|
6732
|
-
|
|
6733
|
-
|
|
6734
|
-
|
|
6735
|
-
});
|
|
6736
|
-
var fromVariables = function (variables) {
|
|
6737
|
-
normalized.variables = variables;
|
|
6738
|
-
var sourcesWithInfo = _this.fetchQueryByPolicy(queryInfo, normalized, networkStatus);
|
|
6739
|
-
if (
|
|
6740
|
-
normalized.fetchPolicy !== "standby" &&
|
|
6741
|
-
sourcesWithInfo.sources.length > 0 &&
|
|
6742
|
-
queryInfo.observableQuery) {
|
|
6743
|
-
queryInfo.observableQuery["applyNextFetchPolicy"]("after-fetch", options);
|
|
6744
|
-
}
|
|
6745
|
-
return sourcesWithInfo;
|
|
6746
|
-
};
|
|
6747
|
-
var cleanupCancelFn = function () { return _this.fetchCancelFns.delete(queryId); };
|
|
6748
|
-
this.fetchCancelFns.set(queryId, function (reason) {
|
|
6749
|
-
cleanupCancelFn();
|
|
6750
|
-
setTimeout(function () { return concast.cancel(reason); });
|
|
6723
|
+
LocalState.prototype.shouldForceResolvers = function (document) {
|
|
6724
|
+
var forceResolvers = false;
|
|
6725
|
+
graphql.visit(document, {
|
|
6726
|
+
Directive: {
|
|
6727
|
+
enter: function (node) {
|
|
6728
|
+
if (node.name.value === "client" && node.arguments) {
|
|
6729
|
+
forceResolvers = node.arguments.some(function (arg) {
|
|
6730
|
+
return arg.name.value === "always" &&
|
|
6731
|
+
arg.value.kind === "BooleanValue" &&
|
|
6732
|
+
arg.value.value === true;
|
|
6733
|
+
});
|
|
6734
|
+
if (forceResolvers) {
|
|
6735
|
+
return graphql.BREAK;
|
|
6736
|
+
}
|
|
6737
|
+
}
|
|
6738
|
+
},
|
|
6739
|
+
},
|
|
6751
6740
|
});
|
|
6752
|
-
|
|
6753
|
-
if (this.getDocumentInfo(normalized.query).hasClientExports) {
|
|
6754
|
-
concast = new Concast(this.localState
|
|
6755
|
-
.addExportedVariables(normalized.query, normalized.variables, normalized.context)
|
|
6756
|
-
.then(fromVariables)
|
|
6757
|
-
.then(function (sourcesWithInfo) { return sourcesWithInfo.sources; }));
|
|
6758
|
-
containsDataFromLink = true;
|
|
6759
|
-
}
|
|
6760
|
-
else {
|
|
6761
|
-
var sourcesWithInfo = fromVariables(normalized.variables);
|
|
6762
|
-
containsDataFromLink = sourcesWithInfo.fromLink;
|
|
6763
|
-
concast = new Concast(sourcesWithInfo.sources);
|
|
6764
|
-
}
|
|
6765
|
-
concast.promise.then(cleanupCancelFn, cleanupCancelFn);
|
|
6766
|
-
return {
|
|
6767
|
-
concast: concast,
|
|
6768
|
-
fromLink: containsDataFromLink,
|
|
6769
|
-
};
|
|
6741
|
+
return forceResolvers;
|
|
6770
6742
|
};
|
|
6771
|
-
|
|
6772
|
-
|
|
6773
|
-
|
|
6774
|
-
|
|
6775
|
-
|
|
6776
|
-
|
|
6777
|
-
|
|
6778
|
-
|
|
6779
|
-
|
|
6780
|
-
|
|
6743
|
+
LocalState.prototype.buildRootValueFromCache = function (document, variables) {
|
|
6744
|
+
return this.cache.diff({
|
|
6745
|
+
query: buildQueryFromSelectionSet(document),
|
|
6746
|
+
variables: variables,
|
|
6747
|
+
returnPartialData: true,
|
|
6748
|
+
optimistic: false,
|
|
6749
|
+
}).result;
|
|
6750
|
+
};
|
|
6751
|
+
LocalState.prototype.resolveDocument = function (document_1, rootValue_1) {
|
|
6752
|
+
return tslib.__awaiter(this, arguments, void 0, function (document, rootValue, context, variables, fragmentMatcher, onlyRunForcedResolvers) {
|
|
6753
|
+
var mainDefinition, fragments, fragmentMap, selectionsToResolve, definitionOperation, defaultOperationType, _a, cache, client, execContext, isClientFieldDescendant;
|
|
6754
|
+
if (context === void 0) { context = {}; }
|
|
6755
|
+
if (variables === void 0) { variables = {}; }
|
|
6756
|
+
if (fragmentMatcher === void 0) { fragmentMatcher = function () { return true; }; }
|
|
6757
|
+
if (onlyRunForcedResolvers === void 0) { onlyRunForcedResolvers = false; }
|
|
6758
|
+
return tslib.__generator(this, function (_b) {
|
|
6759
|
+
mainDefinition = getMainDefinition(document);
|
|
6760
|
+
fragments = getFragmentDefinitions(document);
|
|
6761
|
+
fragmentMap = createFragmentMap(fragments);
|
|
6762
|
+
selectionsToResolve = this.collectSelectionsToResolve(mainDefinition, fragmentMap);
|
|
6763
|
+
definitionOperation = mainDefinition.operation;
|
|
6764
|
+
defaultOperationType = definitionOperation ?
|
|
6765
|
+
definitionOperation.charAt(0).toUpperCase() +
|
|
6766
|
+
definitionOperation.slice(1)
|
|
6767
|
+
: "Query";
|
|
6768
|
+
_a = this, cache = _a.cache, client = _a.client;
|
|
6769
|
+
execContext = {
|
|
6770
|
+
fragmentMap: fragmentMap,
|
|
6771
|
+
context: tslib.__assign(tslib.__assign({}, context), { cache: cache, client: client }),
|
|
6772
|
+
variables: variables,
|
|
6773
|
+
fragmentMatcher: fragmentMatcher,
|
|
6774
|
+
defaultOperationType: defaultOperationType,
|
|
6775
|
+
exportedVariables: {},
|
|
6776
|
+
selectionsToResolve: selectionsToResolve,
|
|
6777
|
+
onlyRunForcedResolvers: onlyRunForcedResolvers,
|
|
6778
|
+
};
|
|
6779
|
+
isClientFieldDescendant = false;
|
|
6780
|
+
return [2 , this.resolveSelectionSet(mainDefinition.selectionSet, isClientFieldDescendant, rootValue, execContext).then(function (result) { return ({
|
|
6781
|
+
result: result,
|
|
6782
|
+
exportedVariables: execContext.exportedVariables,
|
|
6783
|
+
}); })];
|
|
6781
6784
|
});
|
|
6782
|
-
}
|
|
6783
|
-
|
|
6784
|
-
|
|
6785
|
-
|
|
6786
|
-
|
|
6787
|
-
|
|
6788
|
-
|
|
6789
|
-
|
|
6790
|
-
|
|
6791
|
-
|
|
6792
|
-
|
|
6793
|
-
|
|
6794
|
-
|
|
6795
|
-
|
|
6796
|
-
|
|
6797
|
-
}
|
|
6798
|
-
if (result !== false) {
|
|
6799
|
-
results.set(oq, result);
|
|
6800
|
-
}
|
|
6801
|
-
return result;
|
|
6785
|
+
});
|
|
6786
|
+
};
|
|
6787
|
+
LocalState.prototype.resolveSelectionSet = function (selectionSet, isClientFieldDescendant, rootValue, execContext) {
|
|
6788
|
+
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
6789
|
+
var fragmentMap, context, variables, resultsToMerge, execute;
|
|
6790
|
+
var _this = this;
|
|
6791
|
+
return tslib.__generator(this, function (_a) {
|
|
6792
|
+
fragmentMap = execContext.fragmentMap, context = execContext.context, variables = execContext.variables;
|
|
6793
|
+
resultsToMerge = [rootValue];
|
|
6794
|
+
execute = function (selection) { return tslib.__awaiter(_this, void 0, void 0, function () {
|
|
6795
|
+
var fragment, typeCondition;
|
|
6796
|
+
return tslib.__generator(this, function (_a) {
|
|
6797
|
+
if (!isClientFieldDescendant &&
|
|
6798
|
+
!execContext.selectionsToResolve.has(selection)) {
|
|
6799
|
+
return [2 ];
|
|
6802
6800
|
}
|
|
6803
|
-
if (
|
|
6804
|
-
|
|
6801
|
+
if (!shouldInclude(selection, variables)) {
|
|
6802
|
+
return [2 ];
|
|
6805
6803
|
}
|
|
6806
|
-
|
|
6807
|
-
|
|
6804
|
+
if (isField(selection)) {
|
|
6805
|
+
return [2 , this.resolveField(selection, isClientFieldDescendant, rootValue, execContext).then(function (fieldResult) {
|
|
6806
|
+
var _a;
|
|
6807
|
+
if (typeof fieldResult !== "undefined") {
|
|
6808
|
+
resultsToMerge.push((_a = {},
|
|
6809
|
+
_a[resultKeyNameFromField(selection)] = fieldResult,
|
|
6810
|
+
_a));
|
|
6811
|
+
}
|
|
6812
|
+
})];
|
|
6813
|
+
}
|
|
6814
|
+
if (isInlineFragment(selection)) {
|
|
6815
|
+
fragment = selection;
|
|
6816
|
+
}
|
|
6817
|
+
else {
|
|
6818
|
+
fragment = fragmentMap[selection.name.value];
|
|
6819
|
+
invariant(fragment, 18, selection.name.value);
|
|
6820
|
+
}
|
|
6821
|
+
if (fragment && fragment.typeCondition) {
|
|
6822
|
+
typeCondition = fragment.typeCondition.name.value;
|
|
6823
|
+
if (execContext.fragmentMatcher(rootValue, typeCondition, context)) {
|
|
6824
|
+
return [2 , this.resolveSelectionSet(fragment.selectionSet, isClientFieldDescendant, rootValue, execContext).then(function (fragmentResult) {
|
|
6825
|
+
resultsToMerge.push(fragmentResult);
|
|
6826
|
+
})];
|
|
6827
|
+
}
|
|
6828
|
+
}
|
|
6829
|
+
return [2 ];
|
|
6830
|
+
});
|
|
6831
|
+
}); };
|
|
6832
|
+
return [2 , Promise.all(selectionSet.selections.map(execute)).then(function () {
|
|
6833
|
+
return mergeDeepArray(resultsToMerge);
|
|
6834
|
+
})];
|
|
6808
6835
|
});
|
|
6809
|
-
}
|
|
6810
|
-
|
|
6811
|
-
|
|
6812
|
-
|
|
6813
|
-
|
|
6814
|
-
|
|
6815
|
-
|
|
6816
|
-
|
|
6817
|
-
|
|
6818
|
-
diff = info.getDiff();
|
|
6819
|
-
}
|
|
6820
|
-
result = onQueryUpdated(oq, diff, lastDiff);
|
|
6821
|
-
}
|
|
6822
|
-
if (!onQueryUpdated || result === true) {
|
|
6823
|
-
result = oq.refetch();
|
|
6824
|
-
}
|
|
6825
|
-
if (result !== false) {
|
|
6826
|
-
results.set(oq, result);
|
|
6836
|
+
});
|
|
6837
|
+
};
|
|
6838
|
+
LocalState.prototype.resolveField = function (field, isClientFieldDescendant, rootValue, execContext) {
|
|
6839
|
+
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
6840
|
+
var variables, fieldName, aliasedFieldName, aliasUsed, defaultResult, resultPromise, resolverType, resolverMap, resolve;
|
|
6841
|
+
var _this = this;
|
|
6842
|
+
return tslib.__generator(this, function (_a) {
|
|
6843
|
+
if (!rootValue) {
|
|
6844
|
+
return [2 , null];
|
|
6827
6845
|
}
|
|
6828
|
-
|
|
6829
|
-
|
|
6846
|
+
variables = execContext.variables;
|
|
6847
|
+
fieldName = field.name.value;
|
|
6848
|
+
aliasedFieldName = resultKeyNameFromField(field);
|
|
6849
|
+
aliasUsed = fieldName !== aliasedFieldName;
|
|
6850
|
+
defaultResult = rootValue[aliasedFieldName] || rootValue[fieldName];
|
|
6851
|
+
resultPromise = Promise.resolve(defaultResult);
|
|
6852
|
+
if (!execContext.onlyRunForcedResolvers ||
|
|
6853
|
+
this.shouldForceResolvers(field)) {
|
|
6854
|
+
resolverType = rootValue.__typename || execContext.defaultOperationType;
|
|
6855
|
+
resolverMap = this.resolvers && this.resolvers[resolverType];
|
|
6856
|
+
if (resolverMap) {
|
|
6857
|
+
resolve = resolverMap[aliasUsed ? fieldName : aliasedFieldName];
|
|
6858
|
+
if (resolve) {
|
|
6859
|
+
resultPromise = Promise.resolve(
|
|
6860
|
+
cacheSlot.withValue(this.cache, resolve, [
|
|
6861
|
+
rootValue,
|
|
6862
|
+
argumentsObjectFromField(field, variables),
|
|
6863
|
+
execContext.context,
|
|
6864
|
+
{ field: field, fragmentMap: execContext.fragmentMap },
|
|
6865
|
+
]));
|
|
6866
|
+
}
|
|
6867
|
+
}
|
|
6830
6868
|
}
|
|
6869
|
+
return [2 , resultPromise.then(function (result) {
|
|
6870
|
+
var _a, _b;
|
|
6871
|
+
if (result === void 0) { result = defaultResult; }
|
|
6872
|
+
if (field.directives) {
|
|
6873
|
+
field.directives.forEach(function (directive) {
|
|
6874
|
+
if (directive.name.value === "export" && directive.arguments) {
|
|
6875
|
+
directive.arguments.forEach(function (arg) {
|
|
6876
|
+
if (arg.name.value === "as" && arg.value.kind === "StringValue") {
|
|
6877
|
+
execContext.exportedVariables[arg.value.value] = result;
|
|
6878
|
+
}
|
|
6879
|
+
});
|
|
6880
|
+
}
|
|
6881
|
+
});
|
|
6882
|
+
}
|
|
6883
|
+
if (!field.selectionSet) {
|
|
6884
|
+
return result;
|
|
6885
|
+
}
|
|
6886
|
+
if (result == null) {
|
|
6887
|
+
return result;
|
|
6888
|
+
}
|
|
6889
|
+
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;
|
|
6890
|
+
if (Array.isArray(result)) {
|
|
6891
|
+
return _this.resolveSubSelectedArray(field, isClientFieldDescendant || isClientField, result, execContext);
|
|
6892
|
+
}
|
|
6893
|
+
if (field.selectionSet) {
|
|
6894
|
+
return _this.resolveSelectionSet(field.selectionSet, isClientFieldDescendant || isClientField, result, execContext);
|
|
6895
|
+
}
|
|
6896
|
+
})];
|
|
6831
6897
|
});
|
|
6832
|
-
}
|
|
6833
|
-
if (removeOptimistic) {
|
|
6834
|
-
this.cache.removeOptimistic(removeOptimistic);
|
|
6835
|
-
}
|
|
6836
|
-
return results;
|
|
6898
|
+
});
|
|
6837
6899
|
};
|
|
6838
|
-
|
|
6839
|
-
networkStatus) {
|
|
6900
|
+
LocalState.prototype.resolveSubSelectedArray = function (field, isClientFieldDescendant, result, execContext) {
|
|
6840
6901
|
var _this = this;
|
|
6841
|
-
|
|
6842
|
-
|
|
6843
|
-
|
|
6844
|
-
document: query,
|
|
6845
|
-
variables: variables,
|
|
6846
|
-
networkStatus: networkStatus,
|
|
6847
|
-
});
|
|
6848
|
-
var readCache = function () { return queryInfo.getDiff(); };
|
|
6849
|
-
var resultsFromCache = function (diff, networkStatus) {
|
|
6850
|
-
if (networkStatus === void 0) { networkStatus = queryInfo.networkStatus || exports.NetworkStatus.loading; }
|
|
6851
|
-
var data = diff.result;
|
|
6852
|
-
if (globalThis.__DEV__ !== false && !returnPartialData && !equal.equal(data, {})) {
|
|
6853
|
-
logMissingFieldErrors(diff.missing);
|
|
6854
|
-
}
|
|
6855
|
-
var fromData = function (data) {
|
|
6856
|
-
return zenObservableTs.Observable.of(tslib.__assign({ data: data, loading: isNetworkRequestInFlight(networkStatus), networkStatus: networkStatus }, (diff.complete ? null : { partial: true })));
|
|
6857
|
-
};
|
|
6858
|
-
if (data && _this.getDocumentInfo(query).hasForcedResolvers) {
|
|
6859
|
-
return _this.localState
|
|
6860
|
-
.runResolvers({
|
|
6861
|
-
document: query,
|
|
6862
|
-
remoteResult: { data: data },
|
|
6863
|
-
context: context,
|
|
6864
|
-
variables: variables,
|
|
6865
|
-
onlyRunForcedResolvers: true,
|
|
6866
|
-
})
|
|
6867
|
-
.then(function (resolved) { return fromData(resolved.data || void 0); });
|
|
6868
|
-
}
|
|
6869
|
-
if (errorPolicy === "none" &&
|
|
6870
|
-
networkStatus === exports.NetworkStatus.refetch &&
|
|
6871
|
-
Array.isArray(diff.missing)) {
|
|
6872
|
-
return fromData(void 0);
|
|
6902
|
+
return Promise.all(result.map(function (item) {
|
|
6903
|
+
if (item === null) {
|
|
6904
|
+
return null;
|
|
6873
6905
|
}
|
|
6874
|
-
|
|
6875
|
-
|
|
6876
|
-
var cacheWriteBehavior = fetchPolicy === "no-cache" ? 0
|
|
6877
|
-
: (networkStatus === exports.NetworkStatus.refetch &&
|
|
6878
|
-
refetchWritePolicy !== "merge") ?
|
|
6879
|
-
1
|
|
6880
|
-
: 2 ;
|
|
6881
|
-
var resultsFromLink = function () {
|
|
6882
|
-
return _this.getResultsFromLink(queryInfo, cacheWriteBehavior, {
|
|
6883
|
-
query: query,
|
|
6884
|
-
variables: variables,
|
|
6885
|
-
context: context,
|
|
6886
|
-
fetchPolicy: fetchPolicy,
|
|
6887
|
-
errorPolicy: errorPolicy,
|
|
6888
|
-
});
|
|
6889
|
-
};
|
|
6890
|
-
var shouldNotify = notifyOnNetworkStatusChange &&
|
|
6891
|
-
typeof oldNetworkStatus === "number" &&
|
|
6892
|
-
oldNetworkStatus !== networkStatus &&
|
|
6893
|
-
isNetworkRequestInFlight(networkStatus);
|
|
6894
|
-
switch (fetchPolicy) {
|
|
6895
|
-
default:
|
|
6896
|
-
case "cache-first": {
|
|
6897
|
-
var diff = readCache();
|
|
6898
|
-
if (diff.complete) {
|
|
6899
|
-
return {
|
|
6900
|
-
fromLink: false,
|
|
6901
|
-
sources: [resultsFromCache(diff, queryInfo.markReady())],
|
|
6902
|
-
};
|
|
6903
|
-
}
|
|
6904
|
-
if (returnPartialData || shouldNotify) {
|
|
6905
|
-
return {
|
|
6906
|
-
fromLink: true,
|
|
6907
|
-
sources: [resultsFromCache(diff), resultsFromLink()],
|
|
6908
|
-
};
|
|
6909
|
-
}
|
|
6910
|
-
return { fromLink: true, sources: [resultsFromLink()] };
|
|
6906
|
+
if (Array.isArray(item)) {
|
|
6907
|
+
return _this.resolveSubSelectedArray(field, isClientFieldDescendant, item, execContext);
|
|
6911
6908
|
}
|
|
6912
|
-
|
|
6913
|
-
|
|
6914
|
-
if (diff.complete || returnPartialData || shouldNotify) {
|
|
6915
|
-
return {
|
|
6916
|
-
fromLink: true,
|
|
6917
|
-
sources: [resultsFromCache(diff), resultsFromLink()],
|
|
6918
|
-
};
|
|
6919
|
-
}
|
|
6920
|
-
return { fromLink: true, sources: [resultsFromLink()] };
|
|
6909
|
+
if (field.selectionSet) {
|
|
6910
|
+
return _this.resolveSelectionSet(field.selectionSet, isClientFieldDescendant, item, execContext);
|
|
6921
6911
|
}
|
|
6922
|
-
|
|
6923
|
-
return {
|
|
6924
|
-
fromLink: false,
|
|
6925
|
-
sources: [resultsFromCache(readCache(), queryInfo.markReady())],
|
|
6926
|
-
};
|
|
6927
|
-
case "network-only":
|
|
6928
|
-
if (shouldNotify) {
|
|
6929
|
-
return {
|
|
6930
|
-
fromLink: true,
|
|
6931
|
-
sources: [resultsFromCache(readCache()), resultsFromLink()],
|
|
6932
|
-
};
|
|
6933
|
-
}
|
|
6934
|
-
return { fromLink: true, sources: [resultsFromLink()] };
|
|
6935
|
-
case "no-cache":
|
|
6936
|
-
if (shouldNotify) {
|
|
6937
|
-
return {
|
|
6938
|
-
fromLink: true,
|
|
6939
|
-
sources: [resultsFromCache(queryInfo.getDiff()), resultsFromLink()],
|
|
6940
|
-
};
|
|
6941
|
-
}
|
|
6942
|
-
return { fromLink: true, sources: [resultsFromLink()] };
|
|
6943
|
-
case "standby":
|
|
6944
|
-
return { fromLink: false, sources: [] };
|
|
6945
|
-
}
|
|
6912
|
+
}));
|
|
6946
6913
|
};
|
|
6947
|
-
|
|
6948
|
-
|
|
6949
|
-
|
|
6914
|
+
LocalState.prototype.collectSelectionsToResolve = function (mainDefinition, fragmentMap) {
|
|
6915
|
+
var isSingleASTNode = function (node) { return !Array.isArray(node); };
|
|
6916
|
+
var selectionsToResolveCache = this.selectionsToResolveCache;
|
|
6917
|
+
function collectByDefinition(definitionNode) {
|
|
6918
|
+
if (!selectionsToResolveCache.has(definitionNode)) {
|
|
6919
|
+
var matches_1 = new Set();
|
|
6920
|
+
selectionsToResolveCache.set(definitionNode, matches_1);
|
|
6921
|
+
graphql.visit(definitionNode, {
|
|
6922
|
+
Directive: function (node, _, __, ___, ancestors) {
|
|
6923
|
+
if (node.name.value === "client") {
|
|
6924
|
+
ancestors.forEach(function (node) {
|
|
6925
|
+
if (isSingleASTNode(node) && graphql.isSelectionNode(node)) {
|
|
6926
|
+
matches_1.add(node);
|
|
6927
|
+
}
|
|
6928
|
+
});
|
|
6929
|
+
}
|
|
6930
|
+
},
|
|
6931
|
+
FragmentSpread: function (spread, _, __, ___, ancestors) {
|
|
6932
|
+
var fragment = fragmentMap[spread.name.value];
|
|
6933
|
+
invariant(fragment, 19, spread.name.value);
|
|
6934
|
+
var fragmentSelections = collectByDefinition(fragment);
|
|
6935
|
+
if (fragmentSelections.size > 0) {
|
|
6936
|
+
ancestors.forEach(function (node) {
|
|
6937
|
+
if (isSingleASTNode(node) && graphql.isSelectionNode(node)) {
|
|
6938
|
+
matches_1.add(node);
|
|
6939
|
+
}
|
|
6940
|
+
});
|
|
6941
|
+
matches_1.add(spread);
|
|
6942
|
+
fragmentSelections.forEach(function (selection) {
|
|
6943
|
+
matches_1.add(selection);
|
|
6944
|
+
});
|
|
6945
|
+
}
|
|
6946
|
+
},
|
|
6947
|
+
});
|
|
6948
|
+
}
|
|
6949
|
+
return selectionsToResolveCache.get(definitionNode);
|
|
6950
6950
|
}
|
|
6951
|
-
return
|
|
6952
|
-
};
|
|
6953
|
-
QueryManager.prototype.prepareContext = function (context) {
|
|
6954
|
-
if (context === void 0) { context = {}; }
|
|
6955
|
-
var newContext = this.localState.prepareContext(context);
|
|
6956
|
-
return tslib.__assign(tslib.__assign(tslib.__assign({}, this.defaultContext), newContext), { clientAwareness: this.clientAwareness });
|
|
6951
|
+
return collectByDefinition(mainDefinition);
|
|
6957
6952
|
};
|
|
6958
|
-
return
|
|
6953
|
+
return LocalState;
|
|
6959
6954
|
}());
|
|
6960
6955
|
|
|
6961
6956
|
var hasSuggestedDevtools = false;
|
|
@@ -7017,7 +7012,7 @@ var ApolloClient = (function () {
|
|
|
7017
7012
|
},
|
|
7018
7013
|
localState: this.localState,
|
|
7019
7014
|
assumeImmutableResults: assumeImmutableResults,
|
|
7020
|
-
onBroadcast:
|
|
7015
|
+
onBroadcast: this.devtoolsConfig.enabled ?
|
|
7021
7016
|
function () {
|
|
7022
7017
|
if (_this.devToolsHookCb) {
|
|
7023
7018
|
_this.devToolsHookCb({
|
|
@@ -7499,7 +7494,6 @@ function wrapHook(hookName, useHook, clientOrObsQuery) {
|
|
|
7499
7494
|
}
|
|
7500
7495
|
|
|
7501
7496
|
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
7502
|
-
var originalResult = Symbol();
|
|
7503
7497
|
function noop() { }
|
|
7504
7498
|
var lastWatchOptions = Symbol();
|
|
7505
7499
|
function useQuery(query, options) {
|
|
@@ -7562,10 +7556,8 @@ function useQueryInternals(query, options) {
|
|
|
7562
7556
|
observable,
|
|
7563
7557
|
client, options, watchQueryOptions);
|
|
7564
7558
|
var obsQueryFields = React__namespace.useMemo(function () { return bindObservableMethods(observable); }, [observable]);
|
|
7565
|
-
useHandleSkip(resultData,
|
|
7566
|
-
observable, client, options, watchQueryOptions, disableNetworkFetches, isSyncSSR);
|
|
7567
7559
|
useRegisterSSRObservable(observable, renderPromises, ssrAllowed);
|
|
7568
|
-
var result = useObservableSubscriptionResult(resultData, observable, client, disableNetworkFetches, partialRefetch, isSyncSSR, {
|
|
7560
|
+
var result = useObservableSubscriptionResult(resultData, observable, client, options, watchQueryOptions, disableNetworkFetches, partialRefetch, isSyncSSR, {
|
|
7569
7561
|
onCompleted: options.onCompleted || noop,
|
|
7570
7562
|
onError: options.onError || noop,
|
|
7571
7563
|
});
|
|
@@ -7578,13 +7570,25 @@ function useQueryInternals(query, options) {
|
|
|
7578
7570
|
onQueryExecuted: onQueryExecuted,
|
|
7579
7571
|
};
|
|
7580
7572
|
}
|
|
7581
|
-
function useObservableSubscriptionResult(resultData, observable, client, disableNetworkFetches, partialRefetch,
|
|
7573
|
+
function useObservableSubscriptionResult(resultData, observable, client, options, watchQueryOptions, disableNetworkFetches, partialRefetch, isSyncSSR, callbacks) {
|
|
7582
7574
|
var callbackRef = React__namespace.useRef(callbacks);
|
|
7583
7575
|
React__namespace.useEffect(function () {
|
|
7584
7576
|
callbackRef.current = callbacks;
|
|
7585
7577
|
});
|
|
7578
|
+
var resultOverride = ((isSyncSSR || disableNetworkFetches) &&
|
|
7579
|
+
options.ssr === false &&
|
|
7580
|
+
!options.skip) ?
|
|
7581
|
+
ssrDisabledResult
|
|
7582
|
+
: options.skip || watchQueryOptions.fetchPolicy === "standby" ?
|
|
7583
|
+
skipStandbyResult
|
|
7584
|
+
: void 0;
|
|
7585
|
+
var previousData = resultData.previousData;
|
|
7586
|
+
var currentResultOverride = React__namespace.useMemo(function () {
|
|
7587
|
+
return resultOverride &&
|
|
7588
|
+
toQueryResult(resultOverride, previousData, observable, client);
|
|
7589
|
+
}, [client, observable, resultOverride, previousData]);
|
|
7586
7590
|
return useSyncExternalStore(React__namespace.useCallback(function (handleStoreChange) {
|
|
7587
|
-
if (
|
|
7591
|
+
if (isSyncSSR) {
|
|
7588
7592
|
return function () { };
|
|
7589
7593
|
}
|
|
7590
7594
|
var onNext = function () {
|
|
@@ -7622,15 +7626,17 @@ function useObservableSubscriptionResult(resultData, observable, client, disable
|
|
|
7622
7626
|
};
|
|
7623
7627
|
}, [
|
|
7624
7628
|
disableNetworkFetches,
|
|
7625
|
-
|
|
7629
|
+
isSyncSSR,
|
|
7626
7630
|
observable,
|
|
7627
7631
|
resultData,
|
|
7628
7632
|
partialRefetch,
|
|
7629
7633
|
client,
|
|
7630
7634
|
]), function () {
|
|
7631
|
-
return
|
|
7635
|
+
return currentResultOverride ||
|
|
7636
|
+
getCurrentResult(resultData, observable, callbackRef.current, partialRefetch, client);
|
|
7632
7637
|
}, function () {
|
|
7633
|
-
return
|
|
7638
|
+
return currentResultOverride ||
|
|
7639
|
+
getCurrentResult(resultData, observable, callbackRef.current, partialRefetch, client);
|
|
7634
7640
|
});
|
|
7635
7641
|
}
|
|
7636
7642
|
function useRegisterSSRObservable(observable, renderPromises, ssrAllowed) {
|
|
@@ -7641,23 +7647,6 @@ function useRegisterSSRObservable(observable, renderPromises, ssrAllowed) {
|
|
|
7641
7647
|
}
|
|
7642
7648
|
}
|
|
7643
7649
|
}
|
|
7644
|
-
function useHandleSkip(
|
|
7645
|
-
resultData, observable, client, options, watchQueryOptions, disableNetworkFetches, isSyncSSR) {
|
|
7646
|
-
if ((isSyncSSR || disableNetworkFetches) &&
|
|
7647
|
-
options.ssr === false &&
|
|
7648
|
-
!options.skip) {
|
|
7649
|
-
resultData.current = toQueryResult(ssrDisabledResult, resultData.previousData, observable, client);
|
|
7650
|
-
}
|
|
7651
|
-
else if (options.skip || watchQueryOptions.fetchPolicy === "standby") {
|
|
7652
|
-
resultData.current = toQueryResult(skipStandbyResult, resultData.previousData, observable, client);
|
|
7653
|
-
}
|
|
7654
|
-
else if (
|
|
7655
|
-
resultData.current &&
|
|
7656
|
-
(resultData.current[originalResult] === ssrDisabledResult ||
|
|
7657
|
-
resultData.current[originalResult] === skipStandbyResult)) {
|
|
7658
|
-
resultData.current = void 0;
|
|
7659
|
-
}
|
|
7660
|
-
}
|
|
7661
7650
|
function useResubscribeIfNecessary(
|
|
7662
7651
|
resultData,
|
|
7663
7652
|
observable, client, options, watchQueryOptions) {
|
|
@@ -7716,11 +7705,14 @@ function setResult(nextResult, resultData, observable, client, partialRefetch, f
|
|
|
7716
7705
|
if (previousResult && previousResult.data) {
|
|
7717
7706
|
resultData.previousData = previousResult.data;
|
|
7718
7707
|
}
|
|
7708
|
+
if (!nextResult.error && isNonEmptyArray(nextResult.errors)) {
|
|
7709
|
+
nextResult.error = new ApolloError({ graphQLErrors: nextResult.errors });
|
|
7710
|
+
}
|
|
7719
7711
|
resultData.current = toQueryResult(unsafeHandlePartialRefetch(nextResult, observable, partialRefetch), resultData.previousData, observable, client);
|
|
7720
7712
|
forceUpdate();
|
|
7721
|
-
handleErrorOrCompleted(nextResult, previousResult === null || previousResult === void 0 ? void 0 : previousResult
|
|
7713
|
+
handleErrorOrCompleted(nextResult, previousResult === null || previousResult === void 0 ? void 0 : previousResult.networkStatus, callbacks);
|
|
7722
7714
|
}
|
|
7723
|
-
function handleErrorOrCompleted(result,
|
|
7715
|
+
function handleErrorOrCompleted(result, previousNetworkStatus, callbacks) {
|
|
7724
7716
|
if (!result.loading) {
|
|
7725
7717
|
var error_1 = toApolloError$1(result);
|
|
7726
7718
|
Promise.resolve()
|
|
@@ -7729,7 +7721,7 @@ function handleErrorOrCompleted(result, previousResult, callbacks) {
|
|
|
7729
7721
|
callbacks.onError(error_1);
|
|
7730
7722
|
}
|
|
7731
7723
|
else if (result.data &&
|
|
7732
|
-
|
|
7724
|
+
previousNetworkStatus !== result.networkStatus &&
|
|
7733
7725
|
result.networkStatus === exports.NetworkStatus.ready) {
|
|
7734
7726
|
callbacks.onCompleted(result.data);
|
|
7735
7727
|
}
|
|
@@ -7759,10 +7751,6 @@ function toApolloError$1(result) {
|
|
|
7759
7751
|
function toQueryResult(result, previousData, observable, client) {
|
|
7760
7752
|
var data = result.data; result.partial; var resultWithoutPartial = tslib.__rest(result, ["data", "partial"]);
|
|
7761
7753
|
var queryResult = tslib.__assign(tslib.__assign({ data: data }, resultWithoutPartial), { client: client, observable: observable, variables: observable.variables, called: result !== ssrDisabledResult && result !== skipStandbyResult, previousData: previousData });
|
|
7762
|
-
Object.defineProperty(queryResult, originalResult, { value: result });
|
|
7763
|
-
if (!queryResult.error && isNonEmptyArray(result.errors)) {
|
|
7764
|
-
queryResult.error = new ApolloError({ graphQLErrors: result.errors });
|
|
7765
|
-
}
|
|
7766
7754
|
return queryResult;
|
|
7767
7755
|
}
|
|
7768
7756
|
function unsafeHandlePartialRefetch(result, observable, partialRefetch) {
|