@apollo/client 3.10.4 → 3.10.6

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 (57) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/apollo-client.cjs +63 -36
  3. package/apollo-client.cjs.map +1 -1
  4. package/apollo-client.min.cjs +1 -1
  5. package/core/core.cjs +1 -1
  6. package/core/core.cjs.map +1 -1
  7. package/core/core.cjs.native.js +1 -1
  8. package/dev/dev.cjs +1 -1
  9. package/dev/dev.cjs.map +1 -1
  10. package/dev/dev.cjs.native.js +1 -1
  11. package/link/batch-http/batch-http.cjs +6 -5
  12. package/link/batch-http/batch-http.cjs.map +1 -1
  13. package/link/batch-http/batch-http.cjs.native.js +6 -5
  14. package/link/batch-http/batchHttpLink.js +15 -10
  15. package/link/batch-http/batchHttpLink.js.map +1 -1
  16. package/link/error/error.cjs +3 -2
  17. package/link/error/error.cjs.map +1 -1
  18. package/link/error/error.cjs.native.js +3 -2
  19. package/link/error/index.js +3 -2
  20. package/link/error/index.js.map +1 -1
  21. package/package.json +10 -6
  22. package/react/hooks/hooks.cjs +61 -34
  23. package/react/hooks/hooks.cjs.map +1 -1
  24. package/react/hooks/hooks.cjs.native.js +61 -34
  25. package/react/hooks/internal/useRenderGuard.js +37 -12
  26. package/react/hooks/internal/useRenderGuard.js.map +1 -1
  27. package/react/hooks/useLazyQuery.js +7 -8
  28. package/react/hooks/useLazyQuery.js.map +1 -1
  29. package/react/hooks/useLoadableQuery.d.ts +1 -1
  30. package/react/hooks/useLoadableQuery.js +9 -2
  31. package/react/hooks/useLoadableQuery.js.map +1 -1
  32. package/react/hooks/useMutation.js +11 -7
  33. package/react/hooks/useMutation.js.map +1 -1
  34. package/react/hooks/useQuery.d.ts +2 -2
  35. package/react/hooks/useQuery.js +26 -12
  36. package/react/hooks/useQuery.js.map +1 -1
  37. package/react/hooks/useQueryRefHandlers.js +4 -0
  38. package/react/hooks/useQueryRefHandlers.js.map +1 -1
  39. package/react/hooks/useReadQuery.js +5 -1
  40. package/react/hooks/useReadQuery.js.map +1 -1
  41. package/react/hooks/useSubscription.js +4 -0
  42. package/react/hooks/useSubscription.js.map +1 -1
  43. package/react/hooks/useSuspenseQuery.js +2 -2
  44. package/react/hooks/useSuspenseQuery.js.map +1 -1
  45. package/react/hooks/useSyncExternalStore.js +4 -0
  46. package/react/hooks/useSyncExternalStore.js.map +1 -1
  47. package/react/internal/internal.cjs +1 -1
  48. package/react/internal/internal.cjs.map +1 -1
  49. package/react/internal/internal.cjs.native.js +1 -1
  50. package/testing/core/mocking/mockLink.d.ts +8 -3
  51. package/testing/core/mocking/mockLink.js.map +1 -1
  52. package/testing/internal/profile/profile.js +6 -2
  53. package/testing/internal/profile/profile.js.map +1 -1
  54. package/utilities/globals/globals.cjs +1 -1
  55. package/utilities/globals/globals.cjs.map +1 -1
  56. package/utilities/globals/globals.cjs.native.js +1 -1
  57. package/version.js +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,36 @@
1
1
  # @apollo/client
2
2
 
3
+ ## 3.10.6
4
+
5
+ ### Patch Changes
6
+
7
+ - [#11900](https://github.com/apollographql/apollo-client/pull/11900) [`f745558`](https://github.com/apollographql/apollo-client/commit/f74555826995009a6bb9d824506cecb3508e3365) Thanks [@phryneas](https://github.com/phryneas)! - `useMutation`: use `useIsomorphicLayoutEffect` instead of `useLayoutEffect`
8
+
9
+ ## 3.10.5
10
+
11
+ ### Patch Changes
12
+
13
+ - [#11888](https://github.com/apollographql/apollo-client/pull/11888) [`7fb7939`](https://github.com/apollographql/apollo-client/commit/7fb7939edb7ca8f4273b75554f96ea9936731458) Thanks [@phryneas](https://github.com/phryneas)! - switch `useRenderGuard` to an approach not accessing React's internals
14
+
15
+ - [#11511](https://github.com/apollographql/apollo-client/pull/11511) [`6536369`](https://github.com/apollographql/apollo-client/commit/6536369cf213469d20d15b779c344268d70fecd5) Thanks [@phryneas](https://github.com/phryneas)! - `useLoadableQuery`: ensure that `loadQuery` is updated if the ApolloClient instance changes
16
+
17
+ - [#11860](https://github.com/apollographql/apollo-client/pull/11860) [`8740f19`](https://github.com/apollographql/apollo-client/commit/8740f198805a99e01136617c4055d611b92cc231) Thanks [@alessbell](https://github.com/alessbell)! - Fixes [#11849](https://github.com/apollographql/apollo-client/issues/11849) by reevaluating `window.fetch` each time `BatchHttpLink` uses it, if not configured via `options.fetch`. Takes the same approach as PR [#8603](https://github.com/apollographql/apollo-client/pull/8603) which fixed the same issue in `HttpLink`.
18
+
19
+ - [#11852](https://github.com/apollographql/apollo-client/pull/11852) [`d502a69`](https://github.com/apollographql/apollo-client/commit/d502a69654d8ffa31e09467da028304a934a9874) Thanks [@phryneas](https://github.com/phryneas)! - Fix a bug where calling the `useMutation` `reset` function would point the hook to an outdated `client` reference.
20
+
21
+ - [#11329](https://github.com/apollographql/apollo-client/pull/11329) [`3d164ea`](https://github.com/apollographql/apollo-client/commit/3d164ea16c17d271f6fa9e5ad8f013623eec23a0) Thanks [@PaLy](https://github.com/PaLy)! - Fix graphQLErrors in Error Link if networkError.result is an empty string
22
+
23
+ - [#11852](https://github.com/apollographql/apollo-client/pull/11852) [`d502a69`](https://github.com/apollographql/apollo-client/commit/d502a69654d8ffa31e09467da028304a934a9874) Thanks [@phryneas](https://github.com/phryneas)! - Prevent writing to a ref in render in `useMutation`.
24
+ As a result, you might encounter problems in the future if you call the mutation's `execute` function during render. Please note that this was never supported behavior, and we strongly recommend against it.
25
+
26
+ - [#11848](https://github.com/apollographql/apollo-client/pull/11848) [`ad63924`](https://github.com/apollographql/apollo-client/commit/ad6392424ddbeb6f91b165c806251490e1cdd69e) Thanks [@phryneas](https://github.com/phryneas)! - Ensure covariant behavior: `MockedResponse<X,Y>` should be assignable to `MockedResponse`
27
+
28
+ - [#11851](https://github.com/apollographql/apollo-client/pull/11851) [`45c47be`](https://github.com/apollographql/apollo-client/commit/45c47be26d4e020cfcff359a5af19ccfc39b930e) Thanks [@phryneas](https://github.com/phryneas)! - Avoid usage of useRef in useInternalState to prevent ref access in render.
29
+
30
+ - [#11877](https://github.com/apollographql/apollo-client/pull/11877) [`634d91a`](https://github.com/apollographql/apollo-client/commit/634d91aeb10ab308b05d5ffb918678806046af09) Thanks [@phryneas](https://github.com/phryneas)! - Add missing name to tuple member (fix TS5084)
31
+
32
+ - [#11851](https://github.com/apollographql/apollo-client/pull/11851) [`45c47be`](https://github.com/apollographql/apollo-client/commit/45c47be26d4e020cfcff359a5af19ccfc39b930e) Thanks [@phryneas](https://github.com/phryneas)! - Fix a bug where `useLazyQuery` would not pick up a client change.
33
+
3
34
  ## 3.10.4
4
35
 
5
36
  ### 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.10.4";
34
+ var version = "3.10.6";
35
35
 
36
36
  function maybe(thunk) {
37
37
  try {
@@ -7421,15 +7421,28 @@ function useDeepMemo(memoFn, deps) {
7421
7421
  return ref.current.value;
7422
7422
  }
7423
7423
 
7424
- function getRenderDispatcher() {
7425
- var _a, _b;
7426
- return (_b = (_a = React__namespace.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED) === null || _a === void 0 ? void 0 : _a.ReactCurrentDispatcher) === null || _b === void 0 ? void 0 : _b.current;
7427
- }
7428
- var RenderDispatcher = null;
7424
+ var useIsomorphicLayoutEffect = canUseDOM ? React__namespace.useLayoutEffect : React__namespace.useEffect;
7425
+
7426
+ var Ctx;
7427
+ function noop() { }
7429
7428
  function useRenderGuard() {
7430
- RenderDispatcher = getRenderDispatcher();
7431
- return React__namespace.useCallback(function () {
7432
- return (RenderDispatcher != null && RenderDispatcher === getRenderDispatcher());
7429
+ if (!Ctx) {
7430
+ Ctx = React__namespace.createContext(null);
7431
+ }
7432
+ return React__namespace.useCallback(
7433
+ function () {
7434
+ var orig = console.error;
7435
+ try {
7436
+ console.error = noop;
7437
+ React__namespace["useContext" ](Ctx);
7438
+ return true;
7439
+ }
7440
+ catch (e) {
7441
+ return false;
7442
+ }
7443
+ finally {
7444
+ console.error = orig;
7445
+ }
7433
7446
  }, []);
7434
7447
  }
7435
7448
 
@@ -7474,14 +7487,16 @@ function _useQuery(query, options) {
7474
7487
  return useInternalState(useApolloClient(options.client), query).useQuery(options);
7475
7488
  }
7476
7489
  function useInternalState(client, query) {
7477
- var stateRef = React__namespace.useRef();
7478
- if (!stateRef.current ||
7479
- client !== stateRef.current.client ||
7480
- query !== stateRef.current.query) {
7481
- stateRef.current = new InternalState(client, query, stateRef.current);
7482
- }
7483
- var state = stateRef.current;
7484
- state.forceUpdateState = React__namespace.useReducer(function (tick) { return tick + 1; }, 0)[1];
7490
+ var forceUpdateState = React__namespace.useReducer(function (tick) { return tick + 1; }, 0)[1];
7491
+ function createInternalState(previous) {
7492
+ return Object.assign(new InternalState(client, query, previous), {
7493
+ forceUpdateState: forceUpdateState,
7494
+ });
7495
+ }
7496
+ var _a = React__namespace.useState(createInternalState), state = _a[0], updateState = _a[1];
7497
+ if (client !== state.client || query !== state.query) {
7498
+ updateState((state = createInternalState(state)));
7499
+ }
7485
7500
  return state;
7486
7501
  }
7487
7502
  var InternalState = (function () {
@@ -7544,7 +7559,8 @@ var InternalState = (function () {
7544
7559
  this.renderPromises = React__namespace.useContext(getApolloContext()).renderPromises;
7545
7560
  this.useOptions(options);
7546
7561
  var obsQuery = this.useObservableQuery();
7547
- var result = useSyncExternalStore(React__namespace.useCallback(function (handleStoreChange) {
7562
+ var result = useSyncExternalStore(
7563
+ React__namespace.useCallback(function (handleStoreChange) {
7548
7564
  if (_this.renderPromises) {
7549
7565
  return function () { };
7550
7566
  }
@@ -7779,17 +7795,15 @@ function useLazyQuery(query, options) {
7779
7795
  var useQueryResult = internalState.useQuery(tslib.__assign(tslib.__assign({}, merged), { skip: !execOptionsRef.current }));
7780
7796
  var initialFetchPolicy = useQueryResult.observable.options.initialFetchPolicy ||
7781
7797
  internalState.getDefaultFetchPolicy();
7782
- var result = Object.assign(useQueryResult, {
7783
- called: !!execOptionsRef.current,
7784
- });
7798
+ var forceUpdateState = internalState.forceUpdateState, obsQueryFields = internalState.obsQueryFields;
7785
7799
  var eagerMethods = React__namespace.useMemo(function () {
7786
7800
  var eagerMethods = {};
7787
7801
  var _loop_1 = function (key) {
7788
- var method = result[key];
7802
+ var method = obsQueryFields[key];
7789
7803
  eagerMethods[key] = function () {
7790
7804
  if (!execOptionsRef.current) {
7791
7805
  execOptionsRef.current = Object.create(null);
7792
- internalState.forceUpdateState();
7806
+ forceUpdateState();
7793
7807
  }
7794
7808
  return method.apply(this, arguments);
7795
7809
  };
@@ -7799,8 +7813,9 @@ function useLazyQuery(query, options) {
7799
7813
  _loop_1(key);
7800
7814
  }
7801
7815
  return eagerMethods;
7802
- }, []);
7803
- Object.assign(result, eagerMethods);
7816
+ }, [forceUpdateState, obsQueryFields]);
7817
+ var called = !!execOptionsRef.current;
7818
+ var result = React__namespace.useMemo(function () { return (tslib.__assign(tslib.__assign(tslib.__assign({}, useQueryResult), eagerMethods), { called: called })); }, [useQueryResult, eagerMethods, called]);
7804
7819
  var execute = React__namespace.useCallback(function (executeOptions) {
7805
7820
  execOptionsRef.current =
7806
7821
  executeOptions ? tslib.__assign(tslib.__assign({}, executeOptions), { fetchPolicy: executeOptions.fetchPolicy || initialFetchPolicy }) : {
@@ -7812,7 +7827,7 @@ function useLazyQuery(query, options) {
7812
7827
  .then(function (queryResult) { return Object.assign(queryResult, eagerMethods); });
7813
7828
  promise.catch(function () { });
7814
7829
  return promise;
7815
- }, []);
7830
+ }, [eagerMethods, initialFetchPolicy, internalState]);
7816
7831
  return [execute, result];
7817
7832
  }
7818
7833
 
@@ -7832,9 +7847,9 @@ function useMutation(mutation, options) {
7832
7847
  mutation: mutation,
7833
7848
  options: options,
7834
7849
  });
7835
- {
7850
+ useIsomorphicLayoutEffect(function () {
7836
7851
  Object.assign(ref.current, { client: client, options: options, mutation: mutation });
7837
- }
7852
+ });
7838
7853
  var execute = React__namespace.useCallback(function (executeOptions) {
7839
7854
  if (executeOptions === void 0) { executeOptions = {}; }
7840
7855
  var _a = ref.current, options = _a.options, mutation = _a.mutation;
@@ -7908,15 +7923,20 @@ function useMutation(mutation, options) {
7908
7923
  }, []);
7909
7924
  var reset = React__namespace.useCallback(function () {
7910
7925
  if (ref.current.isMounted) {
7911
- var result_3 = { called: false, loading: false, client: client };
7926
+ var result_3 = {
7927
+ called: false,
7928
+ loading: false,
7929
+ client: ref.current.client,
7930
+ };
7912
7931
  Object.assign(ref.current, { mutationId: 0, result: result_3 });
7913
7932
  setResult(result_3);
7914
7933
  }
7915
7934
  }, []);
7916
7935
  React__namespace.useEffect(function () {
7917
- ref.current.isMounted = true;
7936
+ var current = ref.current;
7937
+ current.isMounted = true;
7918
7938
  return function () {
7919
- ref.current.isMounted = false;
7939
+ current.isMounted = false;
7920
7940
  };
7921
7941
  }, []);
7922
7942
  return [execute, tslib.__assign({ reset: reset }, result)];
@@ -8469,11 +8489,11 @@ function _useSuspenseQuery(query, options) {
8469
8489
  };
8470
8490
  }, [queryRef.result]);
8471
8491
  var result = fetchPolicy === "standby" ? skipResult : __use(promise);
8472
- var fetchMore = React__namespace.useCallback((function (options) {
8492
+ var fetchMore = React__namespace.useCallback(function (options) {
8473
8493
  var promise = queryRef.fetchMore(options);
8474
8494
  setPromise([queryRef.key, queryRef.promise]);
8475
8495
  return promise;
8476
- }), [queryRef]);
8496
+ }, [queryRef]);
8477
8497
  var refetch = React__namespace.useCallback(function (variables) {
8478
8498
  var promise = queryRef.refetch(variables);
8479
8499
  setPromise([queryRef.key, queryRef.promise]);
@@ -8636,10 +8656,17 @@ function useLoadableQuery(query, options) {
8636
8656
  return client.watchQuery(tslib.__assign(tslib.__assign({}, watchQueryOptions), { variables: variables }));
8637
8657
  });
8638
8658
  setQueryRef(wrapQueryRef(queryRef));
8639
- }, [query, queryKey, suspenseCache, watchQueryOptions, calledDuringRender]);
8659
+ }, [
8660
+ query,
8661
+ queryKey,
8662
+ suspenseCache,
8663
+ watchQueryOptions,
8664
+ calledDuringRender,
8665
+ client,
8666
+ ]);
8640
8667
  var reset = React__namespace.useCallback(function () {
8641
8668
  setQueryRef(null);
8642
- }, [queryRef]);
8669
+ }, []);
8643
8670
  return [loadQuery, queryRef, { fetchMore: fetchMore, refetch: refetch, reset: reset }];
8644
8671
  }
8645
8672
 
@@ -8694,7 +8721,7 @@ function _useReadQuery(queryRef) {
8694
8721
  updateWrappedQueryRef(queryRef, promise);
8695
8722
  forceUpdate();
8696
8723
  });
8697
- }, [internalQueryRef]), getPromise, getPromise);
8724
+ }, [internalQueryRef, queryRef]), getPromise, getPromise);
8698
8725
  var result = __use(promise);
8699
8726
  return React__namespace.useMemo(function () {
8700
8727
  return {