v4.0.0-alpha.8
Breaking Changes📦 apollo-client
⚠ 4 breaking✨ 6 features🐛 1 fixes⚡ 4 deprecations🔧 12 symbols
Summary
This release adds a unified error handling API for `onError`, enhances `MockLink` with variable callbacks, realistic delay helpers, and default delay configuration, while removing deprecated methods and options that require migration.
⚠️ Breaking Changes
- Removed the `onError` and `setOnError` methods from `ApolloLink`; code that calls these methods must be updated to use the new `onError` link signature that provides a single `error` property.
- Removed the `variableMatcher` option from mocked responses passed to `MockLink`; replace it with a callback assigned to `request.variables`.
- Removed the undocumented `newData` option from mocked responses (both `MockLink` and `MockedProvider`); replicate its behavior by using a `result` callback and setting `maxUsageCount: Number.POSITIVE_INFINITY`.
- The `@apollo/client/core` entry point will be removed in the next major version; migrate imports from `@apollo/client/core` to `@apollo/client` now to avoid future breakage.
Migration Steps
- Update `onError` link usage: replace `onError(({ graphQLErrors, networkError, protocolErrors }) => { ... })` with `onError(({ error }) => { ... })` and handle `CombinedGraphQLErrors` or `CombinedProtocolErrors` as needed.
- Remove any imports or calls to `ApolloLink.onError` and `ApolloLink.setOnError`.
- For mocks, move the callback from `variableMatcher` to `request.variables` (e.g., `variables: (requestVariables) => true`).
- Replace `newData` with `result` callback and add `maxUsageCount: Number.POSITIVE_INFINITY` if you need infinite usage.
- Change imports from `@apollo/client/core` to `@apollo/client`.
- If you relied on the previous zero‑delay default for mocks, set `MockLink.defaultOptions = { delay: 0 }` to retain the old behavior.
✨ New Features
- `onError` link now reports a single `error` property which can be an instance of `CombinedGraphQLErrors`, `CombinedProtocolErrors`, or the original error type.
- `MockLink` now accepts a callback for `request.variables` to match mocks based on request variables.
- Added `realisticDelay` helper function for generating random delays (20‑50ms by default) for mocked responses.
- Mocked responses can now accept a callback for the `delay` option, receiving the current operation to compute dynamic delays.
- Global and per‑instance default `delay` configuration for `MockLink` via `MockLink.defaultOptions`.
- The `@apollo/client` and `@apollo/client/core` entry points are now identical.
🐛 Bug Fixes
- Throws an explicit error when a client‑only query is used in a mocked response passed to `MockLink`.
🔧 Affected Symbols
ApolloLink.onErrorApolloLink.setOnErroronErrorMockLinkMockedProviderrequest.variablesrealisticDelayMockLink.defaultOptionsCombinedGraphQLErrorsCombinedProtocolErrors@apollo/client@apollo/client/core⚡ Deprecations
- `onError` and `setOnError` methods on `ApolloLink` are deprecated and have been removed.
- `variableMatcher` option for `MockLink` mocks is deprecated and removed.
- `newData` option for mocked responses is deprecated and removed.
- `@apollo/client/core` entry point is deprecated and will be removed in the next major release.