@apollo/client@4.2.0-alpha.4
📦 apollo-clientView on GitHub →
✨ 8 features🔧 7 symbols
Summary
This release introduces automatic event-based refetching capabilities through the new RefetchEventManager, allowing queries to automatically refresh on events like window focus or network reconnection. Event refetching is opt-in and highly configurable at both the client and query levels.
Migration Steps
- To activate event-based refetching, create and pass a RefetchEventManager instance to the ApolloClient constructor, configuring desired sources.
- If migrating from previous behavior where refetching might have been implicitly enabled, ensure you explicitly configure `refetchEventManager` in ApolloClient, as event refetching is now fully opt-in.
- If customizing event handling, ensure custom handlers return a RefetchQueriesResult or void.
✨ New Features
- Added support for automatic event-based refetching (e.g., window focus) via the new RefetchEventManager class.
- Introduced built-in event sources: windowFocusSource and onlineSource.
- Queries can now opt out of event refetching using the `refetchOn` option in useQuery, which supports boolean values, specific event control, or a function for dynamic control.
- Event refetching is opt-in by passing a RefetchEventManager instance to the ApolloClient constructor.
- Support for custom events by registering them via TypeScript module augmentation and providing an Observable source function.
- Imperative triggering of event refetches using refetchEventManager.emit(eventName, payload).
- Support for sourceless events (declared as true) that only support imperative emission.
- Ability to override the default refetch handler for specific events within RefetchEventManager configuration.