graphql-resolver-cache-key-config

1.0.3 • Public • Published

Graphql resolver cache

Greenkeeper badge

Maintenance Status NPM version Build Status Dependency Status Coverage Status Code Climate BCH compliance

Easy wrapper around resolvers to cache results based on root elements and Graphql query arguments. Works best with Apollo Graphql.

Installation

$ npm install graphql-resolver-cache --save

Configuration

Add a cache to your Graphql middleware:

import express from 'express';
import bodyParser from 'body-parser';
import { graphqlExpress } from 'apollo-server-express';
import { LruCache } from 'graphql-resolver-cache';

const myGraphQLSchema = // ... define or import your schema here!
const PORT = 3000;

const app = express();
const resolverCache = new LruCache();

// bodyParser is needed just for POST.
app.use('/graphql', bodyParser.json(), graphqlExpress({ 
  schema: myGraphQLSchema,
  context: { resolverCache }
}));

app.listen(PORT);

Wrap your resolver in a cache function:

import { withCache } from 'graphql-resolver-cache';
export default {
  User: {
    getFriends: withCache((root, args, context) => { /* logic */ }),
  },
};

Readme

Keywords

Package Sidebar

Install

npm i graphql-resolver-cache-key-config

Weekly Downloads

1

Version

1.0.3

License

MIT

Unpacked Size

109 kB

Total Files

15

Last publish

Collaborators

  • matteodem