Migrating to Apollo Client @apollo/client@4.0.0-alpha.21
Version @apollo/client@4.0.0-alpha.21 introduces 3 breaking changes. This guide details how to update your code.
Released: 6/10/2025
⚠️ Check Your Code
If you use any of these symbols, you need to read this guide:
NetworkStatususeLazyQuerycache.fragmentMatchesBreaking Changes
●Issue #1
The `loading` flag now stays true for `@defer` queries until the streamed response completes, which may affect UI logic that expected `loading` to become false while streaming.
●Issue #2
`cache.fragmentMatches` is now required; the previous check and warning were removed, so data masking will crash if `cache.fragmentMatches` is missing.
●Issue #3
`useLazyQuery` no longer accepts a `context` option; `context` must be passed to the returned `execute` function, and omitted context defaults to an empty object.
Migration Steps
- 1Update UI or logic that checks the `loading` flag for `@defer` queries to handle the flag remaining true until streaming completes.
- 2Ensure your cache implementation provides a `fragmentMatches` function; otherwise data masking will throw.
- 3Remove `context` from `useLazyQuery` hook options and pass it as the first argument to the `execute` function instead; if omitted, it will default to `{}`.
Release Summary
Added streaming support for `@defer` queries with a new `NetworkStatus.streaming` value and changed loading semantics, removed the `context` option from `useLazyQuery`, and made `cache.fragmentMatches` mandatory.
Need More Details?
View the full release notes and all changes for Apollo Client @apollo/client@4.0.0-alpha.21.
View Full Changelog