1.0.9 • Published 5 years ago

graphqlcache-server v1.0.9

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

graphqlcache-server

About

graphqlcache-server module will let you cache graphql query data, if it finds the similar query it will return cached data.

Usage

import express from 'express'
import { graphqlExpress } from 'apollo-server-express';
import { graphql } from 'graphql';
const bodyParser = require('body-parser')

var graphqlcache = require('graphqlcache-server');

const app = express();
app.use(bodyParser.json()) /* must parse the body */

graphqlcache({
  engine: 'redis',    /* If you don't specify the redis engine,      */
  port: 6379,         /* the query results will be cached in memory. */
  host: 'localhost'
})


app.use(graphqlcache.intercept)

const options = {
   ttl: 86400 // Cache time out in seconds default is 60 seconds.
   cacheData: true /* Can turn on/off cached data response any time, default true */
}
app.use('/graphql', graphqlcache.sendIfCached(options), graphqlExpress({ schema }));