@magnicache/server
v1.0.9
Published
Server side caching for GraphQL
Downloads
28
Readme
Magnicache/server
@magnicache/server is a lightweight GraphQL caching solution.
Imported as a package from npm, @magnicache/server can be inserted into the middleware chain for a GraphQL endpoint to intercept GraphQL requests and scan the cache for previously executed queries.
Queries present in the cache will return the cached result to the client, improving response speeds and overall GraphQL performance.
How to use @magnicache/server in your GraphQL api
- Install MagniCache Server.
npm i @magnicache/server
- Import MagniCache.
const MagniCache = require('@magnicache/server');
- Declare a new instance of MagniCache, passing in your GraphQL schema.
const magnicache = new MagniCache(schema);
Insert magnicache.query into the middleware chain for your '/graphql' route.
- Ensure all request bodies are parsed
app.use(express.json());
app.use('/graphql', magnicache.query, (req, res) =>
res.status(200).send(res.locals.queryResponse)
);