@apollo/client@4.0.0-alpha.20
Breaking Changes📦 apollo-client
⚠ 5 breaking✨ 4 features🔧 8 symbols
Summary
Apollo Client 8 introduces breaking API changes: ObservableQuery loses its queryId, getObservableQueries now returns a Set, and preloadQuery’s toPromise API changes, while adding a new ObservableQuery.stop method and more aggressive client cleanup.
⚠️ Breaking Changes
- ObservableQuery no longer has a `queryId` property; code accessing `queryId` must be removed or replaced.
- `ApolloClient.getObservableQueries` now returns a `Set<ObservableQuery>` instead of a `Map<string, ObservableQuery>`; update code that expects a Map (e.g., iteration over entries) to work with a Set.
- `ObservableQuery`s are only registered with the client while they have subscribers; consequently `ApolloClient.getObservableQueries` and `ApolloClient.refetchQueries` will only return/refetch queries that have at least one subscriber. Adjust logic that relied on previously registered inactive queries.
- `queryRef` objects created by `preloadQuery` no longer have a `.toPromise()` method. Use `preloadQuery.toPromise(queryRef)` instead.
- `ApolloClient.stop()` now unsubscribes all active ObservableQuery instances and rejects in‑flight queries; ensure any custom cleanup logic accounts for the completed events and rejected promises.
Migration Steps
- Remove any usage of `observableQuery.queryId`.
- Replace code that treats the result of `ApolloClient.getObservableQueries` as a Map with code that works with a Set (e.g., use `for (const oq of set)` or convert to an array).
- If you relied on `ApolloClient.getObservableQueries` or `ApolloClient.refetchQueries` returning inactive queries, add explicit subscriptions or adjust logic to handle the new active/inactive definitions.
- Change `await queryRef.toPromise()` to `await preloadQuery.toPromise(queryRef)`.
- If you have custom listeners for the `completed` event from `ApolloClient.stop()`, verify they still behave as expected after the aggressive cleanup.
✨ New Features
- Added a `.stop` method on `ObservableQuery` to unsubscribe all current subscribers and tear down the query.
- Introduced `preloadQuery.toPromise(queryRef)` as a top‑level helper to await a preload query.
- `ObservableQuery`s are now registered with the client only while they have subscribers, improving resource usage.
- `ApolloClient.stop()` now performs more aggressive cleanup, unsubscribing active queries and rejecting in‑flight queries.
🔧 Affected Symbols
ObservableQueryObservableQuery.queryIdApolloClient.getObservableQueriesApolloClient.refetchQueriesApolloClient.stoppreloadQuerypreloadQuery.toPromisequeryRef