Synchronize Apollo Client state effortlessly across all browsing contexts, such as browser tabs, windows, and iframes.
Apollo State Sync keeps Apollo Client state consistent across browsing contexts without redundant network requests.
It syncs Apollo's in-memory cache and reactive variables across contexts, and can persist state between sessions so users can resume where they left off. It also avoids duplicate GraphQL subscription channels across contexts.
Modern web apps often run across multiple browser tabs or windows within the same workflow. Without shared state synchronization, users can end up with inconsistent data:
Apollo State Sync solves this by keeping state in sync across browsing contexts and user sessions. Apollo Shared WS reuses a shared WebSocket connection to share active subscription channels.
❗ Apollo State Sync keeps Apollo state synchronized across tabs and windows. For shared GraphQL subscription channels and a single reused WebSocket connection across browsing contexts, install and configure Apollo Shared WS npm package.
npm install apollo-state-sync
pnpm add apollo-state-sync
pnpm add apollo-state-sync --filter="./packages/my-workspace"
pnpm add apollo-state-sync -w
yarn add apollo-state-sync
yarn workspace <workspace-name> add apollo-state-sync
yarn add -W apollo-state-sync
Apollo State Sync listens for state changes in Apollo Client and broadcasts them across browsing contexts using Broadcast Channels. It can also persist state in Local Storage so it remains available when the user reopens the app.
If you want to migrate an existing Apollo Client TypeScript project to Apollo State Sync, you can run the following commands:
npm i --save-dev ts-morph
npx apollo-state-sync --help
npx apollo-state-sync
By default, WebSocket migration is not enabled. For details on WebSocket configuration and migration, see the Apollo Shared WebSocket documentation.
To know what the migration does, or to migrate manually, refer to this API_OVERVIEW guide.
For most use cases, refer to the API_OVERVIEW guide.
For advanced configurations, refer to this API Reference.
💬 Have an idea? Suggest new features in GitHub Discussions.
🚀 Support me or my projects through donations.
💼 Need custom work or consultation? I am available for hire! Reach out via email.