v4.0.0-alpha.11
Breaking Changes📦 apollo-client
⚠ 3 breaking✨ 5 features🐛 1 fixes⚡ 1 deprecations🔧 9 symbols
Summary
Apollo Client vX introduces major API changes: context no longer provides `cache`/`forceFetch`, `ApolloLink.execute` now requires a client argument, and `useMutation` typings are stricter, alongside new features like custom context typing and a re‑exported `gql`.
⚠️ Breaking Changes
- `cache` and `forceFetch` properties were removed from the context returned by `operation.getContext()`. Access the cache via `operation.client.cache` and use the new `queryDeduplication` flag instead of `forceFetch`.
- `ApolloLink.execute` (and the exported `execute` function) now requires a third argument `{ client }` that identifies the ApolloClient instance initiating the request. Calls must be updated to pass this object.
- `useMutation` TypeScript signatures now enforce required variables. Missing required variables will cause compile errors; provide them to the hook or to the returned `mutate` function.
Migration Steps
- Replace any usage of `operation.getContext().cache` with `operation.client.cache`.
- Replace any usage of `operation.getContext().forceFetch` with the `queryDeduplication` flag available on the operation.
- Update all direct calls to `ApolloLink.execute` or the `execute` helper to include a third argument: `ApolloLink.execute(link, operation, { client })`.
- If you rely on TypeScript typings for `useMutation`, ensure required variables are supplied either to the hook or to the `mutate` function; adjust code accordingly.
- Add a declaration merging file (e.g., `@apollo-client.d.ts`) to extend `DefaultContext` with any custom properties as shown in the release notes.
✨ New Features
- Extension for defining custom properties on the link‑chain context via declaration merging of `DefaultContext`.
- `operation` objects now include a `client` property referencing the ApolloClient that made the request.
- `gql` is now re‑exported from the `@apollo/client/react` entry point.
- Built‑in links (`HttpLink` and `BatchHttpLink`) expose `ContextOptions` types for use with the custom context extension.
- `useMutation` typings were improved to make required variables optional in the returned `mutate` function when supplied to the hook.
🐛 Bug Fixes
- Queries are no longer broadcast when they are torn down, preventing unnecessary network activity.
🔧 Affected Symbols
operation.getContextApolloLink.executeexecuteuseMutationoperationDefaultContextHttpLink.ContextOptionsBatchHttpLink.ContextOptionsgql⚡ Deprecations
- `forceFetch` property is deprecated and removed; replace with `queryDeduplication`.