Change8

v4.0.0-alpha.0

Breaking Changes
📦 apollo-clientView on GitHub →
12 breaking6 features🔧 15 symbols

Summary

Apollo Client introduces major breaking changes by removing several legacy utilities, dropping React 16 support, and replacing the `ApolloError` wrapper with new error classes, while adding `CombinedGraphQLErrors`, `CombinedProtocolErrors`, and updated query behaviors.

⚠️ Breaking Changes

  • Removed the `asyncMap` utility function; replace its usage with an RxJS operator such as `from` that creates an Observable from a promise.
  • Removed the `isApolloError` utility function; use `instanceof` checks against the new specific error classes instead.
  • Removed the `addTypename` option from `InMemoryCache` and `MockedProvider`; `__typename` is now always added and cannot be disabled, so code that relied on disabling it must include `__typename` in mocked responses.
  • Removed the deprecated `errors` property from `useQuery` and `useLazyQuery`; read errors from the `error` property.
  • Dropped support for React 16; projects must upgrade to React 17 or newer.
  • Removed the deprecated `ignoreResults` option from `useMutation`; use `useApolloClient` and `client.mutate` directly for fire‑and‑forget mutations.
  • Unsubscribing from an `ObservableQuery` while a request is in flight no longer cancels the underlying network request, which may change cancellation semantics.
  • Removed the deprecated `partialRefetch` option.
  • Removed the `iterateObserversSafely` utility function.
  • Apollo Client no longer wraps errors in `ApolloError`; errors are now returned as the native `Error` type or as new classes (`CombinedGraphQLErrors`, `CombinedProtocolErrors`, `UnknownError`). Code that inspected `ApolloError` fields must be updated.
  • `useLazyQuery.previousData` now only updates when `data` changes, not while loading; code that relied on previousData changing during loading may need adjustment.
  • `refetch` with new variables now sets `networkStatus` to `refetch` instead of `setVariables`; adjust any logic that inspected `networkStatus`.

Migration Steps

  1. Replace imports of `asyncMap` with RxJS `from` or another appropriate operator.
  2. Replace `isApolloError` checks with `instanceof` checks against `CombinedGraphQLErrors`, `CombinedProtocolErrors`, `UnknownError`, or the native `Error`.
  3. Remove any `addTypename={false}` usage; ensure mocked responses include a `__typename` field.
  4. Update code to read errors from the `error` property of `useQuery`/`useLazyQuery` instead of `errors`.
  5. Remove `ignoreResults` from `useMutation` calls; use `useApolloClient` and `client.mutate` for fire‑and‑forget mutations.
  6. If you relied on cancelling a request by unsubscribing from an `ObservableQuery`, implement explicit cancellation via the link or an AbortController.
  7. Remove usage of the `partialRefetch` option.
  8. Remove imports of `iterateObserversSafely` and replace with direct iteration or an appropriate utility.
  9. Update error handling: check for `CombinedGraphQLErrors`, `CombinedProtocolErrors`, `UnknownError`, or use `instanceof Error`. Access GraphQL errors via `error.errors` when `error instanceof CombinedGraphQLErrors`.
  10. Adjust any logic that depended on `useLazyQuery.previousData` changing during loading.
  11. Update any `networkStatus` checks that expected `setVariables` after a `refetch` with new variables to now handle `refetch` status.

✨ New Features

  • Introduced `CombinedGraphQLErrors` class to encapsulate multiple GraphQL errors, exposing a `.errors` array.
  • Introduced `CombinedProtocolErrors` class to encapsulate protocol‑level errors, exposing a `.errors` array.
  • Introduced `UnknownError` class for non‑Error objects sent through the link, with the original object stored in the `cause` property.
  • `useLazyQuery.previousData` now updates only when the `data` result actually changes.
  • `refetch` with new variables now sets `networkStatus` to `refetch`.
  • `ObservableQuery` unsubscription no longer aborts in‑flight requests, improving request stability.

🔧 Affected Symbols

asyncMapisApolloErrorInMemoryCache.addTypenameMockedProvider.addTypenameuseQuery.errorsuseLazyQuery.errorsuseMutation.ignoreResultsObservableQueryuseLazyQuery.previousDatauseQuery.refetchiterateObserversSafelyApolloErrorCombinedGraphQLErrorsCombinedProtocolErrorsUnknownError