graphql-ioredis-subscriptions
TypeScript icon, indicating that this package has built-in type declarations

2.1.0 • Public • Published

graphql-ioredis-subscriptions

A graphql subscriptions PubSubEngine using IORedis that works with Apollo Server in TypeScript

Installation

npm i --save graphql-ioredis-subscriptions

Usage

Supports both ESM and CommonJS

// esm
import RedisPubSubEngine from 'graphql-ioredis-subscriptions`
// commonjs
const RedisPubSubEngine = require('graphql-ioredis-subscriptions')

Use it with Type-GraphQL and ApolloServer

import RedisPubSubEngine from 'graphql-ioredis-subscriptions`
import { ApolloServer } from 'apollo-server'
import { buildSchema } from 'type-graphql'
import IORedis from 'ioredis'

const schema = buildSchema({
  //...
  pubSub: new RedisPubSubEngine({
    /* required */
    pub: new IORedis(),
    sub: new IORedis(),

    /* optional */
    // defaults to JSON
    parser: {
      stringify: (val) => JSON.stringify(val)
      parse: (str) => JSON.parse(str)
    },
    // defaults to console
    logger: {
      warn: (...args) => console.warn(...args)
      error: (...args) => console.error(...args)
    }
  })
})

const server = new ApolloServer({
  schema,
  // other options...
})

// ...

License

MIT

Dependents (0)

Package Sidebar

Install

npm i graphql-ioredis-subscriptions

Weekly Downloads

7

Version

2.1.0

License

MIT

Unpacked Size

123 kB

Total Files

37

Last publish

Collaborators

  • tjmehta