@apollo/client 3.11.3 → 3.11.5

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 (44) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/apollo-client.cjs +17 -25
  3. package/apollo-client.cjs.map +1 -1
  4. package/apollo-client.min.cjs +1 -1
  5. package/cache/core/types/common.d.ts +5 -3
  6. package/cache/core/types/common.js.map +1 -1
  7. package/cache/inmemory/entityStore.js.map +1 -1
  8. package/core/ObservableQuery.d.ts +1 -1
  9. package/core/ObservableQuery.js +7 -0
  10. package/core/ObservableQuery.js.map +1 -1
  11. package/core/core.cjs +4 -1
  12. package/core/core.cjs.map +1 -1
  13. package/core/core.cjs.native.js +4 -1
  14. package/dev/dev.cjs +1 -1
  15. package/dev/dev.cjs.map +1 -1
  16. package/dev/dev.cjs.native.js +1 -1
  17. package/package.json +4 -4
  18. package/react/hooks/hooks.cjs +12 -23
  19. package/react/hooks/hooks.cjs.map +1 -1
  20. package/react/hooks/hooks.cjs.native.js +12 -23
  21. package/react/hooks/internal/index.d.ts +0 -1
  22. package/react/hooks/internal/index.js +0 -1
  23. package/react/hooks/internal/index.js.map +1 -1
  24. package/react/hooks/useFragment.js +21 -15
  25. package/react/hooks/useFragment.js.map +1 -1
  26. package/react/internal/internal.cjs +1 -1
  27. package/react/internal/internal.cjs.map +1 -1
  28. package/react/internal/internal.cjs.native.js +1 -1
  29. package/react/types/types.d.ts +1 -1
  30. package/react/types/types.js.map +1 -1
  31. package/utilities/caching/sizes.d.ts +2 -2
  32. package/utilities/caching/sizes.js.map +1 -1
  33. package/utilities/globals/globals.cjs +1 -1
  34. package/utilities/globals/globals.cjs.map +1 -1
  35. package/utilities/globals/globals.cjs.native.js +1 -1
  36. package/utilities/observables/Concast.js +1 -1
  37. package/utilities/observables/Concast.js.map +1 -1
  38. package/utilities/utilities.cjs +1 -1
  39. package/utilities/utilities.cjs.map +1 -1
  40. package/utilities/utilities.cjs.native.js +1 -1
  41. package/version.js +1 -1
  42. package/react/hooks/internal/useLazyRef.d.ts +0 -3
  43. package/react/hooks/internal/useLazyRef.js +0 -10
  44. package/react/hooks/internal/useLazyRef.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,30 @@
1
1
  # @apollo/client
2
2
 
3
+ ## 3.11.5
4
+
5
+ ### Patch Changes
6
+
7
+ - [#12027](https://github.com/apollographql/apollo-client/pull/12027) [`eb3e21b`](https://github.com/apollographql/apollo-client/commit/eb3e21b9f7fa6a3161705c2c7270129c17b65095) Thanks [@JavaScriptBach](https://github.com/JavaScriptBach)! - Type `MutationResult.reset` as an arrow function
8
+
9
+ - [#12020](https://github.com/apollographql/apollo-client/pull/12020) [`82d8cb4`](https://github.com/apollographql/apollo-client/commit/82d8cb4255be497748829f12eb25ac87c11ee5e4) Thanks [@jerelmiller](https://github.com/jerelmiller)! - Better conform to Rules of React by avoiding write of ref in render for `useFragment`.
10
+
11
+ ## 3.11.4
12
+
13
+ ### Patch Changes
14
+
15
+ - [#11994](https://github.com/apollographql/apollo-client/pull/11994) [`41b17e5`](https://github.com/apollographql/apollo-client/commit/41b17e5950f4db5ef9e32ded5bb327b3bf19e6e8) Thanks [@jerelmiller](https://github.com/jerelmiller)! - Update the `Modifier` function type to allow `cache.modify` to return deeply partial data.
16
+
17
+ - [#11989](https://github.com/apollographql/apollo-client/pull/11989) [`e609156`](https://github.com/apollographql/apollo-client/commit/e609156c4989def88ae1a28b2e0f0378077a5528) Thanks [@phryneas](https://github.com/phryneas)! - Fix a potential crash when calling `clearStore` while a query was running.
18
+
19
+ Previously, calling `client.clearStore()` while a query was running had one of these results:
20
+
21
+ - `useQuery` would stay in a `loading: true` state.
22
+ - `useLazyQuery` would stay in a `loading: true` state, but also crash with a `"Cannot read property 'data' of undefined"` error.
23
+
24
+ Now, in both cases, the hook will enter an error state with a `networkError`, and the promise returned by the `useLazyQuery` `execute` function will return a result in an error state.
25
+
26
+ - [#11994](https://github.com/apollographql/apollo-client/pull/11994) [`41b17e5`](https://github.com/apollographql/apollo-client/commit/41b17e5950f4db5ef9e32ded5bb327b3bf19e6e8) Thanks [@jerelmiller](https://github.com/jerelmiller)! - Prevent accidental distribution on `cache.modify` field modifiers when a field is a union type array.
27
+
3
28
  ## 3.11.3
4
29
 
5
30
  ### Patch Changes
package/apollo-client.cjs CHANGED
@@ -31,7 +31,7 @@ function _interopNamespace(e) {
31
31
  var equal__default = /*#__PURE__*/_interopDefaultLegacy(equal);
32
32
  var React__namespace = /*#__PURE__*/_interopNamespace(React);
33
33
 
34
- var version = "3.11.3";
34
+ var version = "3.11.5";
35
35
 
36
36
  function maybe(thunk) {
37
37
  try {
@@ -1396,7 +1396,7 @@ var Concast = (function (_super) {
1396
1396
  _this.cancel = function (reason) {
1397
1397
  _this.reject(reason);
1398
1398
  _this.sources = [];
1399
- _this.handlers.complete();
1399
+ _this.handlers.error(reason);
1400
1400
  };
1401
1401
  _this.promise.catch(function (_) { });
1402
1402
  if (typeof sources === "function") {
@@ -5363,6 +5363,9 @@ var ObservableQuery = (function (_super) {
5363
5363
  },
5364
5364
  error: function (error) {
5365
5365
  if (equal.equal(_this.variables, variables)) {
5366
+ if (!isApolloError(error)) {
5367
+ error = new ApolloError({ networkError: error });
5368
+ }
5366
5369
  finishWaitingForOwnResult();
5367
5370
  _this.reportError(error, variables);
5368
5371
  }
@@ -7478,15 +7481,6 @@ function useRenderGuard() {
7478
7481
  }, []);
7479
7482
  }
7480
7483
 
7481
- var INIT = {};
7482
- function useLazyRef(getInitialValue) {
7483
- var ref = React__namespace.useRef(INIT);
7484
- if (ref.current === INIT) {
7485
- ref.current = getInitialValue();
7486
- }
7487
- return ref;
7488
- }
7489
-
7490
7484
  var useKey = "use";
7491
7485
  var realHook = React__namespace[useKey];
7492
7486
  var __use = realHook ||
@@ -8190,23 +8184,20 @@ function useFragment(options) {
8190
8184
  }
8191
8185
  function _useFragment(options) {
8192
8186
  var cache = useApolloClient(options.client).cache;
8193
- var diffOptions = useDeepMemo(function () {
8194
- var fragment = options.fragment, fragmentName = options.fragmentName, from = options.from, _a = options.optimistic, optimistic = _a === void 0 ? true : _a, rest = tslib.__rest(options, ["fragment", "fragmentName", "from", "optimistic"]);
8195
- return tslib.__assign(tslib.__assign({}, rest), { returnPartialData: true, id: typeof from === "string" ? from : cache.identify(from), query: cache["getFragmentDoc"](fragment, fragmentName), optimistic: optimistic });
8196
- }, [options]);
8197
- var resultRef = useLazyRef(function () {
8198
- return diffToResult(cache.diff(diffOptions));
8199
- });
8200
- var stableOptions = useDeepMemo(function () { return options; }, [options]);
8201
- React__namespace.useMemo(function () {
8202
- resultRef.current = diffToResult(cache.diff(diffOptions));
8203
- }, [diffOptions, cache]);
8204
- var getSnapshot = React__namespace.useCallback(function () { return resultRef.current; }, []);
8187
+ var from = options.from, rest = tslib.__rest(options, ["from"]);
8188
+ var id = React__namespace.useMemo(function () { return (typeof from === "string" ? from : cache.identify(from)); }, [cache, from]);
8189
+ var resultRef = React__namespace.useRef();
8190
+ var stableOptions = useDeepMemo(function () { return (tslib.__assign(tslib.__assign({}, rest), { from: id })); }, [rest, id]);
8191
+ var currentDiff = React__namespace.useMemo(function () {
8192
+ var fragment = stableOptions.fragment, fragmentName = stableOptions.fragmentName, from = stableOptions.from, _a = stableOptions.optimistic, optimistic = _a === void 0 ? true : _a;
8193
+ return diffToResult(cache.diff(tslib.__assign(tslib.__assign({}, stableOptions), { returnPartialData: true, id: from, query: cache["getFragmentDoc"](fragment, fragmentName), optimistic: optimistic })));
8194
+ }, [stableOptions, cache]);
8195
+ var getSnapshot = React__namespace.useCallback(function () { return resultRef.current || currentDiff; }, [currentDiff]);
8205
8196
  return useSyncExternalStore(React__namespace.useCallback(function (forceUpdate) {
8206
8197
  var lastTimeout = 0;
8207
8198
  var subscription = cache.watchFragment(stableOptions).subscribe({
8208
8199
  next: function (result) {
8209
- if (equal__default(result, resultRef.current))
8200
+ if (equal__default(result, currentDiff))
8210
8201
  return;
8211
8202
  resultRef.current = result;
8212
8203
  clearTimeout(lastTimeout);
@@ -8214,10 +8205,11 @@ function _useFragment(options) {
8214
8205
  },
8215
8206
  });
8216
8207
  return function () {
8208
+ resultRef.current = void 0;
8217
8209
  subscription.unsubscribe();
8218
8210
  clearTimeout(lastTimeout);
8219
8211
  };
8220
- }, [cache, stableOptions]), getSnapshot, getSnapshot);
8212
+ }, [cache, stableOptions, currentDiff]), getSnapshot, getSnapshot);
8221
8213
  }
8222
8214
  function diffToResult(diff) {
8223
8215
  var result = {