All Projects → mikesparr → Tutorial Graphql Subscriptions Redis

mikesparr / Tutorial Graphql Subscriptions Redis

GraphQL server implementation with Redis backing allowing pubsub

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Tutorial Graphql Subscriptions Redis

Graphql Redis Subscriptions
A graphql subscriptions implementation using redis and apollo's graphql-subscriptions
Stars: ✭ 829 (+6808.33%)
Mutual labels:  graphql, graphql-subscriptions, redis
Aws Mobile Appsync Sdk Ios
iOS SDK for AWS AppSync.
Stars: ✭ 231 (+1825%)
Mutual labels:  graphql, graphql-subscriptions
36 Graphql Concepts
📜 36 concepts every GraphQL developer should know.
Stars: ✭ 209 (+1641.67%)
Mutual labels:  graphql, graphql-subscriptions
Express Graphql Mongodb Boilerplate
A boilerplate for Node.js apps / GraphQL-API / Authentication from scratch - express, graphql - (graphql compose), mongodb (mongoose).
Stars: ✭ 288 (+2300%)
Mutual labels:  graphql, redis
Blog Service
blog service @nestjs
Stars: ✭ 188 (+1466.67%)
Mutual labels:  graphql, redis
Grial
A Node.js framework for creating GraphQL API servers easily and without a lot of boilerplate.
Stars: ✭ 194 (+1516.67%)
Mutual labels:  graphql, graphql-subscriptions
Morpheus Graphql
Haskell GraphQL Api, Client and Tools
Stars: ✭ 285 (+2275%)
Mutual labels:  graphql, graphql-subscriptions
Graphql Genie
Simply pass in your GraphQL type defintions and get a fully featured GraphQL API with referential integrity, inverse updates, subscriptions and role based access control that can be used client side or server side.
Stars: ✭ 147 (+1125%)
Mutual labels:  graphql, graphql-subscriptions
Aws Lambda Graphql
Use AWS Lambda + AWS API Gateway v2 for GraphQL subscriptions over WebSocket and AWS API Gateway v1 for HTTP
Stars: ✭ 313 (+2508.33%)
Mutual labels:  graphql, graphql-subscriptions
Graphql Ts Server Boilerplate
A GraphQL server boilerplate made with Typescript, PostgreSQL, and Redis
Stars: ✭ 643 (+5258.33%)
Mutual labels:  graphql, redis
Graphql Yoga
🧘 Fully-featured GraphQL Server with focus on easy setup, performance & great developer experience
Stars: ✭ 6,573 (+54675%)
Mutual labels:  graphql, graphql-subscriptions
Fullstack Boilerplate
Fullstack boilerplate using Typescript, React, GraphQL
Stars: ✭ 181 (+1408.33%)
Mutual labels:  graphql, redis
Portara
Portara directive is a rate limiter / throttler for GraphQL
Stars: ✭ 158 (+1216.67%)
Mutual labels:  graphql, redis
Djangochannelsgraphqlws
Django Channels based WebSocket GraphQL server with Graphene-like subscriptions
Stars: ✭ 203 (+1591.67%)
Mutual labels:  graphql, graphql-subscriptions
Graphql Kafka Subscriptions
Apollo graphql subscriptions over Kafka protocol
Stars: ✭ 154 (+1183.33%)
Mutual labels:  graphql, graphql-subscriptions
Type Graphql Series
Typescript GraphQL Server built with TypeGraphQL
Stars: ✭ 249 (+1975%)
Mutual labels:  graphql, redis
Graphql Postgres Subscriptions
A graphql subscriptions implementation using postgres and apollo's graphql-subscriptions
Stars: ✭ 133 (+1008.33%)
Mutual labels:  graphql, graphql-subscriptions
Graphql Mqtt Subscriptions
graphql-subscriptions implementation for MQTT protocol
Stars: ✭ 133 (+1008.33%)
Mutual labels:  graphql, graphql-subscriptions
Altair
✨⚡️ A beautiful feature-rich GraphQL Client for all platforms.
Stars: ✭ 3,827 (+31791.67%)
Mutual labels:  graphql, graphql-subscriptions
Aws Mobile Appsync Sdk Js
JavaScript library files for Offline, Sync, Sigv4. includes support for React Native
Stars: ✭ 806 (+6616.67%)
Mutual labels:  graphql, graphql-subscriptions

GraphQL Subscriptions (server) with Redis

This repository includes a working (as of Feb 23, 2018) Apollo GraphQL server implementation providing subscriptions with Redis backing. After scouring various articles and documents, I finally got it working and felt there needs to be a concise HOWTO for what will be a very popular use case.

Background

In a new product, we wanted realtime notifications to users, and planned on adding a Redis user cache. Our UI is built with React and Redux, so we decided on GraphQL as the API layer (instead of REST), and wanted to leverage the new subscriptions feature, or at least compare it to polling.

System Requirements

  • Node version 6 or later
  • Terminal (command line interface and npm)
  • Redis server
  • Apollo Engine API Key (because it's cool and free first 1 million queries/mo)

TL;DR

  1. Clone and install the app
git clone [email protected]:mikesparr/tutorial-graphql-subscriptions-redis.git
cd tutorial-graphql-subscriptions-redis
npm install
  1. Add local ENV variables (I use dotenv or .env file)
# environment variables for application
export SERVER_PORT=3000
export REDIS_HOST=localhost
export REDIS_PORT=6379
  1. Make sure Redis is running
  • Mac users: brew install redis && brew services start redis
  1. Start the server
  • npm start
  1. Open browser (1) to http://localhost:3000/graphiql

  2. Open another browser (2) tab to same URL

  3. Open terminal window (1) to Redis monitor

  • redis-cli monitor
  1. Open second terminal window (2) to execute Redis CLI commands
  • TIP: don't start interactive session and just wait for steps below
  1. In browser (1), subscribe to messages (paste in graphiql and run)
subscription {
  messageAdded {
    id
    content
  }
}
  1. In browser (2), publish (mutate) a message (paste in graphiql and run)
mutation {
  addMessage(message: "Hello World") 
}
  1. In terminal window (1) confirm publish messages appear

  2. In browser (1), confirm message appears

  3. In terminal window (2) publish new message

redis-cli PUBLISH "messageAdded" '{"messageAdded": {"id": "555", "content": "Hello Redis"}}'
  1. Confirm terminal (1) and browser (1) messages appear

  2. Congratulations! Your GraphQL server delivered subscription messages to a client from both mutations and new messages directly into Redis!

Important lessons learned

  • You need to publish a server with subscriptions for clients to use the feature
  • You must wrap Express with another http client in server.js for web socket conn
  • Redis PubSub messages must include wrapper object with schema subscription name
  • To handle incoming messages from Redis you need to use pubsub.subscribe()
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].