@apollo/client 3.7.9 → 3.7.11

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 (79) hide show
  1. package/apollo-client.cjs +196 -153
  2. package/apollo-client.cjs.map +1 -1
  3. package/apollo-client.min.cjs +1 -1
  4. package/cache/core/types/DataProxy.d.ts +3 -2
  5. package/cache/core/types/DataProxy.d.ts.map +1 -1
  6. package/cache/core/types/DataProxy.js.map +1 -1
  7. package/core/ApolloClient.d.ts +3 -3
  8. package/core/ApolloClient.d.ts.map +1 -1
  9. package/core/ApolloClient.js +10 -4
  10. package/core/ApolloClient.js.map +1 -1
  11. package/core/ObservableQuery.d.ts +2 -1
  12. package/core/ObservableQuery.d.ts.map +1 -1
  13. package/core/ObservableQuery.js +8 -5
  14. package/core/ObservableQuery.js.map +1 -1
  15. package/core/QueryManager.d.ts +1 -0
  16. package/core/QueryManager.d.ts.map +1 -1
  17. package/core/QueryManager.js +52 -43
  18. package/core/QueryManager.js.map +1 -1
  19. package/core/core.cjs +73 -56
  20. package/core/core.cjs.map +1 -1
  21. package/core/core.cjs.native.js +73 -56
  22. package/errors/errors.cjs +17 -17
  23. package/errors/errors.cjs.map +1 -1
  24. package/errors/errors.cjs.native.js +17 -17
  25. package/errors/index.d.ts +24 -8
  26. package/errors/index.d.ts.map +1 -1
  27. package/errors/index.js +17 -19
  28. package/errors/index.js.map +1 -1
  29. package/invariantErrorCodes.js +1 -1
  30. package/link/core/types.d.ts +4 -0
  31. package/link/core/types.d.ts.map +1 -1
  32. package/link/core/types.js.map +1 -1
  33. package/link/http/createHttpLink.d.ts.map +1 -1
  34. package/link/http/createHttpLink.js +19 -3
  35. package/link/http/createHttpLink.js.map +1 -1
  36. package/link/http/http.cjs +52 -15
  37. package/link/http/http.cjs.map +1 -1
  38. package/link/http/http.cjs.native.js +52 -15
  39. package/link/http/parseAndCheckHttpResponse.d.ts.map +1 -1
  40. package/link/http/parseAndCheckHttpResponse.js +29 -14
  41. package/link/http/parseAndCheckHttpResponse.js.map +1 -1
  42. package/link/subscriptions/index.d.ts.map +1 -1
  43. package/link/subscriptions/index.js +8 -3
  44. package/link/subscriptions/index.js.map +1 -1
  45. package/link/subscriptions/subscriptions.cjs +8 -3
  46. package/link/subscriptions/subscriptions.cjs.map +1 -1
  47. package/link/subscriptions/subscriptions.cjs.native.js +8 -3
  48. package/package.json +21 -22
  49. package/react/hooks/hooks.cjs +38 -45
  50. package/react/hooks/hooks.cjs.map +1 -1
  51. package/react/hooks/hooks.cjs.native.js +38 -45
  52. package/react/hooks/useLazyQuery.d.ts.map +1 -1
  53. package/react/hooks/useLazyQuery.js +11 -20
  54. package/react/hooks/useLazyQuery.js.map +1 -1
  55. package/react/hooks/useMutation.d.ts.map +1 -1
  56. package/react/hooks/useMutation.js +2 -1
  57. package/react/hooks/useMutation.js.map +1 -1
  58. package/react/hooks/useQuery.d.ts +1 -3
  59. package/react/hooks/useQuery.d.ts.map +1 -1
  60. package/react/hooks/useQuery.js +27 -26
  61. package/react/hooks/useQuery.js.map +1 -1
  62. package/testing/core/itAsync.js.map +1 -1
  63. package/testing/core/mocking/mockSubscriptionLink.d.ts +1 -1
  64. package/testing/react/MockedProvider.js +5 -4
  65. package/testing/react/MockedProvider.js.map +1 -1
  66. package/testing/testing.cjs +4 -2
  67. package/testing/testing.cjs.map +1 -1
  68. package/testing/testing.cjs.native.js +4 -2
  69. package/utilities/common/incrementalResult.d.ts +2 -1
  70. package/utilities/common/incrementalResult.d.ts.map +1 -1
  71. package/utilities/common/incrementalResult.js +4 -0
  72. package/utilities/common/incrementalResult.js.map +1 -1
  73. package/utilities/graphql/getFromAST.d.ts.map +1 -1
  74. package/utilities/graphql/getFromAST.js +7 -3
  75. package/utilities/graphql/getFromAST.js.map +1 -1
  76. package/utilities/utilities.cjs +7 -3
  77. package/utilities/utilities.cjs.map +1 -1
  78. package/utilities/utilities.cjs.native.js +7 -3
  79. package/version.js +1 -1
package/core/core.cjs CHANGED
@@ -15,16 +15,16 @@ 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.9';
19
-
20
- function isNonEmptyArray(value) {
21
- return Array.isArray(value) && value.length > 0;
22
- }
18
+ var version = '3.7.11';
23
19
 
24
20
  function isNonNullObject(obj) {
25
21
  return obj !== null && typeof obj === 'object';
26
22
  }
27
23
 
24
+ function isNonEmptyArray(value) {
25
+ return Array.isArray(value) && value.length > 0;
26
+ }
27
+
28
28
  var hasOwnProperty$2 = Object.prototype.hasOwnProperty;
29
29
  var defaultReconciler = function (target, source, property) {
30
30
  return this.merge(target[property], source[property]);
@@ -456,7 +456,7 @@ var ObservableQuery = (function (_super) {
456
456
  };
457
457
  ObservableQuery.prototype.fetch = function (options, newNetworkStatus) {
458
458
  this.queryManager.setObservableQuery(this);
459
- return this.queryManager.fetchQueryObservable(this.queryId, options, newNetworkStatus);
459
+ return this.queryManager['fetchConcastWithInfo'](this.queryId, options, newNetworkStatus);
460
460
  };
461
461
  ObservableQuery.prototype.updatePolling = function () {
462
462
  var _this = this;
@@ -509,7 +509,7 @@ var ObservableQuery = (function (_super) {
509
509
  }
510
510
  return this.last;
511
511
  };
512
- ObservableQuery.prototype.reobserve = function (newOptions, newNetworkStatus) {
512
+ ObservableQuery.prototype.reobserveAsConcast = function (newOptions, newNetworkStatus) {
513
513
  var _this = this;
514
514
  this.isTornDown = false;
515
515
  var useDisposableConcast = newNetworkStatus === exports.NetworkStatus.refetch ||
@@ -535,7 +535,7 @@ var ObservableQuery = (function (_super) {
535
535
  }
536
536
  }
537
537
  var variables = options.variables && tslib.__assign({}, options.variables);
538
- var concast = this.fetch(options, newNetworkStatus);
538
+ var _a = this.fetch(options, newNetworkStatus), concast = _a.concast, fromLink = _a.fromLink;
539
539
  var observer = {
540
540
  next: function (result) {
541
541
  _this.reportResult(result, variables);
@@ -544,7 +544,7 @@ var ObservableQuery = (function (_super) {
544
544
  _this.reportError(error, variables);
545
545
  },
546
546
  };
547
- if (!useDisposableConcast) {
547
+ if (!useDisposableConcast && fromLink) {
548
548
  if (this.concast && this.observer) {
549
549
  this.concast.removeObserver(this.observer);
550
550
  }
@@ -552,7 +552,10 @@ var ObservableQuery = (function (_super) {
552
552
  this.observer = observer;
553
553
  }
554
554
  concast.addObserver(observer);
555
- return concast.promise;
555
+ return concast;
556
+ };
557
+ ObservableQuery.prototype.reobserve = function (newOptions, newNetworkStatus) {
558
+ return this.reobserveAsConcast(newOptions, newNetworkStatus).promise;
556
559
  };
557
560
  ObservableQuery.prototype.observe = function () {
558
561
  this.reportResult(this.getCurrentResult(false), this.variables);
@@ -1723,10 +1726,17 @@ var QueryManager = (function () {
1723
1726
  }
1724
1727
  _this.broadcastQueries();
1725
1728
  }
1726
- if (utilities.graphQLResultHasError(result)) {
1727
- throw new errors.ApolloError({
1728
- graphQLErrors: result.errors,
1729
- });
1729
+ var hasErrors = utilities.graphQLResultHasError(result);
1730
+ var hasProtocolErrors = errors.graphQLResultHasProtocolErrors(result);
1731
+ if (hasErrors || hasProtocolErrors) {
1732
+ var errors$1 = {};
1733
+ if (hasErrors) {
1734
+ errors$1.graphQLErrors = result.errors;
1735
+ }
1736
+ if (hasProtocolErrors) {
1737
+ errors$1.protocolErrors = result.extensions[errors.PROTOCOL_ERRORS_SYMBOL];
1738
+ }
1739
+ throw new errors.ApolloError(errors$1);
1730
1740
  }
1731
1741
  return result;
1732
1742
  });
@@ -1858,6 +1868,9 @@ var QueryManager = (function () {
1858
1868
  });
1859
1869
  };
1860
1870
  QueryManager.prototype.fetchQueryObservable = function (queryId, options, networkStatus) {
1871
+ return this.fetchConcastWithInfo(queryId, options, networkStatus).concast;
1872
+ };
1873
+ QueryManager.prototype.fetchConcastWithInfo = function (queryId, options, networkStatus) {
1861
1874
  var _this = this;
1862
1875
  if (networkStatus === void 0) { networkStatus = exports.NetworkStatus.loading; }
1863
1876
  var query = this.transform(options.query).document;
@@ -1876,24 +1889,36 @@ var QueryManager = (function () {
1876
1889
  });
1877
1890
  var fromVariables = function (variables) {
1878
1891
  normalized.variables = variables;
1879
- var concastSources = _this.fetchQueryByPolicy(queryInfo, normalized, networkStatus);
1892
+ var sourcesWithInfo = _this.fetchQueryByPolicy(queryInfo, normalized, networkStatus);
1880
1893
  if (normalized.fetchPolicy !== "standby" &&
1881
- concastSources.length > 0 &&
1894
+ sourcesWithInfo.sources.length > 0 &&
1882
1895
  queryInfo.observableQuery) {
1883
1896
  queryInfo.observableQuery["applyNextFetchPolicy"]("after-fetch", options);
1884
1897
  }
1885
- return concastSources;
1898
+ return sourcesWithInfo;
1886
1899
  };
1887
1900
  var cleanupCancelFn = function () { return _this.fetchCancelFns.delete(queryId); };
1888
1901
  this.fetchCancelFns.set(queryId, function (reason) {
1889
1902
  cleanupCancelFn();
1890
1903
  setTimeout(function () { return concast.cancel(reason); });
1891
1904
  });
1892
- var concast = new utilities.Concast(this.transform(normalized.query).hasClientExports
1893
- ? this.localState.addExportedVariables(normalized.query, normalized.variables, normalized.context).then(fromVariables)
1894
- : fromVariables(normalized.variables));
1905
+ var concast, containsDataFromLink;
1906
+ if (this.transform(normalized.query).hasClientExports) {
1907
+ concast = new utilities.Concast(this.localState
1908
+ .addExportedVariables(normalized.query, normalized.variables, normalized.context)
1909
+ .then(fromVariables).then(function (sourcesWithInfo) { return sourcesWithInfo.sources; }));
1910
+ containsDataFromLink = true;
1911
+ }
1912
+ else {
1913
+ var sourcesWithInfo = fromVariables(normalized.variables);
1914
+ containsDataFromLink = sourcesWithInfo.fromLink;
1915
+ concast = new utilities.Concast(sourcesWithInfo.sources);
1916
+ }
1895
1917
  concast.promise.then(cleanupCancelFn, cleanupCancelFn);
1896
- return concast;
1918
+ return {
1919
+ concast: concast,
1920
+ fromLink: containsDataFromLink,
1921
+ };
1897
1922
  };
1898
1923
  QueryManager.prototype.refetchQueries = function (_a) {
1899
1924
  var _this = this;
@@ -2017,54 +2042,40 @@ var QueryManager = (function () {
2017
2042
  case "cache-first": {
2018
2043
  var diff = readCache();
2019
2044
  if (diff.complete) {
2020
- return [
2021
- resultsFromCache(diff, queryInfo.markReady()),
2022
- ];
2045
+ return { fromLink: false, sources: [resultsFromCache(diff, queryInfo.markReady())] };
2023
2046
  }
2024
2047
  if (returnPartialData || shouldNotify) {
2025
- return [
2026
- resultsFromCache(diff),
2027
- resultsFromLink(),
2028
- ];
2048
+ return { fromLink: true, sources: [resultsFromCache(diff), resultsFromLink()] };
2029
2049
  }
2030
- return [
2031
- resultsFromLink(),
2032
- ];
2050
+ return { fromLink: true, sources: [resultsFromLink()] };
2033
2051
  }
2034
2052
  case "cache-and-network": {
2035
2053
  var diff = readCache();
2036
2054
  if (diff.complete || returnPartialData || shouldNotify) {
2037
- return [
2038
- resultsFromCache(diff),
2039
- resultsFromLink(),
2040
- ];
2055
+ return { fromLink: true, sources: [resultsFromCache(diff), resultsFromLink()] };
2041
2056
  }
2042
- return [
2043
- resultsFromLink(),
2044
- ];
2057
+ return { fromLink: true, sources: [resultsFromLink()] };
2045
2058
  }
2046
2059
  case "cache-only":
2047
- return [
2048
- resultsFromCache(readCache(), queryInfo.markReady()),
2049
- ];
2060
+ return { fromLink: false, sources: [resultsFromCache(readCache(), queryInfo.markReady())] };
2050
2061
  case "network-only":
2051
2062
  if (shouldNotify) {
2052
- return [
2053
- resultsFromCache(readCache()),
2054
- resultsFromLink(),
2055
- ];
2063
+ return { fromLink: true, sources: [resultsFromCache(readCache()), resultsFromLink()] };
2056
2064
  }
2057
- return [resultsFromLink()];
2065
+ return { fromLink: true, sources: [resultsFromLink()] };
2058
2066
  case "no-cache":
2059
2067
  if (shouldNotify) {
2060
- return [
2061
- resultsFromCache(queryInfo.getDiff()),
2062
- resultsFromLink(),
2063
- ];
2068
+ return {
2069
+ fromLink: true,
2070
+ sources: [
2071
+ resultsFromCache(queryInfo.getDiff()),
2072
+ resultsFromLink(),
2073
+ ],
2074
+ };
2064
2075
  }
2065
- return [resultsFromLink()];
2076
+ return { fromLink: true, sources: [resultsFromLink()] };
2066
2077
  case "standby":
2067
- return [];
2078
+ return { fromLink: false, sources: [] };
2068
2079
  }
2069
2080
  };
2070
2081
  QueryManager.prototype.getQuery = function (queryId) {
@@ -2220,12 +2231,18 @@ var ApolloClient = (function () {
2220
2231
  return this.cache.readFragment(options, optimistic);
2221
2232
  };
2222
2233
  ApolloClient.prototype.writeQuery = function (options) {
2223
- this.cache.writeQuery(options);
2224
- this.queryManager.broadcastQueries();
2234
+ var ref = this.cache.writeQuery(options);
2235
+ if (options.broadcast !== false) {
2236
+ this.queryManager.broadcastQueries();
2237
+ }
2238
+ return ref;
2225
2239
  };
2226
2240
  ApolloClient.prototype.writeFragment = function (options) {
2227
- this.cache.writeFragment(options);
2228
- this.queryManager.broadcastQueries();
2241
+ var ref = this.cache.writeFragment(options);
2242
+ if (options.broadcast !== false) {
2243
+ this.queryManager.broadcastQueries();
2244
+ }
2245
+ return ref;
2229
2246
  };
2230
2247
  ApolloClient.prototype.__actionHookForDevTools = function (cb) {
2231
2248
  this.devToolsHookCb = cb;