Registry / storage / apollo-proxy-cache

apollo-proxy-cache

JSON →
library10.0.1jsnpmunverified

Apollo Link and Express middleware that caches GraphQL queries using a @cache directive. Version 10.0.1 supports Apollo Client 3, Express 4, and any GraphQL >=14. It provides an in-memory cache (Map-based) and a Redis backend. Key differentiator: server-side caching for SSR to reduce initial render time, with a proxy that strips the directive and serves cached responses locally. It uses http-proxy-middleware to forward non-cached queries. Release cadence is semantic-release based, with frequent minor updates.

npm install apollo-proxy-cache
INSTALL
IMPORT
SIG · APOLLO-PROXY-CACHE
A
apollo-proxy-cache
storagejavascriptv10.0.1
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.

createProxyCacheMiddleware
import { createProxyCacheMiddleware } from 'apollo-proxy-cache'
const { createProxyCacheMiddleware } = require('apollo-proxy-cache')
Package is ESM-only as of v10.0.1; CJS require works only in older versions.
InMemoryCache
import { InMemoryCache } from 'apollo-proxy-cache'
import InMemoryCache from 'apollo-proxy-cache/InMemoryCache'
InMemoryCache is exported from the main package index, not a subpath.
RedisCache
import { RedisCache } from 'apollo-proxy-cache'
import { RedisCache } from 'apollo-proxy-cache/RedisCache'
RedisCache is exported from the main index. Requires passing a Redis client instance.

Sets up Express middleware with InMemoryCache that caches GraphQL queries containing @cache directive and proxies others.

import { createProxyCacheMiddleware, InMemoryCache } from 'apollo-proxy-cache'; import express from 'express'; import bodyParser from 'body-parser'; const queryCache = new InMemoryCache(); const app = express(); app.use(bodyParser.json()); const { directiveMiddleware, proxyMiddleware } = createProxyCacheMiddleware(queryCache)( { target: 'http://localhost:4000/graphql', changeOrigin: true } ); app.use('/graphql', directiveMiddleware); app.use('/graphql', proxyMiddleware); app.listen(3000);
Debug
Known issues
breakingVersion 10.0.0 dropped support for Node <16.
fix
Upgrade Node to >=16 or use an older version of the package.
affects: <10.0.0
deprecatedThe 'apollo-utilities' peer dependency is deprecated; @apollo/client v3 includes its own utilities.
fix
Replace usage of apollo-utilities with @apollo/client equivalents.
affects: >=10.0.0
gotchabody-parser (or equivalent) must be registered before the proxy cache middleware.
fix
Ensure app.use(bodyParser.json()) precedes app.use('/graphql', directiveMiddleware).
affects: >=1.0.0
gotchaThe @cache directive is stripped from queries before forwarding; ensure your GraphQL server does not require the directive.
fix
Your server schema should not enforce unknown directives; the directive is only used client-side.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'apollo-utilities'
Missing peer dependency apollo-utilities.
fix
npm install apollo-utilities
ReferenceError: require is not defined in ES module scope
Using require() with ESM package in Node >=16.
fix
Use import statements instead of require().
TypeError: req.body is undefined
body-parser not set up before middleware.
fix
Add app.use(bodyParser.json()) before the proxy middleware.
Upgrade
Version history
10.0.1latest on npm
Audit
Dependencies
@apollo/clientrequiredPeer dependency for Apollo Link integration
expressrequiredPeer dependency for Express middleware
http-proxy-middlewarerequiredPeer dependency for proxy functionality
graphqlrequiredPeer dependency for GraphQL query processing
apollo-utilitiesrequiredPeer dependency for utility functions
lodashrequiredPeer dependency for cache key modifier path handling
Agent activity
43 hits · last 30 days
node
38
Resources
apollo-proxy-cache — npm install apollo-proxy-cache · libregistry