@apollo/client 3.7.2 → 3.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/apollo-client.cjs +103 -48
- package/apollo-client.cjs.map +1 -1
- package/apollo-client.min.cjs +1 -1
- package/core/QueryInfo.d.ts.map +1 -1
- package/core/QueryInfo.js +8 -17
- package/core/QueryInfo.js.map +1 -1
- package/core/QueryManager.d.ts.map +1 -1
- package/core/QueryManager.js +52 -27
- package/core/QueryManager.js.map +1 -1
- package/core/core.cjs +147 -44
- package/core/core.cjs.map +1 -1
- package/core/core.cjs.native.js +147 -44
- package/invariantErrorCodes.js +1 -1
- package/package.json +8 -6
- package/utilities/common/errorHandling.d.ts +3 -2
- package/utilities/common/errorHandling.d.ts.map +1 -1
- package/utilities/common/errorHandling.js +18 -1
- package/utilities/common/errorHandling.js.map +1 -1
- package/utilities/common/incrementalResult.d.ts +5 -2
- package/utilities/common/incrementalResult.d.ts.map +1 -1
- package/utilities/common/incrementalResult.js +29 -1
- package/utilities/common/incrementalResult.js.map +1 -1
- package/utilities/utilities.cjs +21 -1
- package/utilities/utilities.cjs.map +1 -1
- package/utilities/utilities.cjs.native.js +21 -1
- package/version.js +1 -1
package/core/core.cjs
CHANGED
|
@@ -15,10 +15,99 @@ var utils = require('../link/utils');
|
|
|
15
15
|
var tsInvariant = require('ts-invariant');
|
|
16
16
|
var graphqlTag = require('graphql-tag');
|
|
17
17
|
|
|
18
|
-
var version = '3.7.
|
|
18
|
+
var version = '3.7.3';
|
|
19
|
+
|
|
20
|
+
function isNonEmptyArray(value) {
|
|
21
|
+
return Array.isArray(value) && value.length > 0;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function isNonNullObject(obj) {
|
|
25
|
+
return obj !== null && typeof obj === 'object';
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
var hasOwnProperty$2 = Object.prototype.hasOwnProperty;
|
|
29
|
+
var defaultReconciler = function (target, source, property) {
|
|
30
|
+
return this.merge(target[property], source[property]);
|
|
31
|
+
};
|
|
32
|
+
var DeepMerger = (function () {
|
|
33
|
+
function DeepMerger(reconciler) {
|
|
34
|
+
if (reconciler === void 0) { reconciler = defaultReconciler; }
|
|
35
|
+
this.reconciler = reconciler;
|
|
36
|
+
this.isObject = isNonNullObject;
|
|
37
|
+
this.pastCopies = new Set();
|
|
38
|
+
}
|
|
39
|
+
DeepMerger.prototype.merge = function (target, source) {
|
|
40
|
+
var _this = this;
|
|
41
|
+
var context = [];
|
|
42
|
+
for (var _i = 2; _i < arguments.length; _i++) {
|
|
43
|
+
context[_i - 2] = arguments[_i];
|
|
44
|
+
}
|
|
45
|
+
if (isNonNullObject(source) && isNonNullObject(target)) {
|
|
46
|
+
Object.keys(source).forEach(function (sourceKey) {
|
|
47
|
+
if (hasOwnProperty$2.call(target, sourceKey)) {
|
|
48
|
+
var targetValue = target[sourceKey];
|
|
49
|
+
if (source[sourceKey] !== targetValue) {
|
|
50
|
+
var result = _this.reconciler.apply(_this, tslib.__spreadArray([target, source, sourceKey], context, false));
|
|
51
|
+
if (result !== targetValue) {
|
|
52
|
+
target = _this.shallowCopyForMerge(target);
|
|
53
|
+
target[sourceKey] = result;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
target = _this.shallowCopyForMerge(target);
|
|
59
|
+
target[sourceKey] = source[sourceKey];
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
return target;
|
|
63
|
+
}
|
|
64
|
+
return source;
|
|
65
|
+
};
|
|
66
|
+
DeepMerger.prototype.shallowCopyForMerge = function (value) {
|
|
67
|
+
if (isNonNullObject(value)) {
|
|
68
|
+
if (!this.pastCopies.has(value)) {
|
|
69
|
+
if (Array.isArray(value)) {
|
|
70
|
+
value = value.slice(0);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
value = tslib.__assign({ __proto__: Object.getPrototypeOf(value) }, value);
|
|
74
|
+
}
|
|
75
|
+
this.pastCopies.add(value);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return value;
|
|
79
|
+
};
|
|
80
|
+
return DeepMerger;
|
|
81
|
+
}());
|
|
19
82
|
|
|
20
83
|
function isExecutionPatchIncrementalResult(value) {
|
|
21
|
-
return
|
|
84
|
+
return "incremental" in value;
|
|
85
|
+
}
|
|
86
|
+
function isExecutionPatchInitialResult(value) {
|
|
87
|
+
return "hasNext" in value && "data" in value;
|
|
88
|
+
}
|
|
89
|
+
function isExecutionPatchResult(value) {
|
|
90
|
+
return (isExecutionPatchIncrementalResult(value) ||
|
|
91
|
+
isExecutionPatchInitialResult(value));
|
|
92
|
+
}
|
|
93
|
+
function mergeIncrementalData(prevResult, result) {
|
|
94
|
+
var mergedData = prevResult;
|
|
95
|
+
var merger = new DeepMerger();
|
|
96
|
+
if (isExecutionPatchIncrementalResult(result) &&
|
|
97
|
+
isNonEmptyArray(result.incremental)) {
|
|
98
|
+
result.incremental.forEach(function (_a) {
|
|
99
|
+
var data = _a.data, path = _a.path;
|
|
100
|
+
for (var i = path.length - 1; i >= 0; --i) {
|
|
101
|
+
var key = path[i];
|
|
102
|
+
var isNumericKey = !isNaN(+key);
|
|
103
|
+
var parent_1 = isNumericKey ? [] : {};
|
|
104
|
+
parent_1[key] = data;
|
|
105
|
+
data = parent_1;
|
|
106
|
+
}
|
|
107
|
+
mergedData = merger.merge(mergedData, data);
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
return mergedData;
|
|
22
111
|
}
|
|
23
112
|
|
|
24
113
|
exports.NetworkStatus = void 0;
|
|
@@ -983,28 +1072,18 @@ var QueryInfo = (function () {
|
|
|
983
1072
|
};
|
|
984
1073
|
QueryInfo.prototype.markResult = function (result, document, options, cacheWriteBehavior) {
|
|
985
1074
|
var _this = this;
|
|
1075
|
+
var merger = new utilities.DeepMerger();
|
|
986
1076
|
var graphQLErrors = utilities.isNonEmptyArray(result.errors)
|
|
987
1077
|
? result.errors.slice(0)
|
|
988
1078
|
: [];
|
|
989
1079
|
this.reset();
|
|
990
1080
|
if ('incremental' in result && utilities.isNonEmptyArray(result.incremental)) {
|
|
991
|
-
var
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
var isNumericKey = !isNaN(+key);
|
|
998
|
-
var parent_1 = isNumericKey ? [] : {};
|
|
999
|
-
parent_1[key] = data;
|
|
1000
|
-
data = parent_1;
|
|
1001
|
-
}
|
|
1002
|
-
if (errors) {
|
|
1003
|
-
graphQLErrors.push.apply(graphQLErrors, errors);
|
|
1004
|
-
}
|
|
1005
|
-
mergedData_1 = merger_1.merge(mergedData_1, data);
|
|
1006
|
-
});
|
|
1007
|
-
result.data = mergedData_1;
|
|
1081
|
+
var mergedData = mergeIncrementalData(this.getDiff().result, result);
|
|
1082
|
+
result.data = mergedData;
|
|
1083
|
+
}
|
|
1084
|
+
else if ('hasNext' in result && result.hasNext) {
|
|
1085
|
+
var diff = this.getDiff();
|
|
1086
|
+
result.data = merger.merge(diff.result, result.data);
|
|
1008
1087
|
}
|
|
1009
1088
|
this.graphQLErrors = graphQLErrors;
|
|
1010
1089
|
if (options.fetchPolicy === 'no-cache') {
|
|
@@ -1161,7 +1240,7 @@ var QueryManager = (function () {
|
|
|
1161
1240
|
return utilities.asyncMap(self.getObservableFromLink(mutation, tslib.__assign(tslib.__assign({}, context), { optimisticResponse: optimisticResponse }), variables, false), function (result) {
|
|
1162
1241
|
if (utilities.graphQLResultHasError(result) && errorPolicy === 'none') {
|
|
1163
1242
|
throw new errors.ApolloError({
|
|
1164
|
-
graphQLErrors: result
|
|
1243
|
+
graphQLErrors: utilities.getGraphQLErrorsFromResult(result),
|
|
1165
1244
|
});
|
|
1166
1245
|
}
|
|
1167
1246
|
if (mutationStoreValue) {
|
|
@@ -1195,7 +1274,9 @@ var QueryManager = (function () {
|
|
|
1195
1274
|
}).subscribe({
|
|
1196
1275
|
next: function (storeResult) {
|
|
1197
1276
|
self.broadcastQueries();
|
|
1198
|
-
|
|
1277
|
+
if (!('hasNext' in storeResult) || storeResult.hasNext === false) {
|
|
1278
|
+
resolve(storeResult);
|
|
1279
|
+
}
|
|
1199
1280
|
},
|
|
1200
1281
|
error: function (err) {
|
|
1201
1282
|
if (mutationStoreValue) {
|
|
@@ -1223,12 +1304,33 @@ var QueryManager = (function () {
|
|
|
1223
1304
|
var cacheWrites = [];
|
|
1224
1305
|
var skipCache = mutation.fetchPolicy === "no-cache";
|
|
1225
1306
|
if (!skipCache && shouldWriteResult(result, mutation.errorPolicy)) {
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1307
|
+
if (!isExecutionPatchIncrementalResult(result)) {
|
|
1308
|
+
cacheWrites.push({
|
|
1309
|
+
result: result.data,
|
|
1310
|
+
dataId: 'ROOT_MUTATION',
|
|
1311
|
+
query: mutation.document,
|
|
1312
|
+
variables: mutation.variables,
|
|
1313
|
+
});
|
|
1314
|
+
}
|
|
1315
|
+
if (isExecutionPatchIncrementalResult(result) && utilities.isNonEmptyArray(result.incremental)) {
|
|
1316
|
+
var diff = cache.diff({
|
|
1317
|
+
id: "ROOT_MUTATION",
|
|
1318
|
+
query: this.transform(mutation.document).asQuery,
|
|
1319
|
+
variables: mutation.variables,
|
|
1320
|
+
optimistic: false,
|
|
1321
|
+
returnPartialData: true,
|
|
1322
|
+
});
|
|
1323
|
+
var mergedData = mergeIncrementalData(diff.result, result);
|
|
1324
|
+
if (typeof mergedData !== 'undefined') {
|
|
1325
|
+
result.data = mergedData;
|
|
1326
|
+
cacheWrites.push({
|
|
1327
|
+
result: mergedData,
|
|
1328
|
+
dataId: 'ROOT_MUTATION',
|
|
1329
|
+
query: mutation.document,
|
|
1330
|
+
variables: mutation.variables,
|
|
1331
|
+
});
|
|
1332
|
+
}
|
|
1333
|
+
}
|
|
1232
1334
|
var updateQueries_1 = mutation.updateQueries;
|
|
1233
1335
|
if (updateQueries_1) {
|
|
1234
1336
|
this.queries.forEach(function (_a, queryId) {
|
|
@@ -1275,6 +1377,8 @@ var QueryManager = (function () {
|
|
|
1275
1377
|
cacheWrites.forEach(function (write) { return cache.write(write); });
|
|
1276
1378
|
}
|
|
1277
1379
|
var update = mutation.update;
|
|
1380
|
+
var isFinalResult = !isExecutionPatchResult(result) ||
|
|
1381
|
+
(isExecutionPatchIncrementalResult(result) && !result.hasNext);
|
|
1278
1382
|
if (update) {
|
|
1279
1383
|
if (!skipCache) {
|
|
1280
1384
|
var diff = cache.diff({
|
|
@@ -1284,16 +1388,24 @@ var QueryManager = (function () {
|
|
|
1284
1388
|
optimistic: false,
|
|
1285
1389
|
returnPartialData: true,
|
|
1286
1390
|
});
|
|
1287
|
-
if (diff.complete
|
|
1391
|
+
if (diff.complete) {
|
|
1288
1392
|
result = tslib.__assign(tslib.__assign({}, result), { data: diff.result });
|
|
1393
|
+
if ('incremental' in result) {
|
|
1394
|
+
delete result.incremental;
|
|
1395
|
+
}
|
|
1396
|
+
if ('hasNext' in result) {
|
|
1397
|
+
delete result.hasNext;
|
|
1398
|
+
}
|
|
1289
1399
|
}
|
|
1290
1400
|
}
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1401
|
+
if (isFinalResult) {
|
|
1402
|
+
update(cache, result, {
|
|
1403
|
+
context: mutation.context,
|
|
1404
|
+
variables: mutation.variables,
|
|
1405
|
+
});
|
|
1406
|
+
}
|
|
1295
1407
|
}
|
|
1296
|
-
if (!skipCache && !mutation.keepRootFields) {
|
|
1408
|
+
if (!skipCache && !mutation.keepRootFields && isFinalResult) {
|
|
1297
1409
|
cache.modify({
|
|
1298
1410
|
id: 'ROOT_MUTATION',
|
|
1299
1411
|
fields: function (value, _a) {
|
|
@@ -1661,17 +1773,8 @@ var QueryManager = (function () {
|
|
|
1661
1773
|
var requestId = queryInfo.lastRequestId = this.generateRequestId();
|
|
1662
1774
|
var linkDocument = this.cache.transformForLink(this.transform(queryInfo.document).document);
|
|
1663
1775
|
return utilities.asyncMap(this.getObservableFromLink(linkDocument, options.context, options.variables), function (result) {
|
|
1664
|
-
var graphQLErrors = utilities.
|
|
1665
|
-
|
|
1666
|
-
: [];
|
|
1667
|
-
if ('incremental' in result && utilities.isNonEmptyArray(result.incremental)) {
|
|
1668
|
-
result.incremental.forEach(function (incrementalResult) {
|
|
1669
|
-
if (incrementalResult.errors) {
|
|
1670
|
-
graphQLErrors.push.apply(graphQLErrors, incrementalResult.errors);
|
|
1671
|
-
}
|
|
1672
|
-
});
|
|
1673
|
-
}
|
|
1674
|
-
var hasErrors = utilities.isNonEmptyArray(graphQLErrors);
|
|
1776
|
+
var graphQLErrors = utilities.getGraphQLErrorsFromResult(result);
|
|
1777
|
+
var hasErrors = graphQLErrors.length > 0;
|
|
1675
1778
|
if (requestId >= queryInfo.lastRequestId) {
|
|
1676
1779
|
if (hasErrors && options.errorPolicy === "none") {
|
|
1677
1780
|
throw queryInfo.markError(new errors.ApolloError({
|