Registry / database / apollo-simple-cache

apollo-simple-cache

JSON →
library0.4.3jsnpmunverified

A lightweight cache library for Apollo Client (v0.4.3, updated ~2024) providing two simplified cache implementations: SimpleDocumentCache (a fast per-query document cache) and OptimizedNormalizedCache (a normalized cache optimized for read/write performance, often faster than Apollo's InMemoryCache). Ships TypeScript types, requires Node >=20, and has peer dependencies on @apollo/client ^3.13.8 || ^4 and graphql ^15 || ^16. Differentiators include explicit control over cache keys, optimized reads, and a simpler API surface compared to Apollo's built-in caches.

npm install apollo-simple-cache
INSTALL
IMPORT
SIG · APOLLO-SIMPLE-CACH
A
apollo-simple-cache
databasejavascriptv0.4.3
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.

SimpleDocumentCache
import { SimpleDocumentCache } from 'apollo-simple-cache';
import SimpleDocumentCache from 'apollo-simple-cache';
Named export — cannot use default import. For Apollo Client v4, use 'apollo-simple-cache/v4' instead.
OptimizedNormalizedCache
import { OptimizedNormalizedCache } from 'apollo-simple-cache';
const { OptimizedNormalizedCache } = require('apollo-simple-cache');
ESM-only package (Node >=20, no CommonJS exports). Must use import syntax.
SimpleDocumentCacheOptions
import type { SimpleDocumentCacheOptions } from 'apollo-simple-cache';
import { SimpleDocumentCacheOptions } from 'apollo-simple-cache';
TypeScript type — import with 'import type' or use as value but it will be a type-only export in runtime.

Creates an Apollo Client with SimpleDocumentCache and executes a simple query. Note the document must have an operation name.

import { ApolloClient, InMemoryCache } from '@apollo/client'; import { SimpleDocumentCache } from 'apollo-simple-cache'; const cache = new SimpleDocumentCache(); const client = new ApolloClient({ uri: process.env.GRAPHQL_ENDPOINT ?? 'http://localhost:4000/graphql', cache, }); // The GraphQL document must have an operation name with default options. const query = ` query GetUser($id: ID!) { user(id: $id) { id name } } `; client.query({ query: gql`${query}`, variables: { id: '1' }, }).then(result => console.log(result.data));
Debug
Known issues
breakingApollo Client v4 users must import from 'apollo-simple-cache/v4' instead of 'apollo-simple-cache'.
fix
Replace import { ... } from 'apollo-simple-cache' with import { ... } from 'apollo-simple-cache/v4'.
affects: >=4.0.0
gotchaSimpleDocumentCache does NOT support optimistic updates. Using optimistic updates will silently fail or produce incorrect results.
fix
Use OptimizedNormalizedCache or InMemoryCache if you need optimistic UI.
affects: >=0.0.0
gotchaSimpleDocumentCache requires the GraphQL document to have an operation name (e.g., 'query MyQuery') by default. Missing operation name causes cache misses.
fix
Either add operation names to all queries, or provide a custom getCacheKey callback.
affects: >=0.0.0
breakingPackage is ESM-only and requires Node >=20. Using require() or older Node throws an error.
fix
Use import syntax and ensure Node version >=20.
affects: >=0.0.0
Errors
Common errors & fixes
ERR_REQUIRE_ESM: require() of ES Module not supported
Package is ESM-only and does not provide CommonJS exports.
fix
Change require() to import or set type: 'module' in package.json.
Cannot find module 'apollo-simple-cache/v4'
Using v4 import path but npm version or installation is too old.
fix
Ensure you are using apollo-simple-cache v0.4.0 or later and have installed @apollo/client v4.
Upgrade
Version history
0.4.3latest on npm
Audit
Dependencies
@apollo/clientrequiredPeer dependency — Apollo Client is required to use the cache classes (SimpleDocumentCache and OptimizedNormalizedCache).
graphqlrequiredPeer dependency — GraphQL is required for query documents and type definitions.
Agent activity
24 hits · last 30 days
node
20
OpenAI (training)
1
Resources
apollo-simple-cache — npm install apollo-simple-cache · libregistry