@apollo/client 3.11.2 → 3.11.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 (82) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/apollo-client.cjs +105 -86
  3. package/apollo-client.cjs.map +1 -1
  4. package/apollo-client.min.cjs +1 -1
  5. package/core/ObservableQuery.js +72 -43
  6. package/core/ObservableQuery.js.map +1 -1
  7. package/core/QueryManager.js +19 -11
  8. package/core/QueryManager.js.map +1 -1
  9. package/core/core.cjs +62 -43
  10. package/core/core.cjs.map +1 -1
  11. package/core/core.cjs.native.js +62 -43
  12. package/dev/dev.cjs +72 -67
  13. package/dev/dev.cjs.map +1 -1
  14. package/dev/dev.cjs.native.js +72 -67
  15. package/invariantErrorCodes.js +72 -66
  16. package/link/core/ApolloLink.js +2 -2
  17. package/link/core/core.cjs +2 -2
  18. package/link/core/core.cjs.map +1 -1
  19. package/link/core/core.cjs.native.js +2 -2
  20. package/link/http/checkFetcher.js +1 -1
  21. package/link/http/createHttpLink.js +1 -1
  22. package/link/http/http.cjs +3 -3
  23. package/link/http/http.cjs.map +1 -1
  24. package/link/http/http.cjs.native.js +3 -3
  25. package/link/http/serializeFetchParameter.js +1 -1
  26. package/link/persisted-queries/index.js +2 -2
  27. package/link/persisted-queries/persisted-queries.cjs +2 -2
  28. package/link/persisted-queries/persisted-queries.cjs.map +1 -1
  29. package/link/persisted-queries/persisted-queries.cjs.native.js +2 -2
  30. package/link/utils/toPromise.js +1 -1
  31. package/link/utils/utils.cjs +2 -2
  32. package/link/utils/utils.cjs.map +1 -1
  33. package/link/utils/utils.cjs.native.js +2 -2
  34. package/link/utils/validateOperation.js +1 -1
  35. package/package.json +1 -1
  36. package/react/context/ApolloConsumer.js +1 -1
  37. package/react/context/ApolloContext.js +1 -1
  38. package/react/context/ApolloProvider.js +1 -1
  39. package/react/context/context.cjs +3 -3
  40. package/react/context/context.cjs.map +1 -1
  41. package/react/context/context.cjs.native.js +3 -3
  42. package/react/hoc/hoc-utils.js +1 -1
  43. package/react/hoc/hoc.cjs +2 -2
  44. package/react/hoc/hoc.cjs.map +1 -1
  45. package/react/hoc/hoc.cjs.native.js +2 -2
  46. package/react/hoc/withApollo.js +1 -1
  47. package/react/hooks/hooks.cjs +9 -9
  48. package/react/hooks/hooks.cjs.map +1 -1
  49. package/react/hooks/hooks.cjs.native.js +9 -9
  50. package/react/hooks/useApolloClient.js +1 -1
  51. package/react/hooks/useLoadableQuery.js +2 -2
  52. package/react/hooks/useSubscription.js +3 -3
  53. package/react/hooks/useSuspenseQuery.js +2 -2
  54. package/react/hooks/useSyncExternalStore.js +1 -1
  55. package/react/internal/cache/QueryReference.js +1 -1
  56. package/react/internal/internal.cjs +2 -2
  57. package/react/internal/internal.cjs.map +1 -1
  58. package/react/internal/internal.cjs.native.js +2 -2
  59. package/react/parser/index.js +5 -5
  60. package/react/parser/parser.cjs +5 -5
  61. package/react/parser/parser.cjs.map +1 -1
  62. package/react/parser/parser.cjs.native.js +5 -5
  63. package/testing/core/core.cjs +2 -2
  64. package/testing/core/core.cjs.map +1 -1
  65. package/testing/core/core.cjs.native.js +2 -2
  66. package/testing/core/mocking/mockLink.js +2 -2
  67. package/testing/internal/scenarios/index.d.ts +5 -0
  68. package/testing/internal/scenarios/index.js +1 -1
  69. package/testing/internal/scenarios/index.js.map +1 -1
  70. package/utilities/globals/globals.cjs +1 -1
  71. package/utilities/globals/globals.cjs.map +1 -1
  72. package/utilities/globals/globals.cjs.native.js +1 -1
  73. package/utilities/graphql/DocumentTransform.js +1 -1
  74. package/utilities/graphql/directives.js +4 -4
  75. package/utilities/graphql/fragments.js +3 -3
  76. package/utilities/graphql/getFromAST.js +8 -8
  77. package/utilities/graphql/storeUtils.js +1 -1
  78. package/utilities/graphql/transform.js +2 -2
  79. package/utilities/utilities.cjs +19 -19
  80. package/utilities/utilities.cjs.map +1 -1
  81. package/utilities/utilities.cjs.native.js +19 -19
  82. package/version.js +1 -1
package/core/core.cjs CHANGED
@@ -20,7 +20,7 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
20
20
 
21
21
  var equal__default = /*#__PURE__*/_interopDefaultLegacy(equal);
22
22
 
23
- var version = "3.11.2";
23
+ var version = "3.11.3";
24
24
 
25
25
  function isNonNullObject(obj) {
26
26
  return obj !== null && typeof obj === "object";
@@ -406,6 +406,11 @@ var ObservableQuery = (function (_super) {
406
406
  this.observe();
407
407
  }
408
408
  var updatedQuerySet = new Set();
409
+ var updateQuery = fetchMoreOptions === null || fetchMoreOptions === void 0 ? void 0 : fetchMoreOptions.updateQuery;
410
+ var isCached = this.options.fetchPolicy !== "no-cache";
411
+ if (!isCached) {
412
+ globals.invariant(updateQuery, 21);
413
+ }
409
414
  return this.queryManager
410
415
  .fetchQuery(qid, combinedOptions, exports.NetworkStatus.fetchMore)
411
416
  .then(function (fetchMoreResult) {
@@ -413,38 +418,48 @@ var ObservableQuery = (function (_super) {
413
418
  if (queryInfo.networkStatus === exports.NetworkStatus.fetchMore) {
414
419
  queryInfo.networkStatus = originalNetworkStatus;
415
420
  }
416
- _this.queryManager.cache.batch({
417
- update: function (cache) {
418
- var updateQuery = fetchMoreOptions.updateQuery;
419
- if (updateQuery) {
420
- cache.updateQuery({
421
- query: _this.query,
422
- variables: _this.variables,
423
- returnPartialData: true,
424
- optimistic: false,
425
- }, function (previous) {
426
- return updateQuery(previous, {
427
- fetchMoreResult: fetchMoreResult.data,
421
+ if (isCached) {
422
+ _this.queryManager.cache.batch({
423
+ update: function (cache) {
424
+ var updateQuery = fetchMoreOptions.updateQuery;
425
+ if (updateQuery) {
426
+ cache.updateQuery({
427
+ query: _this.query,
428
+ variables: _this.variables,
429
+ returnPartialData: true,
430
+ optimistic: false,
431
+ }, function (previous) {
432
+ return updateQuery(previous, {
433
+ fetchMoreResult: fetchMoreResult.data,
434
+ variables: combinedOptions.variables,
435
+ });
436
+ });
437
+ }
438
+ else {
439
+ cache.writeQuery({
440
+ query: combinedOptions.query,
428
441
  variables: combinedOptions.variables,
442
+ data: fetchMoreResult.data,
429
443
  });
430
- });
431
- }
432
- else {
433
- cache.writeQuery({
434
- query: combinedOptions.query,
435
- variables: combinedOptions.variables,
436
- data: fetchMoreResult.data,
437
- });
438
- }
439
- },
440
- onWatchUpdated: function (watch) {
441
- updatedQuerySet.add(watch.query);
442
- },
443
- });
444
+ }
445
+ },
446
+ onWatchUpdated: function (watch) {
447
+ updatedQuerySet.add(watch.query);
448
+ },
449
+ });
450
+ }
451
+ else {
452
+ var lastResult = _this.getLast("result");
453
+ var data = updateQuery(lastResult.data, {
454
+ fetchMoreResult: fetchMoreResult.data,
455
+ variables: combinedOptions.variables,
456
+ });
457
+ _this.reportResult(tslib.__assign(tslib.__assign({}, lastResult), { data: data }), _this.variables);
458
+ }
444
459
  return fetchMoreResult;
445
460
  })
446
461
  .finally(function () {
447
- if (!updatedQuerySet.has(_this.query)) {
462
+ if (isCached && !updatedQuerySet.has(_this.query)) {
448
463
  reobserveCacheFirst(_this);
449
464
  }
450
465
  });
@@ -475,7 +490,7 @@ var ObservableQuery = (function (_super) {
475
490
  options.onError(err);
476
491
  return;
477
492
  }
478
- globalThis.__DEV__ !== false && globals.invariant.error(21, err);
493
+ globalThis.__DEV__ !== false && globals.invariant.error(22, err);
479
494
  },
480
495
  });
481
496
  this.subscriptions.add(subscription);
@@ -575,7 +590,7 @@ var ObservableQuery = (function (_super) {
575
590
  if (pollingInfo && pollingInfo.interval === pollInterval) {
576
591
  return;
577
592
  }
578
- globals.invariant(pollInterval, 22);
593
+ globals.invariant(pollInterval, 23);
579
594
  var info = pollingInfo || (this.pollingInfo = {});
580
595
  info.interval = pollInterval;
581
596
  var maybeFetch = function () {
@@ -749,11 +764,11 @@ function reobserveCacheFirst(obsQuery) {
749
764
  return obsQuery.reobserve();
750
765
  }
751
766
  function defaultSubscriptionObserverErrorCallback(error) {
752
- globalThis.__DEV__ !== false && globals.invariant.error(23, error.message, error.stack);
767
+ globalThis.__DEV__ !== false && globals.invariant.error(24, error.message, error.stack);
753
768
  }
754
769
  function logMissingFieldErrors(missing) {
755
770
  if (globalThis.__DEV__ !== false && missing) {
756
- globalThis.__DEV__ !== false && globals.invariant.debug(24, missing);
771
+ globalThis.__DEV__ !== false && globals.invariant.debug(25, missing);
757
772
  }
758
773
  }
759
774
  function skipCacheDataFor(fetchPolicy ) {
@@ -1081,7 +1096,7 @@ var QueryManager = (function () {
1081
1096
  this.queries.forEach(function (_info, queryId) {
1082
1097
  _this.stopQueryNoBroadcast(queryId);
1083
1098
  });
1084
- this.cancelPendingFetches(globals.newInvariantError(25));
1099
+ this.cancelPendingFetches(globals.newInvariantError(26));
1085
1100
  };
1086
1101
  QueryManager.prototype.cancelPendingFetches = function (error) {
1087
1102
  this.fetchCancelFns.forEach(function (cancel) { return cancel(error); });
@@ -1095,8 +1110,8 @@ var QueryManager = (function () {
1095
1110
  return tslib.__generator(this, function (_j) {
1096
1111
  switch (_j.label) {
1097
1112
  case 0:
1098
- globals.invariant(mutation, 26);
1099
- globals.invariant(fetchPolicy === "network-only" || fetchPolicy === "no-cache", 27);
1113
+ globals.invariant(mutation, 27);
1114
+ globals.invariant(fetchPolicy === "network-only" || fetchPolicy === "no-cache", 28);
1100
1115
  mutationId = this.generateMutationId();
1101
1116
  mutation = this.cache.transformForLink(this.transform(mutation));
1102
1117
  hasClientExports = this.getDocumentInfo(mutation).hasClientExports;
@@ -1418,10 +1433,10 @@ var QueryManager = (function () {
1418
1433
  QueryManager.prototype.query = function (options, queryId) {
1419
1434
  var _this = this;
1420
1435
  if (queryId === void 0) { queryId = this.generateQueryId(); }
1421
- globals.invariant(options.query, 28);
1422
- globals.invariant(options.query.kind === "Document", 29);
1423
- globals.invariant(!options.returnPartialData, 30);
1424
- globals.invariant(!options.pollInterval, 31);
1436
+ globals.invariant(options.query, 29);
1437
+ globals.invariant(options.query.kind === "Document", 30);
1438
+ globals.invariant(!options.returnPartialData, 31);
1439
+ globals.invariant(!options.pollInterval, 32);
1425
1440
  return this.fetchQuery(queryId, tslib.__assign(tslib.__assign({}, options), { query: this.transform(options.query) })).finally(function () { return _this.stopQuery(queryId); });
1426
1441
  };
1427
1442
  QueryManager.prototype.generateQueryId = function () {
@@ -1446,7 +1461,7 @@ var QueryManager = (function () {
1446
1461
  if (options === void 0) { options = {
1447
1462
  discardWatches: true,
1448
1463
  }; }
1449
- this.cancelPendingFetches(globals.newInvariantError(32));
1464
+ this.cancelPendingFetches(globals.newInvariantError(33));
1450
1465
  this.queries.forEach(function (queryInfo) {
1451
1466
  if (queryInfo.observableQuery) {
1452
1467
  queryInfo.networkStatus = exports.NetworkStatus.loading;
@@ -1522,7 +1537,7 @@ var QueryManager = (function () {
1522
1537
  if (globalThis.__DEV__ !== false && queryNamesAndDocs.size) {
1523
1538
  queryNamesAndDocs.forEach(function (included, nameOrDoc) {
1524
1539
  if (!included) {
1525
- globalThis.__DEV__ !== false && globals.invariant.warn(typeof nameOrDoc === "string" ? 33 : 34, nameOrDoc);
1540
+ globalThis.__DEV__ !== false && globals.invariant.warn(typeof nameOrDoc === "string" ? 34 : 35, nameOrDoc);
1526
1541
  }
1527
1542
  });
1528
1543
  }
@@ -1680,8 +1695,9 @@ var QueryManager = (function () {
1680
1695
  return utilities.asyncMap(this.getObservableFromLink(linkDocument, options.context, options.variables), function (result) {
1681
1696
  var graphQLErrors = utilities.getGraphQLErrorsFromResult(result);
1682
1697
  var hasErrors = graphQLErrors.length > 0;
1698
+ var errorPolicy = options.errorPolicy;
1683
1699
  if (requestId >= queryInfo.lastRequestId) {
1684
- if (hasErrors && options.errorPolicy === "none") {
1700
+ if (hasErrors && errorPolicy === "none") {
1685
1701
  throw queryInfo.markError(new errors.ApolloError({
1686
1702
  graphQLErrors: graphQLErrors,
1687
1703
  }));
@@ -1694,7 +1710,10 @@ var QueryManager = (function () {
1694
1710
  loading: false,
1695
1711
  networkStatus: exports.NetworkStatus.ready,
1696
1712
  };
1697
- if (hasErrors && options.errorPolicy !== "ignore") {
1713
+ if (hasErrors && errorPolicy === "none") {
1714
+ aqr.data = void 0;
1715
+ }
1716
+ if (hasErrors && errorPolicy !== "ignore") {
1698
1717
  aqr.errors = graphQLErrors;
1699
1718
  aqr.networkStatus = exports.NetworkStatus.error;
1700
1719
  }