A graphql subscriptions PubSubEngine using IORedis that works with Apollo Server in TypeScript
npm i --save graphql-ioredis-subscriptions
// esm
import RedisPubSubEngine from 'graphql-ioredis-subscriptions`
// commonjs
const RedisPubSubEngine = require('graphql-ioredis-subscriptions')
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...
})
// ...
MIT