Change8

@apollo/client@4.0.0-alpha.17

Breaking Changes
📦 apollo-client
3 breaking3 features🔧 12 symbols

Summary

This release introduces a new `dataState` property and modifies the `TData` generic handling, removes the deprecated `QueryReference` type, and adds a `.retain()` method to result promises, requiring migration of type signatures and handling of lazy query execution.

⚠️ Breaking Changes

  • The `TData` generic for types returning a `dataState` property now expects the original `TData` type and requires an explicit `TDataState` generic specifying allowed states, breaking existing `QueryRef` type signatures.
  • The deprecated `QueryReference` type has been removed; code must replace it with `QueryRef`.
  • `useLazyQuery`'s `execute` function now aborts previously started queries from the same hook unless the previous promise's `.retain()` method is called, breaking callers that relied on previous behavior.

Migration Steps

  1. Update all `QueryRef` (and related) type declarations to include the appropriate `TDataState` generic, e.g., replace `QueryRef<TData, TVariables>` with `QueryRef<TData, TVariables, 'complete' | 'streaming'>` or the full set of states as needed.
  2. Replace any usage of the removed `QueryReference` type with `QueryRef`.
  3. If you call `useLazyQuery`'s `execute` multiple times, call `.retain()` on the promise returned by previous `execute` calls to prevent them from being aborted.
  4. Adjust code that relied on the previous `ResultPromise` behavior to handle the new `.retain()` method if needed.

✨ New Features

  • Added a new `dataState` property to indicate completeness of `data`, emitted from `ObservableQuery` and all React hooks.
  • `ObservableQuery.refetch`, `ObservableQuery.reobserve`, and the `execute` function of `useLazyQuery` now return a `ResultPromise` with a `.retain()` method to keep the network operation alive.
  • Default `*QueryRef` types now default to `complete | streaming` states, while other types default to `complete | streaming | partial | empty`.

🔧 Affected Symbols

ApolloQueryResultQueryRefPreloadedQueryRefuseLazyQuery.ResultuseQuery.ResultuseReadQuery.ResultuseSuspenseQuery.ResultQueryReferenceuseLazyQueryObservableQuery.refetchObservableQuery.reobserveResultPromise.retain