atlantis-cache
v1.0.5
Published
Server-side caching solution for graphQL
Downloads
28
Readme
About
Atlantis is a light-weight library that leverages a Redis key-value store to dynamically cache GraphQL queries as responses. Atlantis is able to dynamically store deeply-nested queries and maintain the most recent and relevant data as mutations are made to the database. Queries that are more shallow and within the scope of previous queries are pulled directly from the cache, offering further flexibility and precision, without additional network requests or overriding previous key-values.
Getting Started
1. Installing and Connecting to a Redis Server
This package is meant to work in conjunction with redis. To install redis:
Mac-HomeBrew:
- At the terminal,
brew install redis
- Start redis server with
redis-server
- Test if redis server is running:
redis-cli ping
. If it replies “PONG”, then it’s good to go! - Default port is
6379
(Keep note of the port)
- At the terminal,
Linux or Window:
- Download appropriate version of Redis from redis.io/download
- Follow the instructions
- Once installation is completed, start redis server with
redis-server
- Default port is
6379
(Keep note of the port)
2. Installing Atlantis-Cache
Install Atlantis-Cache as an npm module and save it to your package.json as a dependency.
npm i atlantis-cache
How to Use Atlantis-Cache
const express = require('express');
const redis = require('redis');
const { graphql } = require('graphql');
const schema = require('./schema/schema');
const { atlantis } = require('atlantis-cache');
const app = express();
// Configure your redis client
const redisClient = redis.createClient({
host: 'localhost',
port: 6379,
});
// Define your endpoint for graphQL queries and pass in your redis, and schema
app.use('/graphql', atlantis(redisClient, schema), async (req, res) => {
return res.status(202).json({ data: res.locals.graphQLResponse });
});
Contributors:
- Coral Fussman - Github | Linkedin
- Sett Hein -Github | Linkedin
- Erik Matevosyan - Github | Linkedin
- Erik Rogel - Github | Linkedin
Notes:
if you want to use graphiQL (graphQL IDE), you can use a different endpoint for atlantis requests in devlopment. ie. app.use('/atlantis', atlants ..) as the middleware for all your queries. Then, app.use('/graphql',) for your graphQLHTTP import.