@apollo/client@4.0.0-rc.5
Breaking Changes📦 apollo-client
⚠ 3 breaking✨ 3 features⚡ 1 deprecations🔧 10 symbols
Summary
This release adds improved handling of masked fragments, introduces dataState in watchFragment, normalizes empty argument storage, and updates cache read behavior, while deprecating old readFragment/readQuery signatures and removing gql from the react entrypoint.
⚠️ Breaking Changes
- client.readQuery, client.readFragment, client.watchFragment, useFragment, and useSuspenseFragment now apply document transforms before reading data from the cache, changing previous behavior. To retain the old behavior, use the equivalent cache.readQuery, cache.readFragment, etc.
- cache.watchFragment now returns an Unmasked<TData> result instead of a masked result, which may break TypeScript type expectations.
- The gql export has been removed from the @apollo/client/react entrypoint; import gql from @apollo/client instead.
Migration Steps
- Replace imports of gql from @apollo/client/react with imports from @apollo/client.
- If you need the previous cache‑reading behavior, switch from client.readQuery/client.readFragment/etc. to cache.readQuery, cache.readFragment, etc.
- Update TypeScript code to handle the Unmasked<TData> return type from cache.watchFragment.
- Modify calls to readFragment and readQuery to include the optimistic flag inside the first argument object instead of as a separate second argument.
✨ New Features
- Masked fragments are now reported as complete even when a nested masked fragment contains partial data.
- client.watchFragment now emits a dataState property in its result.
- InMemoryCache now stores fields with an empty argument object the same way as fields without arguments.
🔧 Affected Symbols
client.readQueryclient.readFragmentclient.watchFragmentuseFragmentuseSuspenseFragmentcache.watchFragmentgqlreadFragmentreadQueryInMemoryCache⚡ Deprecations
- The second argument to readFragment and readQuery is deprecated; pass the optimistic flag as part of the first argument object.