/Atlantis

Lightweight server-side caching solution for GraphQL.

Primary LanguageJavaScriptMIT LicenseMIT

Atlantis-Cache

Light-weight server-side caching solution for GraphQL.

GitHub license npm GitHub issues

About

Atlantis is a light-weight library that solves the issue of storing and maintaining deeply-nested GraphQL queries. This ensures the client always receives the most relevant data as mutations are made to the database. Atlantis leverages Redis’s ‘in-memory’ quick lookup time to rapidly serve up cached graphQL responses regardless of size or structure.Redis integration along with Pub/Sub architecture also allows for scaling as your needs grow and you require more cache space or backup cache workers. New queries that bare resemblance to previous queries, are intelligently pulled from the existing cached nesting instead of creating a new key/value entry.

This package is meant to work in conjunction with Redis. For more information about Redis: check out: Redis

                                           atlantis_demo

Getting Started

1. Installing and Connecting to a Redis Server

  • 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)
  • Linux or non-Homebrew:

    • 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:

License

This product is licensed under the MIT License - see the LICENSE.md file for details.‌

This product is accelerated by OS Labs.