Registry / devops / apollo-cache-router

apollo-cache-router

JSON →
library1.1.6jsnpmunverified

Apollo Cache Router is a utility that routes GraphQL operations to different caches based on directives or query names. Version 1.1.6, last updated in 2019, it extends Apollo Client's cache layer by allowing multiple InMemoryCache instances and custom routing logic. It supports TypeScript, uses ESM imports, and is useful for separating client-only and network GraphQL data. Differentiates from standard Apollo Cache by enabling conditional cache selection via a routing function and cache overrides for lifecycle methods. Requires apollo-cache and graphql as peer dependencies.

npm install apollo-cache-router
INSTALL
IMPORT
SIG · APOLLO-CACHE-ROUTE
A
apollo-cache-router
devopsjavascriptv1.1.6
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import ApolloCacheRouter from 'apollo-cache-router'
const ApolloCacheRouter = require('apollo-cache-router')
Default export; requires ESM. CommonJS not supported.
ApolloCacheRouter
import ApolloCacheRouter from 'apollo-cache-router'
Same as default import; no named export.
CacheResolverFn
import type { CacheResolverFn } from 'apollo-cache-router'
import { CacheResolverFn } from 'apollo-cache-router'
Type export; use type import in TypeScript to avoid runtime import.

Creates a routed cache that sends @client queries to localCache and others to netCache, with custom reset logic.

import { InMemoryCache } from 'apollo-cache-inmemory'; import ApolloCacheRouter from 'apollo-cache-router'; import { hasDirectives } from 'apollo-utilities'; const netCache = new InMemoryCache(); const localCache = new InMemoryCache(); const cache = ApolloCacheRouter.override( ApolloCacheRouter.route([netCache, localCache], document => { if (hasDirectives(['client'], document)) { return [localCache]; } else { return [netCache]; } }), { reset: () => netCache.reset() } ); export { cache };
Debug
Known issues
deprecatedPackage no longer maintained; last release 2019.
fix
Consider forking or using alternative cache management.
affects: >=0.0.0
gotchaApolloCacheRouter expects multiple cache instances; passing single cache will cause routing to always return first.
fix
Provide array of caches as first argument to route().
affects: >=0.0.0
breakingTypeScript types may be incomplete; some internal types exported but not documented.
fix
Use as any or cast types if needed.
affects: >=1.0.0
gotchaoverride() only supports reset method; other lifecycle methods like evict or persist may not work as expected.
fix
Implement custom override object with required methods only.
affects: >=0.0.0
Errors
Common errors & fixes
Cannot find module 'apollo-cache-router'
Missing npm package or typo in import path.
fix
Run 'npm install apollo-cache-router'
TypeError: Cannot read property 'route' of undefined
Incorrect import; default export is a class or object.
fix
Use 'import ApolloCacheRouter from 'apollo-cache-router''
Expected 2 arguments, but got 1.
route() requires two arguments: array of caches and routing function.
fix
Call ApolloCacheRouter.route([cache1, cache2], document => ...)
Upgrade
Version history
1.1.6latest on npm
Audit
Dependencies
apollo-cacherequiredpeer dependency; provides base Cache type
graphqlrequiredpeer dependency; used for operation analysis
Agent activity
14 hits · last 30 days
node
12
OpenAI (training)
1
Resources
apollo-cache-router — npm install apollo-cache-router · libregistry