@apollo/client 3.7.1 → 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/README.md +5 -5
- package/apollo-client.cjs +105 -50
- package/apollo-client.cjs.map +1 -1
- package/apollo-client.min.cjs +1 -1
- package/cache/core/types/common.d.ts +3 -2
- package/cache/core/types/common.d.ts.map +1 -1
- package/cache/core/types/common.js.map +1 -1
- package/cache/index.d.ts +1 -1
- package/cache/index.d.ts.map +1 -1
- package/cache/index.js.map +1 -1
- package/core/ApolloClient.js +1 -1
- package/core/ApolloClient.js.map +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 -28
- package/core/QueryManager.js.map +1 -1
- package/core/core.cjs +148 -46
- package/core/core.cjs.map +1 -1
- package/core/core.cjs.native.js +148 -46
- package/errors/errors.cjs +1 -0
- package/errors/errors.cjs.map +1 -1
- package/errors/errors.cjs.native.js +1 -0
- package/errors/index.d.ts +1 -0
- package/errors/index.d.ts.map +1 -1
- package/errors/index.js +1 -0
- package/errors/index.js.map +1 -1
- package/invariantErrorCodes.js +1 -1
- package/package.json +17 -15
- package/react/hooks/useMutation.d.ts +1 -1
- package/react/hooks/useMutation.d.ts.map +1 -1
- package/react/hooks/useMutation.js.map +1 -1
- 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/README.md
CHANGED
|
@@ -19,7 +19,7 @@ The Apollo Client API reference can be found at: <br/>
|
|
|
19
19
|
Learn how to use Apollo Client with self-paced hands-on training on Odyssey, Apollo's official learning platform: <br/>
|
|
20
20
|
[https://odyssey.apollographql.com/](https://odyssey.apollographql.com/)
|
|
21
21
|
|
|
22
|
-
##
|
|
22
|
+
## Maintainers
|
|
23
23
|
|
|
24
24
|
- [@benjamn](https://github.com/benjamn)
|
|
25
25
|
- [@alessbell](https://github.com/alessbell)
|
|
@@ -33,10 +33,10 @@ Learn how to use Apollo Client with self-paced hands-on training on Odyssey, Apo
|
|
|
33
33
|
|
|
34
34
|
[Apollo](https://apollographql.com/) builds open-source software and a graph platform to unify GraphQL across your apps and services. We help you ship faster with:
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
- [Apollo Studio](https://www.apollographql.com/studio/develop/) – A free, end-to-end platform for managing your GraphQL lifecycle. Track your GraphQL schemas in a hosted registry to create a source of truth for everything in your graph. Studio provides an IDE (Apollo Explorer) so you can explore data, collaborate on queries, observe usage, and safely make schema changes.
|
|
37
|
+
- [Apollo Federation](https://www.apollographql.com/apollo-federation) – The industry-standard open architecture for building a distributed graph. Use Apollo’s gateway to compose a unified graph from multiple subgraphs, determine a query plan, and route requests across your services.
|
|
38
|
+
- [Apollo Client](https://www.apollographql.com/apollo-client/) – The most popular GraphQL client for the web. Apollo also builds and maintains [Apollo iOS](https://github.com/apollographql/apollo-ios) and [Apollo Android](https://github.com/apollographql/apollo-android).
|
|
39
|
+
- [Apollo Server](https://www.apollographql.com/docs/apollo-server/) – A production-ready JavaScript GraphQL server that connects to any microservice, API, or database. Compatible with all popular JavaScript frameworks and deployable in serverless environments.
|
|
40
40
|
|
|
41
41
|
## Learn how to build with Apollo
|
|
42
42
|
|
package/apollo-client.cjs
CHANGED
|
@@ -1053,8 +1053,53 @@ function isNonEmptyArray(value) {
|
|
|
1053
1053
|
return Array.isArray(value) && value.length > 0;
|
|
1054
1054
|
}
|
|
1055
1055
|
|
|
1056
|
+
function isExecutionPatchIncrementalResult(value) {
|
|
1057
|
+
return "incremental" in value;
|
|
1058
|
+
}
|
|
1059
|
+
function isExecutionPatchInitialResult(value) {
|
|
1060
|
+
return "hasNext" in value && "data" in value;
|
|
1061
|
+
}
|
|
1062
|
+
function isExecutionPatchResult(value) {
|
|
1063
|
+
return (isExecutionPatchIncrementalResult(value) ||
|
|
1064
|
+
isExecutionPatchInitialResult(value));
|
|
1065
|
+
}
|
|
1066
|
+
function mergeIncrementalData(prevResult, result) {
|
|
1067
|
+
var mergedData = prevResult;
|
|
1068
|
+
var merger = new DeepMerger();
|
|
1069
|
+
if (isExecutionPatchIncrementalResult(result) &&
|
|
1070
|
+
isNonEmptyArray(result.incremental)) {
|
|
1071
|
+
result.incremental.forEach(function (_a) {
|
|
1072
|
+
var data = _a.data, path = _a.path;
|
|
1073
|
+
for (var i = path.length - 1; i >= 0; --i) {
|
|
1074
|
+
var key = path[i];
|
|
1075
|
+
var isNumericKey = !isNaN(+key);
|
|
1076
|
+
var parent_1 = isNumericKey ? [] : {};
|
|
1077
|
+
parent_1[key] = data;
|
|
1078
|
+
data = parent_1;
|
|
1079
|
+
}
|
|
1080
|
+
mergedData = merger.merge(mergedData, data);
|
|
1081
|
+
});
|
|
1082
|
+
}
|
|
1083
|
+
return mergedData;
|
|
1084
|
+
}
|
|
1085
|
+
|
|
1056
1086
|
function graphQLResultHasError(result) {
|
|
1057
|
-
|
|
1087
|
+
var errors = getGraphQLErrorsFromResult(result);
|
|
1088
|
+
return isNonEmptyArray(errors);
|
|
1089
|
+
}
|
|
1090
|
+
function getGraphQLErrorsFromResult(result) {
|
|
1091
|
+
var graphQLErrors = isNonEmptyArray(result.errors)
|
|
1092
|
+
? result.errors.slice(0)
|
|
1093
|
+
: [];
|
|
1094
|
+
if (isExecutionPatchIncrementalResult(result) &&
|
|
1095
|
+
isNonEmptyArray(result.incremental)) {
|
|
1096
|
+
result.incremental.forEach(function (incrementalResult) {
|
|
1097
|
+
if (incrementalResult.errors) {
|
|
1098
|
+
graphQLErrors.push.apply(graphQLErrors, incrementalResult.errors);
|
|
1099
|
+
}
|
|
1100
|
+
});
|
|
1101
|
+
}
|
|
1102
|
+
return graphQLErrors;
|
|
1058
1103
|
}
|
|
1059
1104
|
|
|
1060
1105
|
function compact() {
|
|
@@ -1300,7 +1345,7 @@ var concat = ApolloLink.concat;
|
|
|
1300
1345
|
|
|
1301
1346
|
var execute = ApolloLink.execute;
|
|
1302
1347
|
|
|
1303
|
-
var version = '3.7.
|
|
1348
|
+
var version = '3.7.3';
|
|
1304
1349
|
|
|
1305
1350
|
function isNodeResponse(value) {
|
|
1306
1351
|
return !!value.body;
|
|
@@ -1881,10 +1926,6 @@ var HttpLink = (function (_super) {
|
|
|
1881
1926
|
return HttpLink;
|
|
1882
1927
|
}(ApolloLink));
|
|
1883
1928
|
|
|
1884
|
-
function isExecutionPatchIncrementalResult(value) {
|
|
1885
|
-
return !!value.incremental;
|
|
1886
|
-
}
|
|
1887
|
-
|
|
1888
1929
|
var ApolloCache = (function () {
|
|
1889
1930
|
function ApolloCache() {
|
|
1890
1931
|
this.getFragmentDoc = optimism.wrap(getFragmentQueryDocument);
|
|
@@ -4201,6 +4242,7 @@ var ApolloError = (function (_super) {
|
|
|
4201
4242
|
function ApolloError(_a) {
|
|
4202
4243
|
var graphQLErrors = _a.graphQLErrors, clientErrors = _a.clientErrors, networkError = _a.networkError, errorMessage = _a.errorMessage, extraInfo = _a.extraInfo;
|
|
4203
4244
|
var _this = _super.call(this, errorMessage) || this;
|
|
4245
|
+
_this.name = 'ApolloError';
|
|
4204
4246
|
_this.graphQLErrors = graphQLErrors || [];
|
|
4205
4247
|
_this.clientErrors = clientErrors || [];
|
|
4206
4248
|
_this.networkError = networkError || null;
|
|
@@ -5174,28 +5216,18 @@ var QueryInfo = (function () {
|
|
|
5174
5216
|
};
|
|
5175
5217
|
QueryInfo.prototype.markResult = function (result, document, options, cacheWriteBehavior) {
|
|
5176
5218
|
var _this = this;
|
|
5219
|
+
var merger = new DeepMerger();
|
|
5177
5220
|
var graphQLErrors = isNonEmptyArray(result.errors)
|
|
5178
5221
|
? result.errors.slice(0)
|
|
5179
5222
|
: [];
|
|
5180
5223
|
this.reset();
|
|
5181
5224
|
if ('incremental' in result && isNonEmptyArray(result.incremental)) {
|
|
5182
|
-
var
|
|
5183
|
-
|
|
5184
|
-
|
|
5185
|
-
|
|
5186
|
-
|
|
5187
|
-
|
|
5188
|
-
var isNumericKey = !isNaN(+key);
|
|
5189
|
-
var parent_1 = isNumericKey ? [] : {};
|
|
5190
|
-
parent_1[key] = data;
|
|
5191
|
-
data = parent_1;
|
|
5192
|
-
}
|
|
5193
|
-
if (errors) {
|
|
5194
|
-
graphQLErrors.push.apply(graphQLErrors, errors);
|
|
5195
|
-
}
|
|
5196
|
-
mergedData_1 = merger_1.merge(mergedData_1, data);
|
|
5197
|
-
});
|
|
5198
|
-
result.data = mergedData_1;
|
|
5225
|
+
var mergedData = mergeIncrementalData(this.getDiff().result, result);
|
|
5226
|
+
result.data = mergedData;
|
|
5227
|
+
}
|
|
5228
|
+
else if ('hasNext' in result && result.hasNext) {
|
|
5229
|
+
var diff = this.getDiff();
|
|
5230
|
+
result.data = merger.merge(diff.result, result.data);
|
|
5199
5231
|
}
|
|
5200
5232
|
this.graphQLErrors = graphQLErrors;
|
|
5201
5233
|
if (options.fetchPolicy === 'no-cache') {
|
|
@@ -5352,7 +5384,7 @@ var QueryManager = (function () {
|
|
|
5352
5384
|
return asyncMap(self.getObservableFromLink(mutation, tslib.__assign(tslib.__assign({}, context), { optimisticResponse: optimisticResponse }), variables, false), function (result) {
|
|
5353
5385
|
if (graphQLResultHasError(result) && errorPolicy === 'none') {
|
|
5354
5386
|
throw new ApolloError({
|
|
5355
|
-
graphQLErrors: result
|
|
5387
|
+
graphQLErrors: getGraphQLErrorsFromResult(result),
|
|
5356
5388
|
});
|
|
5357
5389
|
}
|
|
5358
5390
|
if (mutationStoreValue) {
|
|
@@ -5386,7 +5418,9 @@ var QueryManager = (function () {
|
|
|
5386
5418
|
}).subscribe({
|
|
5387
5419
|
next: function (storeResult) {
|
|
5388
5420
|
self.broadcastQueries();
|
|
5389
|
-
|
|
5421
|
+
if (!('hasNext' in storeResult) || storeResult.hasNext === false) {
|
|
5422
|
+
resolve(storeResult);
|
|
5423
|
+
}
|
|
5390
5424
|
},
|
|
5391
5425
|
error: function (err) {
|
|
5392
5426
|
if (mutationStoreValue) {
|
|
@@ -5414,12 +5448,33 @@ var QueryManager = (function () {
|
|
|
5414
5448
|
var cacheWrites = [];
|
|
5415
5449
|
var skipCache = mutation.fetchPolicy === "no-cache";
|
|
5416
5450
|
if (!skipCache && shouldWriteResult(result, mutation.errorPolicy)) {
|
|
5417
|
-
|
|
5418
|
-
|
|
5419
|
-
|
|
5420
|
-
|
|
5421
|
-
|
|
5422
|
-
|
|
5451
|
+
if (!isExecutionPatchIncrementalResult(result)) {
|
|
5452
|
+
cacheWrites.push({
|
|
5453
|
+
result: result.data,
|
|
5454
|
+
dataId: 'ROOT_MUTATION',
|
|
5455
|
+
query: mutation.document,
|
|
5456
|
+
variables: mutation.variables,
|
|
5457
|
+
});
|
|
5458
|
+
}
|
|
5459
|
+
if (isExecutionPatchIncrementalResult(result) && isNonEmptyArray(result.incremental)) {
|
|
5460
|
+
var diff = cache.diff({
|
|
5461
|
+
id: "ROOT_MUTATION",
|
|
5462
|
+
query: this.transform(mutation.document).asQuery,
|
|
5463
|
+
variables: mutation.variables,
|
|
5464
|
+
optimistic: false,
|
|
5465
|
+
returnPartialData: true,
|
|
5466
|
+
});
|
|
5467
|
+
var mergedData = mergeIncrementalData(diff.result, result);
|
|
5468
|
+
if (typeof mergedData !== 'undefined') {
|
|
5469
|
+
result.data = mergedData;
|
|
5470
|
+
cacheWrites.push({
|
|
5471
|
+
result: mergedData,
|
|
5472
|
+
dataId: 'ROOT_MUTATION',
|
|
5473
|
+
query: mutation.document,
|
|
5474
|
+
variables: mutation.variables,
|
|
5475
|
+
});
|
|
5476
|
+
}
|
|
5477
|
+
}
|
|
5423
5478
|
var updateQueries_1 = mutation.updateQueries;
|
|
5424
5479
|
if (updateQueries_1) {
|
|
5425
5480
|
this.queries.forEach(function (_a, queryId) {
|
|
@@ -5466,6 +5521,8 @@ var QueryManager = (function () {
|
|
|
5466
5521
|
cacheWrites.forEach(function (write) { return cache.write(write); });
|
|
5467
5522
|
}
|
|
5468
5523
|
var update = mutation.update;
|
|
5524
|
+
var isFinalResult = !isExecutionPatchResult(result) ||
|
|
5525
|
+
(isExecutionPatchIncrementalResult(result) && !result.hasNext);
|
|
5469
5526
|
if (update) {
|
|
5470
5527
|
if (!skipCache) {
|
|
5471
5528
|
var diff = cache.diff({
|
|
@@ -5475,16 +5532,24 @@ var QueryManager = (function () {
|
|
|
5475
5532
|
optimistic: false,
|
|
5476
5533
|
returnPartialData: true,
|
|
5477
5534
|
});
|
|
5478
|
-
if (diff.complete
|
|
5535
|
+
if (diff.complete) {
|
|
5479
5536
|
result = tslib.__assign(tslib.__assign({}, result), { data: diff.result });
|
|
5537
|
+
if ('incremental' in result) {
|
|
5538
|
+
delete result.incremental;
|
|
5539
|
+
}
|
|
5540
|
+
if ('hasNext' in result) {
|
|
5541
|
+
delete result.hasNext;
|
|
5542
|
+
}
|
|
5480
5543
|
}
|
|
5481
5544
|
}
|
|
5482
|
-
|
|
5483
|
-
|
|
5484
|
-
|
|
5485
|
-
|
|
5545
|
+
if (isFinalResult) {
|
|
5546
|
+
update(cache, result, {
|
|
5547
|
+
context: mutation.context,
|
|
5548
|
+
variables: mutation.variables,
|
|
5549
|
+
});
|
|
5550
|
+
}
|
|
5486
5551
|
}
|
|
5487
|
-
if (!skipCache && !mutation.keepRootFields) {
|
|
5552
|
+
if (!skipCache && !mutation.keepRootFields && isFinalResult) {
|
|
5488
5553
|
cache.modify({
|
|
5489
5554
|
id: 'ROOT_MUTATION',
|
|
5490
5555
|
fields: function (value, _a) {
|
|
@@ -5850,20 +5915,10 @@ var QueryManager = (function () {
|
|
|
5850
5915
|
};
|
|
5851
5916
|
QueryManager.prototype.getResultsFromLink = function (queryInfo, cacheWriteBehavior, options) {
|
|
5852
5917
|
var requestId = queryInfo.lastRequestId = this.generateRequestId();
|
|
5853
|
-
options = cloneDeep(options);
|
|
5854
5918
|
var linkDocument = this.cache.transformForLink(this.transform(queryInfo.document).document);
|
|
5855
5919
|
return asyncMap(this.getObservableFromLink(linkDocument, options.context, options.variables), function (result) {
|
|
5856
|
-
var graphQLErrors =
|
|
5857
|
-
|
|
5858
|
-
: [];
|
|
5859
|
-
if ('incremental' in result && isNonEmptyArray(result.incremental)) {
|
|
5860
|
-
result.incremental.forEach(function (incrementalResult) {
|
|
5861
|
-
if (incrementalResult.errors) {
|
|
5862
|
-
graphQLErrors.push.apply(graphQLErrors, incrementalResult.errors);
|
|
5863
|
-
}
|
|
5864
|
-
});
|
|
5865
|
-
}
|
|
5866
|
-
var hasErrors = isNonEmptyArray(graphQLErrors);
|
|
5920
|
+
var graphQLErrors = getGraphQLErrorsFromResult(result);
|
|
5921
|
+
var hasErrors = graphQLErrors.length > 0;
|
|
5867
5922
|
if (requestId >= queryInfo.lastRequestId) {
|
|
5868
5923
|
if (hasErrors && options.errorPolicy === "none") {
|
|
5869
5924
|
throw queryInfo.markError(new ApolloError({
|
|
@@ -6149,7 +6204,7 @@ var ApolloClient = (function () {
|
|
|
6149
6204
|
if (connectToDevTools && typeof window === 'object') {
|
|
6150
6205
|
window.__APOLLO_CLIENT__ = this;
|
|
6151
6206
|
}
|
|
6152
|
-
if (!hasSuggestedDevtools && __DEV__) {
|
|
6207
|
+
if (!hasSuggestedDevtools && connectToDevTools && __DEV__) {
|
|
6153
6208
|
hasSuggestedDevtools = true;
|
|
6154
6209
|
if (typeof window !== 'undefined' &&
|
|
6155
6210
|
window.document &&
|