Skip to content

Latest commit

History

History
74 lines (46 loc) 路 1.7 KB

README.md

File metadata and controls

74 lines (46 loc) 路 1.7 KB

GraphQL Rate Limit - Redis store

This example illustrates using Redis as a data store. Commonly used to share state in a distrubuted environment.

Overview

Use RateLimiterRedis along with a redis or ioredis client.

Setup

A Redis server is required and the GraphQL server needs to know how to connect to it.

Redis Server

Option 1: Free Cloud Hosted

Use Redis Labs' free subscription for a small cloud hosted Redis database. See Creating a Subscription.

Option 2: Manually

Download, install, and configure Redis.

GraphQL Server

This example requires a url and password to a Redis database.

Step 1: Install requirements

yarn install

Step 2: Create a .env file

cp .env.sample .env

Step 3: Set environment variables

In .env file, set REDIS_URL and REDIS_PASSWORD. These values are used on server startup.

Example .env content:

REDIS_URL=redis://redis-12345.c14.us-east-1-2.ec2.cloud.redislabs.com:12345
REDIS_PASSWORD=MySecretString

Run

Step 1: Start server

node index.js

Step 2: Open GraphiQL

Navigate to http://localhost:4000/graphql in a browser.

Step 3: Execute GraphQL operations

Server is configured to allow each root field to be queried once every 15 seconds. Sample query:

{
  quote
  books {
    title
    author
  }
}