@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.
Files changed (45) hide show
  1. package/README.md +5 -5
  2. package/apollo-client.cjs +105 -50
  3. package/apollo-client.cjs.map +1 -1
  4. package/apollo-client.min.cjs +1 -1
  5. package/cache/core/types/common.d.ts +3 -2
  6. package/cache/core/types/common.d.ts.map +1 -1
  7. package/cache/core/types/common.js.map +1 -1
  8. package/cache/index.d.ts +1 -1
  9. package/cache/index.d.ts.map +1 -1
  10. package/cache/index.js.map +1 -1
  11. package/core/ApolloClient.js +1 -1
  12. package/core/ApolloClient.js.map +1 -1
  13. package/core/QueryInfo.d.ts.map +1 -1
  14. package/core/QueryInfo.js +8 -17
  15. package/core/QueryInfo.js.map +1 -1
  16. package/core/QueryManager.d.ts.map +1 -1
  17. package/core/QueryManager.js +52 -28
  18. package/core/QueryManager.js.map +1 -1
  19. package/core/core.cjs +148 -46
  20. package/core/core.cjs.map +1 -1
  21. package/core/core.cjs.native.js +148 -46
  22. package/errors/errors.cjs +1 -0
  23. package/errors/errors.cjs.map +1 -1
  24. package/errors/errors.cjs.native.js +1 -0
  25. package/errors/index.d.ts +1 -0
  26. package/errors/index.d.ts.map +1 -1
  27. package/errors/index.js +1 -0
  28. package/errors/index.js.map +1 -1
  29. package/invariantErrorCodes.js +1 -1
  30. package/package.json +17 -15
  31. package/react/hooks/useMutation.d.ts +1 -1
  32. package/react/hooks/useMutation.d.ts.map +1 -1
  33. package/react/hooks/useMutation.js.map +1 -1
  34. package/utilities/common/errorHandling.d.ts +3 -2
  35. package/utilities/common/errorHandling.d.ts.map +1 -1
  36. package/utilities/common/errorHandling.js +18 -1
  37. package/utilities/common/errorHandling.js.map +1 -1
  38. package/utilities/common/incrementalResult.d.ts +5 -2
  39. package/utilities/common/incrementalResult.d.ts.map +1 -1
  40. package/utilities/common/incrementalResult.js +29 -1
  41. package/utilities/common/incrementalResult.js.map +1 -1
  42. package/utilities/utilities.cjs +21 -1
  43. package/utilities/utilities.cjs.map +1 -1
  44. package/utilities/utilities.cjs.native.js +21 -1
  45. package/version.js +1 -1
@@ -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.1';
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 !!value.incremental;
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 mergedData_1 = this.getDiff().result;
992
- var merger_1 = new utilities.DeepMerger();
993
- result.incremental.forEach(function (_a) {
994
- var data = _a.data, path = _a.path, errors = _a.errors;
995
- for (var i = path.length - 1; i >= 0; --i) {
996
- var key = path[i];
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.errors,
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
- resolve(storeResult);
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
- cacheWrites.push({
1227
- result: result.data,
1228
- dataId: 'ROOT_MUTATION',
1229
- query: mutation.document,
1230
- variables: mutation.variables,
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 && !(isExecutionPatchIncrementalResult(result))) {
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
- update(cache, result, {
1292
- context: mutation.context,
1293
- variables: mutation.variables,
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) {
@@ -1659,20 +1771,10 @@ var QueryManager = (function () {
1659
1771
  };
1660
1772
  QueryManager.prototype.getResultsFromLink = function (queryInfo, cacheWriteBehavior, options) {
1661
1773
  var requestId = queryInfo.lastRequestId = this.generateRequestId();
1662
- options = utilities.cloneDeep(options);
1663
1774
  var linkDocument = this.cache.transformForLink(this.transform(queryInfo.document).document);
1664
1775
  return utilities.asyncMap(this.getObservableFromLink(linkDocument, options.context, options.variables), function (result) {
1665
- var graphQLErrors = utilities.isNonEmptyArray(result.errors)
1666
- ? result.errors.slice(0)
1667
- : [];
1668
- if ('incremental' in result && utilities.isNonEmptyArray(result.incremental)) {
1669
- result.incremental.forEach(function (incrementalResult) {
1670
- if (incrementalResult.errors) {
1671
- graphQLErrors.push.apply(graphQLErrors, incrementalResult.errors);
1672
- }
1673
- });
1674
- }
1675
- var hasErrors = utilities.isNonEmptyArray(graphQLErrors);
1776
+ var graphQLErrors = utilities.getGraphQLErrorsFromResult(result);
1777
+ var hasErrors = graphQLErrors.length > 0;
1676
1778
  if (requestId >= queryInfo.lastRequestId) {
1677
1779
  if (hasErrors && options.errorPolicy === "none") {
1678
1780
  throw queryInfo.markError(new errors.ApolloError({
@@ -1958,7 +2060,7 @@ var ApolloClient = (function () {
1958
2060
  if (connectToDevTools && typeof window === 'object') {
1959
2061
  window.__APOLLO_CLIENT__ = this;
1960
2062
  }
1961
- if (!hasSuggestedDevtools && __DEV__) {
2063
+ if (!hasSuggestedDevtools && connectToDevTools && __DEV__) {
1962
2064
  hasSuggestedDevtools = true;
1963
2065
  if (typeof window !== 'undefined' &&
1964
2066
  window.document &&
package/errors/errors.cjs CHANGED
@@ -32,6 +32,7 @@ var ApolloError = (function (_super) {
32
32
  function ApolloError(_a) {
33
33
  var graphQLErrors = _a.graphQLErrors, clientErrors = _a.clientErrors, networkError = _a.networkError, errorMessage = _a.errorMessage, extraInfo = _a.extraInfo;
34
34
  var _this = _super.call(this, errorMessage) || this;
35
+ _this.name = 'ApolloError';
35
36
  _this.graphQLErrors = graphQLErrors || [];
36
37
  _this.clientErrors = clientErrors || [];
37
38
  _this.networkError = networkError || null;
@@ -1 +1 @@
1
- {"version":3,"file":"errors.cjs","sources":["index.js"],"sourcesContent":["import { __extends } from \"tslib\";\nimport '../utilities/globals';\nimport { isNonEmptyArray } from '../utilities';\nexport function isApolloError(err) {\n return err.hasOwnProperty('graphQLErrors');\n}\nvar generateErrorMessage = function (err) {\n var message = '';\n if (isNonEmptyArray(err.graphQLErrors) || isNonEmptyArray(err.clientErrors)) {\n var errors = (err.graphQLErrors || [])\n .concat(err.clientErrors || []);\n errors.forEach(function (error) {\n var errorMessage = error\n ? error.message\n : 'Error message not found.';\n message += \"\".concat(errorMessage, \"\\n\");\n });\n }\n if (err.networkError) {\n message += \"\".concat(err.networkError.message, \"\\n\");\n }\n message = message.replace(/\\n$/, '');\n return message;\n};\nvar ApolloError = (function (_super) {\n __extends(ApolloError, _super);\n function ApolloError(_a) {\n var graphQLErrors = _a.graphQLErrors, clientErrors = _a.clientErrors, networkError = _a.networkError, errorMessage = _a.errorMessage, extraInfo = _a.extraInfo;\n var _this = _super.call(this, errorMessage) || this;\n _this.graphQLErrors = graphQLErrors || [];\n _this.clientErrors = clientErrors || [];\n _this.networkError = networkError || null;\n _this.message = errorMessage || generateErrorMessage(_this);\n _this.extraInfo = extraInfo;\n _this.__proto__ = ApolloError.prototype;\n return _this;\n }\n return ApolloError;\n}(Error));\nexport { ApolloError };\n//# sourceMappingURL=index.js.map"],"names":["isNonEmptyArray","__extends"],"mappings":";;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AY,GAAG,EAAE,CAAC,YAAY,EAAE,YAAY,GAAG,EAAE,CAAC,YAAY,EAAE,SAAS,GAAG,EAAE,CAAC,SAAS,CAAC;AACvK,QAAQ,IAAI,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,YAAY,CAAC,IAAI,IAAI,CAAC;AAC5D,QAAQ,KAAK,CAAC,aAAa,GAAG,aAAa,IAAI,EAAE,CAAC;AAClD,QAAQ,KAAK,CAAC,YAAY,GAAG,YAAY,IAAI,EAAE,CAAC;AAChD,QAAQ,KAAK,CAAC,YAAY,GAAG,YAAY,IAAI,IAAI,CAAC;AAClD,QAAQ,KAAK,CAAC,OAAO,GAAG,YAAY,IAAI,oBAAoB,CAAC,KAAK,CAAC,CAAC;AACpE,QAAQ,KAAK,CAAC,SAAS,GAAG,SAAS,CAAC;AACpC,QAAQ,KAAK,CAAC,SAAS,GAAG,WAAW,CAAC,SAAS,CAAC;AAChD,QAAQ,OAAO,KAAK,CAAC;AACrB,KAAK;AACL,IAAI,OAAO,WAAW,CAAC;AACvB,CAAC,CAAC,KAAK,CAAC;;;;;"}
1
+ {"version":3,"file":"errors.cjs","sources":["index.js"],"sourcesContent":["import { __extends } from \"tslib\";\nimport '../utilities/globals';\nimport { isNonEmptyArray } from '../utilities';\nexport function isApolloError(err) {\n return err.hasOwnProperty('graphQLErrors');\n}\nvar generateErrorMessage = function (err) {\n var message = '';\n if (isNonEmptyArray(err.graphQLErrors) || isNonEmptyArray(err.clientErrors)) {\n var errors = (err.graphQLErrors || [])\n .concat(err.clientErrors || []);\n errors.forEach(function (error) {\n var errorMessage = error\n ? error.message\n : 'Error message not found.';\n message += \"\".concat(errorMessage, \"\\n\");\n });\n }\n if (err.networkError) {\n message += \"\".concat(err.networkError.message, \"\\n\");\n }\n message = message.replace(/\\n$/, '');\n return message;\n};\nvar ApolloError = (function (_super) {\n __extends(ApolloError, _super);\n function ApolloError(_a) {\n var graphQLErrors = _a.graphQLErrors, clientErrors = _a.clientErrors, networkError = _a.networkError, errorMessage = _a.errorMessage, extraInfo = _a.extraInfo;\n var _this = _super.call(this, errorMessage) || this;\n _this.name = 'ApolloError';\n _this.graphQLErrors = graphQLErrors || [];\n _this.clientErrors = clientErrors || [];\n _this.networkError = networkError || null;\n _this.message = errorMessage || generateErrorMessage(_this);\n _this.extraInfo = extraInfo;\n _this.__proto__ = ApolloError.prototype;\n return _this;\n }\n return ApolloError;\n}(Error));\nexport { ApolloError };\n//# sourceMappingURL=index.js.map"],"names":["isNonEmptyArray","__extends"],"mappings":";;;;;;;;AAGO,SAAS,aAAa,CAAC,GAAG,EAAE;AACnC,IAAI,OAAO,GAAG,CAAC,cAAc,CAAC,eAAe,CAAC,CAAC;AAC/C,CAAC;AACD,IAAI,oBAAoB,GAAG,UAAU,GAAG,EAAE;AAC1C,IAAI,IAAI,OAAO,GAAG,EAAE,CAAC;AACrB,IAAI,IAAIA,yBAAe,CAAC,GAAG,CAAC,aAAa,CAAC,IAAIA,yBAAe,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE;AACjF,QAAQ,IAAI,MAAM,GAAG,CAAC,GAAG,CAAC,aAAa,IAAI,EAAE;AAC7C,aAAa,MAAM,CAAC,GAAG,CAAC,YAAY,IAAI,EAAE,CAAC,CAAC;AAC5C,QAAQ,MAAM,CAAC,OAAO,CAAC,UAAU,KAAK,EAAE;AACxC,YAAY,IAAI,YAAY,GAAG,KAAK;AACpC,kBAAkB,KAAK,CAAC,OAAO;AAC/B,kBAAkB,0BAA0B,CAAC;AAC7C,YAAY,OAAO,IAAI,EAAE,CAAC,MAAM,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;AACrD,SAAS,CAAC,CAAC;AACX,KAAK;AACL,IAAI,IAAI,GAAG,CAAC,YAAY,EAAE;AAC1B,QAAQ,OAAO,IAAI,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,YAAY,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;AAC7D,KAAK;AACL,IAAI,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AACzC,IAAI,OAAO,OAAO,CAAC;AACnB,CAAC,CAAC;AACC,IAAC,WAAW,IAAI,UAAU,MAAM,EAAE;AACrC,IAAIC,eAAS,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;AACnC,IAAI,SAAS,WAAW,CAAC,EAAE,EAAE;AAC7B,QAAQ,IAAI,aAAa,GAAG,EAAE,CAAC,aAAa,EAAE,YAAY,GAAG,EAAE,CAAC,YAAY,EAAE,YAAY,GAAG,EAAE,CAAC,YAAY,EAAE,YAAY,GAAG,EAAE,CAAC,YAAY,EAAE,SAAS,GAAG,EAAE,CAAC,SAAS,CAAC;AACvK,QAAQ,IAAI,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,YAAY,CAAC,IAAI,IAAI,CAAC;AAC5D,QAAQ,KAAK,CAAC,IAAI,GAAG,aAAa,CAAC;AACnC,QAAQ,KAAK,CAAC,aAAa,GAAG,aAAa,IAAI,EAAE,CAAC;AAClD,QAAQ,KAAK,CAAC,YAAY,GAAG,YAAY,IAAI,EAAE,CAAC;AAChD,QAAQ,KAAK,CAAC,YAAY,GAAG,YAAY,IAAI,IAAI,CAAC;AAClD,QAAQ,KAAK,CAAC,OAAO,GAAG,YAAY,IAAI,oBAAoB,CAAC,KAAK,CAAC,CAAC;AACpE,QAAQ,KAAK,CAAC,SAAS,GAAG,SAAS,CAAC;AACpC,QAAQ,KAAK,CAAC,SAAS,GAAG,WAAW,CAAC,SAAS,CAAC;AAChD,QAAQ,OAAO,KAAK,CAAC;AACrB,KAAK;AACL,IAAI,OAAO,WAAW,CAAC;AACvB,CAAC,CAAC,KAAK,CAAC;;;;;"}
@@ -32,6 +32,7 @@ var ApolloError = (function (_super) {
32
32
  function ApolloError(_a) {
33
33
  var graphQLErrors = _a.graphQLErrors, clientErrors = _a.clientErrors, networkError = _a.networkError, errorMessage = _a.errorMessage, extraInfo = _a.extraInfo;
34
34
  var _this = _super.call(this, errorMessage) || this;
35
+ _this.name = 'ApolloError';
35
36
  _this.graphQLErrors = graphQLErrors || [];
36
37
  _this.clientErrors = clientErrors || [];
37
38
  _this.networkError = networkError || null;
package/errors/index.d.ts CHANGED
@@ -6,6 +6,7 @@ export declare function isApolloError(err: Error): err is ApolloError;
6
6
  export declare type GraphQLErrors = ReadonlyArray<GraphQLError>;
7
7
  export declare type NetworkError = Error | ServerParseError | ServerError | null;
8
8
  export declare class ApolloError extends Error {
9
+ name: string;
9
10
  message: string;
10
11
  graphQLErrors: GraphQLErrors;
11
12
  clientErrors: ReadonlyArray<Error>;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAE9B,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAGvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,wBAAgB,aAAa,CAAC,GAAG,EAAE,KAAK,GAAG,GAAG,IAAI,WAAW,CAE5D;AA6BD,oBAAY,aAAa,GAAG,aAAa,CAAC,YAAY,CAAC,CAAC;AAExD,oBAAY,YAAY,GAAG,KAAK,GAAG,gBAAgB,GAAG,WAAW,GAAG,IAAI,CAAC;AAEzE,qBAAa,WAAY,SAAQ,KAAK;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,aAAa,CAAC;IAC7B,YAAY,EAAE,aAAa,CAAC,KAAK,CAAC,CAAC;IACnC,YAAY,EAAE,KAAK,GAAG,gBAAgB,GAAG,WAAW,GAAG,IAAI,CAAC;IAK5D,SAAS,EAAE,GAAG,CAAC;gBAKV,EACV,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,SAAS,GACV,EAAE;QACD,aAAa,CAAC,EAAE,aAAa,CAAC,YAAY,CAA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EAAE,MAAM,CAAC;QACtB,SAAS,CAAC,EAAE,GAAG,CAAC;KACjB;CAaF"}
package/errors/index.js CHANGED
@@ -27,6 +27,7 @@ var ApolloError = (function (_super) {
27
27
  function ApolloError(_a) {
28
28
  var graphQLErrors = _a.graphQLErrors, clientErrors = _a.clientErrors, networkError = _a.networkError, errorMessage = _a.errorMessage, extraInfo = _a.extraInfo;
29
29
  var _this = _super.call(this, errorMessage) || this;
30
+ _this.name = 'ApolloError';
30
31
  _this.graphQLErrors = graphQLErrors || [];
31
32
  _this.clientErrors = clientErrors || [];
32
33
  _this.networkError = networkError || null;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":";AAAA,OAAO,sBAAsB,CAAC;AAI9B,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAI/C,MAAM,UAAU,aAAa,CAAC,GAAU;IACtC,OAAO,GAAG,CAAC,cAAc,CAAC,eAAe,CAAC,CAAC;AAC7C,CAAC;AAMD,IAAM,oBAAoB,GAAG,UAAC,GAAgB;IAC5C,IAAI,OAAO,GAAG,EAAE,CAAC;IAEjB,IAAI,eAAe,CAAC,GAAG,CAAC,aAAa,CAAC,IAAI,eAAe,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE;QAC3E,IAAM,MAAM,GAAI,CAAC,GAAG,CAAC,aAAa,IAAI,EAAE,CAAsB;aAC3D,MAAM,CAAC,GAAG,CAAC,YAAY,IAAI,EAAE,CAAC,CAAC;QAClC,MAAM,CAAC,OAAO,CAAC,UAAC,KAAY;YAC1B,IAAM,YAAY,GAAG,KAAK;gBACxB,CAAC,CAAC,KAAK,CAAC,OAAO;gBACf,CAAC,CAAC,0BAA0B,CAAC;YAC/B,OAAO,IAAI,UAAG,YAAY,OAAI,CAAC;QACjC,CAAC,CAAC,CAAC;KACJ;IAED,IAAI,GAAG,CAAC,YAAY,EAAE;QACpB,OAAO,IAAI,UAAG,GAAG,CAAC,YAAY,CAAC,OAAO,OAAI,CAAC;KAC5C;IAGD,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACrC,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAMF;IAAiC,+BAAK;IAcpC,qBAAY,EAYX;YAXC,aAAa,mBAAA,EACb,YAAY,kBAAA,EACZ,YAAY,kBAAA,EACZ,YAAY,kBAAA,EACZ,SAAS,eAAA;QALX,YAaE,kBAAM,YAAY,CAAC,SAUpB;QATC,KAAI,CAAC,aAAa,GAAG,aAAa,IAAI,EAAE,CAAC;QACzC,KAAI,CAAC,YAAY,GAAG,YAAY,IAAI,EAAE,CAAC;QACvC,KAAI,CAAC,YAAY,GAAG,YAAY,IAAI,IAAI,CAAC;QACzC,KAAI,CAAC,OAAO,GAAG,YAAY,IAAI,oBAAoB,CAAC,KAAI,CAAC,CAAC;QAC1D,KAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAI1B,KAAY,CAAC,SAAS,GAAG,WAAW,CAAC,SAAS,CAAC;;IAClD,CAAC;IACH,kBAAC;AAAD,CAAC,AAtCD,CAAiC,KAAK,GAsCrC","sourcesContent":["import '../utilities/globals';\n\nimport { GraphQLError } from 'graphql';\n\nimport { isNonEmptyArray } from '../utilities';\nimport { ServerParseError } from '../link/http';\nimport { ServerError } from '../link/utils';\n\nexport function isApolloError(err: Error): err is ApolloError {\n return err.hasOwnProperty('graphQLErrors');\n}\n\n// Sets the error message on this error according to the\n// the GraphQL and network errors that are present.\n// If the error message has already been set through the\n// constructor or otherwise, this function is a nop.\nconst generateErrorMessage = (err: ApolloError) => {\n let message = '';\n // If we have GraphQL errors present, add that to the error message.\n if (isNonEmptyArray(err.graphQLErrors) || isNonEmptyArray(err.clientErrors)) {\n const errors = ((err.graphQLErrors || []) as readonly Error[])\n .concat(err.clientErrors || []);\n errors.forEach((error: Error) => {\n const errorMessage = error\n ? error.message\n : 'Error message not found.';\n message += `${errorMessage}\\n`;\n });\n }\n\n if (err.networkError) {\n message += `${err.networkError.message}\\n`;\n }\n\n // strip newline from the end of the message\n message = message.replace(/\\n$/, '');\n return message;\n};\n\nexport type GraphQLErrors = ReadonlyArray<GraphQLError>;\n\nexport type NetworkError = Error | ServerParseError | ServerError | null;\n\nexport class ApolloError extends Error {\n public message: string;\n public graphQLErrors: GraphQLErrors;\n public clientErrors: ReadonlyArray<Error>;\n public networkError: Error | ServerParseError | ServerError | null;\n\n // An object that can be used to provide some additional information\n // about an error, e.g. specifying the type of error this is. Used\n // internally within Apollo Client.\n public extraInfo: any;\n\n // Constructs an instance of ApolloError given a GraphQLError\n // or a network error. Note that one of these has to be a valid\n // value or the constructed error will be meaningless.\n constructor({\n graphQLErrors,\n clientErrors,\n networkError,\n errorMessage,\n extraInfo,\n }: {\n graphQLErrors?: ReadonlyArray<GraphQLError>;\n clientErrors?: ReadonlyArray<Error>;\n networkError?: Error | ServerParseError | ServerError | null;\n errorMessage?: string;\n extraInfo?: any;\n }) {\n super(errorMessage);\n this.graphQLErrors = graphQLErrors || [];\n this.clientErrors = clientErrors || [];\n this.networkError = networkError || null;\n this.message = errorMessage || generateErrorMessage(this);\n this.extraInfo = extraInfo;\n\n // We're not using `Object.setPrototypeOf` here as it isn't fully\n // supported on Android (see issue #3236).\n (this as any).__proto__ = ApolloError.prototype;\n }\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":";AAAA,OAAO,sBAAsB,CAAC;AAI9B,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAI/C,MAAM,UAAU,aAAa,CAAC,GAAU;IACtC,OAAO,GAAG,CAAC,cAAc,CAAC,eAAe,CAAC,CAAC;AAC7C,CAAC;AAMD,IAAM,oBAAoB,GAAG,UAAC,GAAgB;IAC5C,IAAI,OAAO,GAAG,EAAE,CAAC;IAEjB,IAAI,eAAe,CAAC,GAAG,CAAC,aAAa,CAAC,IAAI,eAAe,CAAC,GAA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';\n\nimport { GraphQLError } from 'graphql';\n\nimport { isNonEmptyArray } from '../utilities';\nimport { ServerParseError } from '../link/http';\nimport { ServerError } from '../link/utils';\n\nexport function isApolloError(err: Error): err is ApolloError {\n return err.hasOwnProperty('graphQLErrors');\n}\n\n// Sets the error message on this error according to the\n// the GraphQL and network errors that are present.\n// If the error message has already been set through the\n// constructor or otherwise, this function is a nop.\nconst generateErrorMessage = (err: ApolloError) => {\n let message = '';\n // If we have GraphQL errors present, add that to the error message.\n if (isNonEmptyArray(err.graphQLErrors) || isNonEmptyArray(err.clientErrors)) {\n const errors = ((err.graphQLErrors || []) as readonly Error[])\n .concat(err.clientErrors || []);\n errors.forEach((error: Error) => {\n const errorMessage = error\n ? error.message\n : 'Error message not found.';\n message += `${errorMessage}\\n`;\n });\n }\n\n if (err.networkError) {\n message += `${err.networkError.message}\\n`;\n }\n\n // strip newline from the end of the message\n message = message.replace(/\\n$/, '');\n return message;\n};\n\nexport type GraphQLErrors = ReadonlyArray<GraphQLError>;\n\nexport type NetworkError = Error | ServerParseError | ServerError | null;\n\nexport class ApolloError extends Error {\n public name: string;\n public message: string;\n public graphQLErrors: GraphQLErrors;\n public clientErrors: ReadonlyArray<Error>;\n public networkError: Error | ServerParseError | ServerError | null;\n\n // An object that can be used to provide some additional information\n // about an error, e.g. specifying the type of error this is. Used\n // internally within Apollo Client.\n public extraInfo: any;\n\n // Constructs an instance of ApolloError given a GraphQLError\n // or a network error. Note that one of these has to be a valid\n // value or the constructed error will be meaningless.\n constructor({\n graphQLErrors,\n clientErrors,\n networkError,\n errorMessage,\n extraInfo,\n }: {\n graphQLErrors?: ReadonlyArray<GraphQLError>;\n clientErrors?: ReadonlyArray<Error>;\n networkError?: Error | ServerParseError | ServerError | null;\n errorMessage?: string;\n extraInfo?: any;\n }) {\n super(errorMessage);\n this.name = 'ApolloError';\n this.graphQLErrors = graphQLErrors || [];\n this.clientErrors = clientErrors || [];\n this.networkError = networkError || null;\n this.message = errorMessage || generateErrorMessage(this);\n this.extraInfo = extraInfo;\n\n // We're not using `Object.setPrototypeOf` here as it isn't fully\n // supported on Android (see issue #3236).\n (this as any).__proto__ = ApolloError.prototype;\n }\n}\n"]}
@@ -5,7 +5,7 @@
5
5
  // consult the @apollo/client/invariantErrorCodes.js file specific to
6
6
  // your @apollo/client version. This file is not meant to be imported.
7
7
  {
8
- "@apollo/client version": "3.7.1",
8
+ "@apollo/client version": "3.7.3",
9
9
 
10
10
  1: {
11
11
  file: "@apollo/client/cache/inmemory/entityStore.js",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apollo/client",
3
- "version": "3.7.1",
3
+ "version": "3.7.3",
4
4
  "description": "A fully-featured caching GraphQL client.",
5
5
  "private": false,
6
6
  "keywords": [
@@ -66,8 +66,10 @@
66
66
  "zen-observable-ts": "^1.2.5"
67
67
  },
68
68
  "devDependencies": {
69
- "@babel/parser": "7.19.4",
70
- "@graphql-tools/schema": "9.0.4",
69
+ "@babel/parser": "7.20.5",
70
+ "@changesets/changelog-github": "0.4.7",
71
+ "@changesets/cli": "2.25.2",
72
+ "@graphql-tools/schema": "9.0.12",
71
73
  "@rollup/plugin-node-resolve": "11.2.1",
72
74
  "@testing-library/react": "13.4.0",
73
75
  "@testing-library/react-12": "npm:@testing-library/react@^12",
@@ -78,14 +80,14 @@
78
80
  "@types/fetch-mock": "7.3.5",
79
81
  "@types/glob": "8.0.0",
80
82
  "@types/hoist-non-react-statics": "3.3.1",
81
- "@types/jest": "29.1.2",
82
- "@types/lodash": "4.14.186",
83
- "@types/node": "16.11.66",
83
+ "@types/jest": "29.2.4",
84
+ "@types/lodash": "4.14.191",
85
+ "@types/node": "18.11.13",
84
86
  "@types/node-fetch": "2.6.2",
85
- "@types/react": "18.0.21",
86
- "@types/react-dom": "18.0.6",
87
+ "@types/react": "18.0.26",
88
+ "@types/react-dom": "18.0.9",
87
89
  "@types/use-sync-external-store": "0.0.3",
88
- "acorn": "8.8.0",
90
+ "acorn": "8.8.1",
89
91
  "blob-polyfill": "7.0.20220408",
90
92
  "bytes": "3.1.2",
91
93
  "cross-fetch": "3.1.5",
@@ -93,22 +95,22 @@
93
95
  "glob": "8.0.3",
94
96
  "graphql": "16.6.0",
95
97
  "graphql-ws": "5.11.2",
96
- "jest": "29.2.0",
97
- "jest-environment-jsdom": "29.2.0",
98
- "jest-junit": "14.0.1",
98
+ "jest": "29.3.1",
99
+ "jest-environment-jsdom": "29.3.1",
100
+ "jest-junit": "15.0.0",
99
101
  "lodash": "4.17.21",
100
102
  "react": "18.2.0",
101
103
  "react-17": "npm:react@^17",
102
104
  "react-dom": "18.2.0",
103
105
  "react-dom-17": "npm:react-dom@^17",
104
- "recast": "0.21.5",
106
+ "recast": "0.22.0",
105
107
  "resolve": "1.22.1",
106
108
  "rimraf": "3.0.2",
107
109
  "rollup": "2.79.1",
108
110
  "rollup-plugin-terser": "7.0.2",
109
- "rxjs": "7.5.7",
111
+ "rxjs": "7.6.0",
110
112
  "subscriptions-transport-ws": "0.11.0",
111
- "terser": "5.15.1",
113
+ "terser": "5.16.1",
112
114
  "ts-jest": "29.0.3",
113
115
  "ts-node": "10.9.1",
114
116
  "typedoc": "0.22.18",
@@ -2,5 +2,5 @@ import { DocumentNode } from 'graphql';
2
2
  import { TypedDocumentNode } from '@graphql-typed-document-node/core';
3
3
  import { MutationHookOptions, MutationTuple } from '../types/types';
4
4
  import { ApolloCache, DefaultContext, OperationVariables } from '../../core';
5
- export declare function useMutation<TData = any, TVariables = OperationVariables, TContext = DefaultContext, TCache extends ApolloCache<any> = ApolloCache<any>>(mutation: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: MutationHookOptions<TData, TVariables, TContext>): MutationTuple<TData, TVariables, TContext, TCache>;
5
+ export declare function useMutation<TData = any, TVariables = OperationVariables, TContext = DefaultContext, TCache extends ApolloCache<any> = ApolloCache<any>>(mutation: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: MutationHookOptions<TData, TVariables, TContext, TCache>): MutationTuple<TData, TVariables, TContext, TCache>;
6
6
  //# sourceMappingURL=useMutation.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useMutation.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useMutation.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAEL,mBAAmB,EAEnB,aAAa,EACd,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,WAAW,EACX,cAAc,EAEd,kBAAkB,EACnB,MAAM,YAAY,CAAC;AAMpB,wBAAgB,WAAW,CACzB,KAAK,GAAG,GAAG,EACX,UAAU,GAAG,kBAAkB,EAC/B,QAAQ,GAAG,cAAc,EACzB,MAAM,SAAS,WAAW,CAAC,GAAG,CAAC,GAAG,WAAW,CAAC,GAAG,CAAC,EAElD,QAAQ,EAAE,YAAY,GAAG,iBAAiB,CAAC,KAAK,EAAE,UAAU,CAAC,EAC7D,OAAO,CAAC,EAAE,mBAAmB,CAAC,KAAK,EAAE,UAAU,EAAE,QAAQ,CAAC,GACzD,aAAa,CAAC,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,CAAC,CAwHpD"}
1
+ {"version":3,"file":"useMutation.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useMutation.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAEL,mBAAmB,EAEnB,aAAa,EACd,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,WAAW,EACX,cAAc,EAEd,kBAAkB,EACnB,MAAM,YAAY,CAAC;AAMpB,wBAAgB,WAAW,CACzB,KAAK,GAAG,GAAG,EACX,UAAU,GAAG,kBAAkB,EAC/B,QAAQ,GAAG,cAAc,EACzB,MAAM,SAAS,WAAW,CAAC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C,OAAO,0CAAE,OAAO,mDAAG,KAAK,EAAE,aAAa,CAAC,CAAC;gBACrD,MAAA,cAAc,CAAC,OAAO,+DAAG,KAAK,EAAE,aAAa,CAAC,CAAC;gBAE/C,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;aACxC;YAED,MAAM,KAAK,CAAC;QACd,CAAC,CAAC,CAAC;IACL,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,IAAM,KAAK,GAAG,WAAW,CAAC;QACxB,IAAI,GAAG,CAAC,OAAO,CAAC,SAAS,EAAE;YACzB,SAAS,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,QAAA,EAAE,CAAC,CAAC;SACtD;IACH,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,SAAS,CAAC;QACR,GAAG,CAAC,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC;QAE7B,OAAO;YACL,GAAG,CAAC,OAAO,CAAC,SAAS,GAAG,KAAK,CAAC;QAChC,CAAC,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,CAAC,OAAO,aAAI,KAAK,OAAA,IAAK,MAAM,EAAG,CAAC;AACzC,CAAC","sourcesContent":["import { useCallback, useEffect, useRef, useState } from 'react';\nimport { DocumentNode } from 'graphql';\nimport { TypedDocumentNode } from '@graphql-typed-document-node/core';\nimport {\n MutationFunctionOptions,\n MutationHookOptions,\n MutationResult,\n MutationTuple,\n} from '../types/types';\n\nimport {\n ApolloCache,\n DefaultContext,\n mergeOptions,\n OperationVariables,\n} from '../../core';\nimport { equal } from '@wry/equality';\nimport { DocumentType, verifyDocumentType } from '../parser';\nimport { ApolloError } from '../../errors';\nimport { useApolloClient } from './useApolloClient';\n\nexport function useMutation<\n TData = any,\n TVariables = OperationVariables,\n TContext = DefaultContext,\n TCache extends ApolloCache<any> = ApolloCache<any>,\n>(\n mutation: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: MutationHookOptions<TData, TVariables, TContext>,\n): MutationTuple<TData, TVariables, TContext, TCache> {\n const client = useApolloClient(options?.client);\n verifyDocumentType(mutation, DocumentType.Mutation);\n const [result, setResult] = useState<Omit<MutationResult, 'reset'>>({\n called: false,\n loading: false,\n client,\n });\n\n const ref = useRef({\n result,\n mutationId: 0,\n isMounted: true,\n client,\n mutation,\n options,\n });\n\n // TODO: Trying to assign these in a useEffect or useLayoutEffect breaks\n // higher-order components.\n {\n Object.assign(ref.current, { client, options, mutation });\n }\n\n const execute = useCallback((\n executeOptions: MutationFunctionOptions<\n TData,\n TVariables,\n TContext,\n TCache\n > = {}\n ) => {\n const {client, options, mutation} = ref.current;\n const baseOptions = { ...options, mutation };\n if (!ref.current.result.loading && !baseOptions.ignoreResults && ref.current.isMounted) {\n setResult(ref.current.result = {\n loading: true,\n error: void 0,\n data: void 0,\n called: true,\n client,\n });\n }\n\n const mutationId = ++ref.current.mutationId;\n const clientOptions = mergeOptions(\n baseOptions,\n executeOptions as any,\n );\n\n return client.mutate(clientOptions).then((response) => {\n const { data, errors } = response;\n const error =\n errors && errors.length > 0\n ? new ApolloError({ graphQLErrors: errors })\n : void 0;\n\n if (\n mutationId === ref.current.mutationId &&\n !clientOptions.ignoreResults\n ) {\n const result = {\n called: true,\n loading: false,\n data,\n error,\n client,\n };\n\n if (ref.current.isMounted && !equal(ref.current.result, result)) {\n setResult(ref.current.result = result);\n }\n }\n ref.current.options?.onCompleted?.(response.data!, clientOptions);\n executeOptions.onCompleted?.(response.data!, clientOptions);\n return response;\n }).catch((error) => {\n if (\n mutationId === ref.current.mutationId &&\n ref.current.isMounted\n ) {\n const result = {\n loading: false,\n error,\n data: void 0,\n called: true,\n client,\n };\n\n if (!equal(ref.current.result, result)) {\n setResult(ref.current.result = result);\n }\n }\n\n if (ref.current.options?.onError || clientOptions.onError) {\n ref.current.options?.onError?.(error, clientOptions);\n executeOptions.onError?.(error, clientOptions);\n // TODO(brian): why are we returning this here???\n return { data: void 0, errors: error };\n }\n\n throw error;\n });\n }, []);\n\n const reset = useCallback(() => {\n if (ref.current.isMounted) {\n setResult({ called: false, loading: false, client });\n }\n }, []);\n\n useEffect(() => {\n ref.current.isMounted = true;\n\n return () => {\n ref.current.isMounted = false;\n };\n }, []);\n\n return [execute, { reset, ...result }];\n}\n"]}
1
+ {"version":3,"file":"useMutation.js","sourceRoot":"","sources":["../../../src/react/hooks/useMutation.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAUjE,OAAO,EAGL,YAAY,GAEb,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,MAAM,UAAU,WAAW,CAMzB,QAA6D,EAC7D,OAAkE;IAElE,IAAM,MAAM,GAAG,eAAe,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM,CAAC,CAAC;IAChD,kBAAkB,CAAC,QAAQ,EAAE,YAAY,CAAC,QAAQ,CAAC,CAAC;IAC9C,IAAA,KAAsB,QAAQ,CAAgC;QAClE,MAAM,EAAE,KAAK;QACb,OAAO,EAAE,KAAK;QACd,MAAM,QAAA;KACP,CAAC,EAJK,MAAM,QAAA,EAAE,SAAS,QAItB,CAAC;IAEH,IAAM,GAAG,GAAG,MAAM,CAAC;QACjB,MAAM,QAAA;QACN,UAAU,EAAE,CAAC;QACb,SAAS,EAAE,IAAI;QACf,MAAM,QAAA;QACN,QAAQ,UAAA;QACR,OAAO,SAAA;KACR,CAAC,CAAC;IAIH;QACE,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,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,cAAc,CAAC,OAAO,+DAAG,KAAK,EAAE,aAAa,CAAC,CAAC;gBAE/C,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;aACxC;YAED,MAAM,KAAK,CAAC;QACd,CAAC,CAAC,CAAC;IACL,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,IAAM,KAAK,GAAG,WAAW,CAAC;QACxB,IAAI,GAAG,CAAC,OAAO,CAAC,SAAS,EAAE;YACzB,SAAS,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,QAAA,EAAE,CAAC,CAAC;SACtD;IACH,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,SAAS,CAAC;QACR,GAAG,CAAC,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC;QAE7B,OAAO;YACL,GAAG,CAAC,OAAO,CAAC,SAAS,GAAG,KAAK,CAAC;QAChC,CAAC,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,CAAC,OAAO,aAAI,KAAK,OAAA,IAAK,MAAM,EAAG,CAAC;AACzC,CAAC","sourcesContent":["import { useCallback, useEffect, useRef, useState } from 'react';\nimport { DocumentNode } from 'graphql';\nimport { TypedDocumentNode } from '@graphql-typed-document-node/core';\nimport {\n MutationFunctionOptions,\n MutationHookOptions,\n MutationResult,\n MutationTuple,\n} from '../types/types';\n\nimport {\n ApolloCache,\n DefaultContext,\n mergeOptions,\n OperationVariables,\n} from '../../core';\nimport { equal } from '@wry/equality';\nimport { DocumentType, verifyDocumentType } from '../parser';\nimport { ApolloError } from '../../errors';\nimport { useApolloClient } from './useApolloClient';\n\nexport function useMutation<\n TData = any,\n TVariables = OperationVariables,\n TContext = DefaultContext,\n TCache extends ApolloCache<any> = ApolloCache<any>,\n>(\n mutation: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: MutationHookOptions<TData, TVariables, TContext, TCache>,\n): MutationTuple<TData, TVariables, TContext, TCache> {\n const client = useApolloClient(options?.client);\n verifyDocumentType(mutation, DocumentType.Mutation);\n const [result, setResult] = useState<Omit<MutationResult, 'reset'>>({\n called: false,\n loading: false,\n client,\n });\n\n const ref = useRef({\n result,\n mutationId: 0,\n isMounted: true,\n client,\n mutation,\n options,\n });\n\n // TODO: Trying to assign these in a useEffect or useLayoutEffect breaks\n // higher-order components.\n {\n Object.assign(ref.current, { client, options, mutation });\n }\n\n const execute = useCallback((\n executeOptions: MutationFunctionOptions<\n TData,\n TVariables,\n TContext,\n TCache\n > = {}\n ) => {\n const {client, options, mutation} = ref.current;\n const baseOptions = { ...options, mutation };\n if (!ref.current.result.loading && !baseOptions.ignoreResults && ref.current.isMounted) {\n setResult(ref.current.result = {\n loading: true,\n error: void 0,\n data: void 0,\n called: true,\n client,\n });\n }\n\n const mutationId = ++ref.current.mutationId;\n const clientOptions = mergeOptions(\n baseOptions,\n executeOptions as any,\n );\n\n return client.mutate(clientOptions).then((response) => {\n const { data, errors } = response;\n const error =\n errors && errors.length > 0\n ? new ApolloError({ graphQLErrors: errors })\n : void 0;\n\n if (\n mutationId === ref.current.mutationId &&\n !clientOptions.ignoreResults\n ) {\n const result = {\n called: true,\n loading: false,\n data,\n error,\n client,\n };\n\n if (ref.current.isMounted && !equal(ref.current.result, result)) {\n setResult(ref.current.result = result);\n }\n }\n ref.current.options?.onCompleted?.(response.data!, clientOptions);\n executeOptions.onCompleted?.(response.data!, clientOptions);\n return response;\n }).catch((error) => {\n if (\n mutationId === ref.current.mutationId &&\n ref.current.isMounted\n ) {\n const result = {\n loading: false,\n error,\n data: void 0,\n called: true,\n client,\n };\n\n if (!equal(ref.current.result, result)) {\n setResult(ref.current.result = result);\n }\n }\n\n if (ref.current.options?.onError || clientOptions.onError) {\n ref.current.options?.onError?.(error, clientOptions);\n executeOptions.onError?.(error, clientOptions);\n // TODO(brian): why are we returning this here???\n return { data: void 0, errors: error };\n }\n\n throw error;\n });\n }, []);\n\n const reset = useCallback(() => {\n if (ref.current.isMounted) {\n setResult({ called: false, loading: false, client });\n }\n }, []);\n\n useEffect(() => {\n ref.current.isMounted = true;\n\n return () => {\n ref.current.isMounted = false;\n };\n }, []);\n\n return [execute, { reset, ...result }];\n}\n"]}
@@ -1,3 +1,4 @@
1
- import { ExecutionResult } from 'graphql';
2
- export declare function graphQLResultHasError(result: ExecutionResult<unknown>): boolean;
1
+ import { FetchResult } from "../../link/core";
2
+ export declare function graphQLResultHasError(result: FetchResult): boolean;
3
+ export declare function getGraphQLErrorsFromResult(result: FetchResult): import("graphql").GraphQLError[];
3
4
  //# sourceMappingURL=errorHandling.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"errorHandling.d.ts","sourceRoot":"","sources":["../../../src/utilities/common/errorHandling.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE1C,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,eAAe,CAAC,OAAO,CAAC,GAAG,OAAO,CAE/E"}
1
+ {"version":3,"file":"errorHandling.d.ts","sourceRoot":"","sources":["../../../src/utilities/common/errorHandling.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAI9C,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAGlE;AAED,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,WAAW,oCAgB7D"}
@@ -1,4 +1,21 @@
1
+ import { isNonEmptyArray } from "./arrays.js";
2
+ import { isExecutionPatchIncrementalResult } from "./incrementalResult.js";
1
3
  export function graphQLResultHasError(result) {
2
- return (result.errors && result.errors.length > 0) || false;
4
+ var errors = getGraphQLErrorsFromResult(result);
5
+ return isNonEmptyArray(errors);
6
+ }
7
+ export function getGraphQLErrorsFromResult(result) {
8
+ var graphQLErrors = isNonEmptyArray(result.errors)
9
+ ? result.errors.slice(0)
10
+ : [];
11
+ if (isExecutionPatchIncrementalResult(result) &&
12
+ isNonEmptyArray(result.incremental)) {
13
+ result.incremental.forEach(function (incrementalResult) {
14
+ if (incrementalResult.errors) {
15
+ graphQLErrors.push.apply(graphQLErrors, incrementalResult.errors);
16
+ }
17
+ });
18
+ }
19
+ return graphQLErrors;
3
20
  }
4
21
  //# sourceMappingURL=errorHandling.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"errorHandling.js","sourceRoot":"","sources":["../../../src/utilities/common/errorHandling.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,qBAAqB,CAAC,MAAgC;IACpE,OAAO,CAAC,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,KAAK,CAAC;AAC9D,CAAC","sourcesContent":["import { ExecutionResult } from 'graphql';\n\nexport function graphQLResultHasError(result: ExecutionResult<unknown>): boolean {\n return (result.errors && result.errors.length > 0) || false;\n}\n"]}
1
+ {"version":3,"file":"errorHandling.js","sourceRoot":"","sources":["../../../src/utilities/common/errorHandling.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,EAAE,iCAAiC,EAAE,MAAM,0CAA0C,CAAC;AAE7F,MAAM,UAAU,qBAAqB,CAAC,MAAmB;IACvD,IAAM,MAAM,GAAG,0BAA0B,CAAC,MAAM,CAAC,CAAC;IAClD,OAAO,eAAe,CAAC,MAAM,CAAC,CAAC;AACjC,CAAC;AAED,MAAM,UAAU,0BAA0B,CAAC,MAAmB;IAC5D,IAAM,aAAa,GAAG,eAAe,CAAC,MAAM,CAAC,MAAM,CAAC;QAClD,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QACxB,CAAC,CAAC,EAAE,CAAC;IAEP,IACE,iCAAiC,CAAC,MAAM,CAAC;QACzC,eAAe,CAAC,MAAM,CAAC,WAAW,CAAC,EACnC;QACA,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,UAAC,iBAAiB;YAC3C,IAAI,iBAAiB,CAAC,MAAM,EAAE;gBAC5B,aAAa,CAAC,IAAI,OAAlB,aAAa,EAAS,iBAAiB,CAAC,MAAM,EAAE;aACjD;QACH,CAAC,CAAC,CAAC;KACJ;IACD,OAAO,aAAa,CAAC;AACvB,CAAC","sourcesContent":["import { FetchResult } from \"../../link/core\";\nimport { isNonEmptyArray } from \"../../utilities/common/arrays\";\nimport { isExecutionPatchIncrementalResult } from \"../../utilities/common/incrementalResult\";\n\nexport function graphQLResultHasError(result: FetchResult): boolean {\n const errors = getGraphQLErrorsFromResult(result);\n return isNonEmptyArray(errors);\n}\n\nexport function getGraphQLErrorsFromResult(result: FetchResult) {\n const graphQLErrors = isNonEmptyArray(result.errors)\n ? result.errors.slice(0)\n : [];\n\n if (\n isExecutionPatchIncrementalResult(result) &&\n isNonEmptyArray(result.incremental)\n ) {\n result.incremental.forEach((incrementalResult) => {\n if (incrementalResult.errors) {\n graphQLErrors.push(...incrementalResult.errors);\n }\n });\n }\n return graphQLErrors;\n}\n"]}
@@ -1,3 +1,6 @@
1
- import { ExecutionPatchIncrementalResult } from '../../link/core';
2
- export declare function isExecutionPatchIncrementalResult(value: any): value is ExecutionPatchIncrementalResult;
1
+ import { ExecutionPatchIncrementalResult, ExecutionPatchInitialResult, ExecutionPatchResult, FetchResult } from "../../link/core";
2
+ export declare function isExecutionPatchIncrementalResult(value: FetchResult): value is ExecutionPatchIncrementalResult;
3
+ export declare function isExecutionPatchInitialResult(value: FetchResult): value is ExecutionPatchInitialResult;
4
+ export declare function isExecutionPatchResult(value: FetchResult): value is ExecutionPatchResult;
5
+ export declare function mergeIncrementalData<TData>(prevResult: TData, result: ExecutionPatchResult<TData>): TData;
3
6
  //# sourceMappingURL=incrementalResult.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"incrementalResult.d.ts","sourceRoot":"","sources":["../../../src/utilities/common/incrementalResult.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,+BAA+B,EAAE,MAAM,iBAAiB,CAAC;AAElE,wBAAgB,iCAAiC,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,+BAA+B,CAEtG"}
1
+ {"version":3,"file":"incrementalResult.d.ts","sourceRoot":"","sources":["../../../src/utilities/common/incrementalResult.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,+BAA+B,EAC/B,2BAA2B,EAC3B,oBAAoB,EACpB,WAAW,EACZ,MAAM,iBAAiB,CAAC;AAIzB,wBAAgB,iCAAiC,CAC/C,KAAK,EAAE,WAAW,GACjB,KAAK,IAAI,+BAA+B,CAE1C;AAED,wBAAgB,6BAA6B,CAC3C,KAAK,EAAE,WAAW,GACjB,KAAK,IAAI,2BAA2B,CAEtC;AAED,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,WAAW,GACjB,KAAK,IAAI,oBAAoB,CAK/B;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EACxC,UAAU,EAAE,KAAK,EACjB,MAAM,EAAE,oBAAoB,CAAC,KAAK,CAAC,SAoBpC"}
@@ -1,4 +1,32 @@
1
+ import { isNonEmptyArray } from "./arrays.js";
2
+ import { DeepMerger } from "./mergeDeep.js";
1
3
  export function isExecutionPatchIncrementalResult(value) {
2
- return !!value.incremental;
4
+ return "incremental" in value;
5
+ }
6
+ export function isExecutionPatchInitialResult(value) {
7
+ return "hasNext" in value && "data" in value;
8
+ }
9
+ export function isExecutionPatchResult(value) {
10
+ return (isExecutionPatchIncrementalResult(value) ||
11
+ isExecutionPatchInitialResult(value));
12
+ }
13
+ export function mergeIncrementalData(prevResult, result) {
14
+ var mergedData = prevResult;
15
+ var merger = new DeepMerger();
16
+ if (isExecutionPatchIncrementalResult(result) &&
17
+ isNonEmptyArray(result.incremental)) {
18
+ result.incremental.forEach(function (_a) {
19
+ var data = _a.data, path = _a.path;
20
+ for (var i = path.length - 1; i >= 0; --i) {
21
+ var key = path[i];
22
+ var isNumericKey = !isNaN(+key);
23
+ var parent_1 = isNumericKey ? [] : {};
24
+ parent_1[key] = data;
25
+ data = parent_1;
26
+ }
27
+ mergedData = merger.merge(mergedData, data);
28
+ });
29
+ }
30
+ return mergedData;
3
31
  }
4
32
  //# sourceMappingURL=incrementalResult.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"incrementalResult.js","sourceRoot":"","sources":["../../../src/utilities/common/incrementalResult.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,iCAAiC,CAAC,KAAU;IAC1D,OAAO,CAAC,CAAE,KAAyC,CAAC,WAAW,CAAC;AAClE,CAAC","sourcesContent":["import { ExecutionPatchIncrementalResult } from '../../link/core';\n\nexport function isExecutionPatchIncrementalResult(value: any): value is ExecutionPatchIncrementalResult {\n return !!(value as ExecutionPatchIncrementalResult).incremental;\n}\n"]}
1
+ {"version":3,"file":"incrementalResult.js","sourceRoot":"","sources":["../../../src/utilities/common/incrementalResult.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,MAAM,UAAU,iCAAiC,CAC/C,KAAkB;IAElB,OAAO,aAAa,IAAI,KAAK,CAAC;AAChC,CAAC;AAED,MAAM,UAAU,6BAA6B,CAC3C,KAAkB;IAElB,OAAO,SAAS,IAAI,KAAK,IAAI,MAAM,IAAI,KAAK,CAAC;AAC/C,CAAC;AAED,MAAM,UAAU,sBAAsB,CACpC,KAAkB;IAElB,OAAO,CACL,iCAAiC,CAAC,KAAK,CAAC;QACxC,6BAA6B,CAAC,KAAK,CAAC,CACrC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,oBAAoB,CAClC,UAAiB,EACjB,MAAmC;IAEnC,IAAI,UAAU,GAAG,UAAU,CAAC;IAC5B,IAAM,MAAM,GAAG,IAAI,UAAU,EAAE,CAAC;IAChC,IACE,iCAAiC,CAAC,MAAM,CAAC;QACzC,eAAe,CAAC,MAAM,CAAC,WAAW,CAAC,EACnC;QACA,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,UAAC,EAAc;gBAAZ,IAAI,UAAA,EAAE,IAAI,UAAA;YACtC,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,EAAE;gBACzC,IAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;gBACpB,IAAM,YAAY,GAAG,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC;gBAClC,IAAM,QAAM,GAAiC,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBACpE,QAAM,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;gBACnB,IAAI,GAAG,QAAqB,CAAC;aAC9B;YACD,UAAU,GAAG,MAAM,CAAC,KAAK,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;QAC9C,CAAC,CAAC,CAAC;KACJ;IACD,OAAO,UAAmB,CAAC;AAC7B,CAAC","sourcesContent":["import {\n ExecutionPatchIncrementalResult,\n ExecutionPatchInitialResult,\n ExecutionPatchResult,\n FetchResult,\n} from \"../../link/core\";\nimport { isNonEmptyArray } from \"./arrays\";\nimport { DeepMerger } from \"./mergeDeep\";\n\nexport function isExecutionPatchIncrementalResult(\n value: FetchResult\n): value is ExecutionPatchIncrementalResult {\n return \"incremental\" in value;\n}\n\nexport function isExecutionPatchInitialResult(\n value: FetchResult\n): value is ExecutionPatchInitialResult {\n return \"hasNext\" in value && \"data\" in value;\n}\n\nexport function isExecutionPatchResult(\n value: FetchResult\n): value is ExecutionPatchResult {\n return (\n isExecutionPatchIncrementalResult(value) ||\n isExecutionPatchInitialResult(value)\n );\n}\n\nexport function mergeIncrementalData<TData>(\n prevResult: TData,\n result: ExecutionPatchResult<TData>\n) {\n let mergedData = prevResult;\n const merger = new DeepMerger();\n if (\n isExecutionPatchIncrementalResult(result) &&\n isNonEmptyArray(result.incremental)\n ) {\n result.incremental.forEach(({ data, path }) => {\n for (let i = path.length - 1; i >= 0; --i) {\n const key = path[i];\n const isNumericKey = !isNaN(+key);\n const parent: Record<string | number, any> = isNumericKey ? [] : {};\n parent[key] = data;\n data = parent as typeof data;\n }\n mergedData = merger.merge(mergedData, data);\n });\n }\n return mergedData as TData;\n}\n"]}