@apollo/client 3.7.0-rc.0 → 3.7.1

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 (48) hide show
  1. package/README.md +1 -0
  2. package/apollo-client.cjs +51 -13
  3. package/apollo-client.cjs.map +1 -1
  4. package/apollo-client.min.cjs +1 -1
  5. package/core/ObservableQuery.d.ts +1 -1
  6. package/core/ObservableQuery.d.ts.map +1 -1
  7. package/core/ObservableQuery.js +5 -3
  8. package/core/ObservableQuery.js.map +1 -1
  9. package/core/core.cjs +6 -4
  10. package/core/core.cjs.map +1 -1
  11. package/core/core.cjs.native.js +6 -4
  12. package/invariantErrorCodes.js +1 -1
  13. package/link/batch-http/batchHttpLink.js.map +1 -1
  14. package/link/http/http.cjs +11 -0
  15. package/link/http/http.cjs.map +1 -1
  16. package/link/http/http.cjs.native.js +11 -0
  17. package/link/http/parseAndCheckHttpResponse.d.ts.map +1 -1
  18. package/link/http/parseAndCheckHttpResponse.js +11 -0
  19. package/link/http/parseAndCheckHttpResponse.js.map +1 -1
  20. package/link/persisted-queries/index.js.map +1 -1
  21. package/package.json +18 -16
  22. package/react/components/Subscription.js +2 -0
  23. package/react/components/Subscription.js.map +1 -1
  24. package/react/components/components.cjs +2 -0
  25. package/react/components/components.cjs.map +1 -1
  26. package/react/components/components.cjs.native.js +2 -0
  27. package/react/hooks/hooks.cjs +34 -9
  28. package/react/hooks/hooks.cjs.map +1 -1
  29. package/react/hooks/hooks.cjs.native.js +34 -9
  30. package/react/hooks/useFragment.d.ts.map +1 -1
  31. package/react/hooks/useFragment.js +2 -4
  32. package/react/hooks/useFragment.js.map +1 -1
  33. package/react/hooks/useSubscription.d.ts.map +1 -1
  34. package/react/hooks/useSubscription.js +33 -5
  35. package/react/hooks/useSubscription.js.map +1 -1
  36. package/react/ssr/getDataFromTree.d.ts.map +1 -1
  37. package/react/ssr/getDataFromTree.js +3 -2
  38. package/react/ssr/getDataFromTree.js.map +1 -1
  39. package/react/ssr/renderToStringWithData.d.ts.map +1 -1
  40. package/react/ssr/renderToStringWithData.js +2 -1
  41. package/react/ssr/renderToStringWithData.js.map +1 -1
  42. package/react/ssr/ssr.cjs +4 -3
  43. package/react/ssr/ssr.cjs.map +1 -1
  44. package/react/ssr/ssr.cjs.native.js +4 -3
  45. package/react/types/types.d.ts +6 -0
  46. package/react/types/types.d.ts.map +1 -1
  47. package/react/types/types.js.map +1 -1
  48. package/version.js +1 -1
package/README.md CHANGED
@@ -27,6 +27,7 @@ Learn how to use Apollo Client with self-paced hands-on training on Odyssey, Apo
27
27
  - [@hwillson](https://github.com/hwillson)
28
28
  - [@jpvajda](https://github.com/jpvajda)
29
29
  - [@mrdoombringer](https://github.com/mrdoombringer)
30
+ - [@jerelmiller](https://github.com/jerelmiller)
30
31
 
31
32
  ## Who is Apollo?
32
33
 
package/apollo-client.cjs CHANGED
@@ -1300,7 +1300,7 @@ var concat = ApolloLink.concat;
1300
1300
 
1301
1301
  var execute = ApolloLink.execute;
1302
1302
 
1303
- var version = '3.7.0-rc.0';
1303
+ var version = '3.7.1';
1304
1304
 
1305
1305
  function isNodeResponse(value) {
1306
1306
  return !!value.body;
@@ -1548,6 +1548,17 @@ function parseHeaders(headerText) {
1548
1548
  return headersInit;
1549
1549
  }
1550
1550
  function parseJsonBody(response, bodyText) {
1551
+ if (response.status >= 300) {
1552
+ var getResult = function () {
1553
+ try {
1554
+ return JSON.parse(bodyText);
1555
+ }
1556
+ catch (err) {
1557
+ return bodyText;
1558
+ }
1559
+ };
1560
+ throwServerError(response, getResult(), "Response not successful: Received status code ".concat(response.status));
1561
+ }
1551
1562
  try {
1552
1563
  return JSON.parse(bodyText);
1553
1564
  }
@@ -4339,8 +4350,10 @@ var ObservableQuery = (function (_super) {
4339
4350
  }
4340
4351
  return result;
4341
4352
  };
4342
- ObservableQuery.prototype.isDifferentFromLastResult = function (newResult) {
4343
- return !this.last || !equality.equal(this.last.result, newResult);
4353
+ ObservableQuery.prototype.isDifferentFromLastResult = function (newResult, variables) {
4354
+ return (!this.last ||
4355
+ !equality.equal(this.last.result, newResult) ||
4356
+ (variables && !equality.equal(this.last.variables, variables)));
4344
4357
  };
4345
4358
  ObservableQuery.prototype.getLast = function (key, variablesMustMatch) {
4346
4359
  var last = this.last;
@@ -4648,7 +4661,7 @@ var ObservableQuery = (function (_super) {
4648
4661
  };
4649
4662
  ObservableQuery.prototype.reportResult = function (result, variables) {
4650
4663
  var lastError = this.getLastError();
4651
- if (lastError || this.isDifferentFromLastResult(result)) {
4664
+ if (lastError || this.isDifferentFromLastResult(result, variables)) {
4652
4665
  if (lastError || !result.partial || this.options.returnPartialData) {
4653
4666
  this.updateLastResult(result, variables);
4654
4667
  }
@@ -6936,6 +6949,7 @@ function useMutation(mutation, options) {
6936
6949
  }
6937
6950
 
6938
6951
  function useSubscription(subscription, options) {
6952
+ var hasIssuedDeprecationWarningRef = React.useRef(false);
6939
6953
  var client = useApolloClient(options === null || options === void 0 ? void 0 : options.client);
6940
6954
  verifyDocumentType(subscription, exports.DocumentType.Subscription);
6941
6955
  var _a = React.useState({
@@ -6944,6 +6958,19 @@ function useSubscription(subscription, options) {
6944
6958
  data: void 0,
6945
6959
  variables: options === null || options === void 0 ? void 0 : options.variables,
6946
6960
  }), result = _a[0], setResult = _a[1];
6961
+ if (!hasIssuedDeprecationWarningRef.current) {
6962
+ hasIssuedDeprecationWarningRef.current = true;
6963
+ if (options === null || options === void 0 ? void 0 : options.onSubscriptionData) {
6964
+ __DEV__ && tsInvariant.invariant.warn(options.onData
6965
+ ? "'useSubscription' supports only the 'onSubscriptionData' or 'onData' option, but not both. Only the 'onData' option will be used."
6966
+ : "'onSubscriptionData' is deprecated and will be removed in a future major version. Please use the 'onData' option instead.");
6967
+ }
6968
+ if (options === null || options === void 0 ? void 0 : options.onSubscriptionComplete) {
6969
+ __DEV__ && tsInvariant.invariant.warn(options.onComplete
6970
+ ? "'useSubscription' supports only the 'onSubscriptionComplete' or 'onComplete' option, but not both. Only the 'onComplete' option will be used."
6971
+ : "'onSubscriptionComplete' is deprecated and will be removed in a future major version. Please use the 'onComplete' option instead.");
6972
+ }
6973
+ }
6947
6974
  var _b = React.useState(function () {
6948
6975
  if (options === null || options === void 0 ? void 0 : options.skip) {
6949
6976
  return null;
@@ -7017,10 +7044,18 @@ function useSubscription(subscription, options) {
7017
7044
  variables: options === null || options === void 0 ? void 0 : options.variables,
7018
7045
  };
7019
7046
  setResult(result);
7020
- (_b = (_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onSubscriptionData) === null || _b === void 0 ? void 0 : _b.call(_a, {
7021
- client: client,
7022
- subscriptionData: result
7023
- });
7047
+ if ((_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onData) {
7048
+ ref.current.options.onData({
7049
+ client: client,
7050
+ data: result
7051
+ });
7052
+ }
7053
+ else if ((_b = ref.current.options) === null || _b === void 0 ? void 0 : _b.onSubscriptionData) {
7054
+ ref.current.options.onSubscriptionData({
7055
+ client: client,
7056
+ subscriptionData: result
7057
+ });
7058
+ }
7024
7059
  },
7025
7060
  error: function (error) {
7026
7061
  var _a, _b;
@@ -7034,7 +7069,12 @@ function useSubscription(subscription, options) {
7034
7069
  },
7035
7070
  complete: function () {
7036
7071
  var _a, _b;
7037
- (_b = (_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onSubscriptionComplete) === null || _b === void 0 ? void 0 : _b.call(_a);
7072
+ if ((_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onComplete) {
7073
+ ref.current.options.onComplete();
7074
+ }
7075
+ else if ((_b = ref.current.options) === null || _b === void 0 ? void 0 : _b.onSubscriptionComplete) {
7076
+ ref.current.options.onSubscriptionComplete();
7077
+ }
7038
7078
  },
7039
7079
  });
7040
7080
  return function () {
@@ -7066,13 +7106,11 @@ function useFragment_experimental(options) {
7066
7106
  var resultRef = React.useRef();
7067
7107
  var latestDiff = cache.diff(diffOptions);
7068
7108
  return useSyncExternalStore(function (forceUpdate) {
7069
- var immediate = true;
7070
- return cache.watch(tslib.__assign(tslib.__assign({}, diffOptions), { immediate: immediate, callback: function (diff) {
7071
- if (!immediate && !equality.equal(diff, latestDiff)) {
7109
+ return cache.watch(tslib.__assign(tslib.__assign({}, diffOptions), { immediate: true, callback: function (diff) {
7110
+ if (!equality.equal(diff, latestDiff)) {
7072
7111
  resultRef.current = diffToResult(latestDiff = diff);
7073
7112
  forceUpdate();
7074
7113
  }
7075
- immediate = false;
7076
7114
  } }));
7077
7115
  }, function () {
7078
7116
  var latestDiffToResult = diffToResult(latestDiff);