v4.0.0-alpha.2
Breaking Changes📦 apollo-client
⚠ 7 breaking✨ 3 features🐛 1 fixes⚡ 1 deprecations🔧 8 symbols
Summary
Apollo Client 4.0 removes several generic arguments and options, defaults data and variable types to `unknown`/`OperationVariables`, and fixes the CommonJS build, requiring code updates for TypeScript users.
⚠️ Breaking Changes
- Removed the `TSerialized` generic argument from `ApolloCache`; `cache.extract` now returns `unknown`. Update type annotations or cast the result to the expected shape.
- Removed the `TCacheShape` generic argument from `ApolloClient`; `client.extract()` now returns `unknown`. Cast the result or call `cache.extract()` on a subclass for a specific type.
- Removed the `defaultOptions` option from `useQuery`. Pass options directly to the hook or configure them via the global `ApolloClient.defaultOptions`.
- Removed the `canonizeResults` option. Code that relied on referential equality when this option was true must be updated, as object identity is no longer guaranteed.
- Removed the `resetResultIdentities` option from `InMemoryCache.gc()`. Calls that passed this option must be simplified to `cache.gc()` without arguments.
- Defaulted the `TData` generic type to `unknown` in all APIs (e.g., `useQuery`, `client.query`). Explicitly specify the data type if you need stricter typing.
- Defaulted the `TVariables` generic type to `OperationVariables` instead of `any`. Provide explicit variable type definitions where needed.
Migration Steps
- Update any `ApolloCache` implementations that relied on the `TSerialized` generic; adjust code to handle `unknown` return type from `cache.extract`.
- Remove `TCacheShape` from `ApolloClient` type parameters and cast the result of `client.extract()` if a specific shape is required.
- Replace usage of `useQuery({ defaultOptions: ... })` with direct option arguments or configure `ApolloClient.defaultOptions` globally.
- Delete any references to the `canonizeResults` option; be aware that result object identity may change.
- Remove the `resetResultIdentities` argument from calls to `InMemoryCache.gc()`.
- If you relied on implicit `any` for `TData` or `TVariables`, add explicit generic type arguments to queries, mutations, and hooks.
- Run TypeScript compilation to surface any type errors introduced by the generic removals.
✨ New Features
- Default `TData` generic type is now `unknown` across the client APIs.
- Default `TVariables` generic type is now `OperationVariables` instead of `any`.
- Fixed the 4.0 CommonJS build.
🐛 Bug Fixes
- Fixed the 4.0 CommonJS build to work correctly.
🔧 Affected Symbols
ApolloCacheApolloClientuseQueryInMemoryCache.gcclient.extractcache.extractTDataTVariables⚡ Deprecations
- The `canonizeResults` option was deprecated and has now been removed.