Registry / messaging / graphql-redis-subscriptions

graphql-redis-subscriptions

JSON →
library2.7.0jsnpmunverified

A PubSub engine for GraphQL subscriptions using Redis as the message broker, enabling horizontal scaling of subscription managers across multiple server instances. Version 2.7.0 is the current stable release, published in early 2024, with no fixed release cadence. It implements both PubSubEngine and AsyncIterator interfaces from graphql-subscriptions. Key differentiators: supports Redis patterns (PSUBSCRIBE), custom serialization, trigger transforms, and connection pooling via separate publisher/subscriber clients. Ships TypeScript types. Peer dependencies: graphql-subscriptions ^1.0.0 || ^2.0.0 || ^3.0.0.

npm install graphql-redis-subscriptions
INSTALL
IMPORT
SIG · GRAPHQL-REDIS-SUBS
G
graphql-redis-subscriptions
messagingjavascriptv2.7.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

RedisPubSub
import { RedisPubSub } from 'graphql-redis-subscriptions';
const RedisPubSub = require('graphql-redis-subscriptions');
This package is ESM-only; CommonJS require will fail unless using dynamic import().
PubSubRedisOptions
import type { PubSubRedisOptions } from 'graphql-redis-subscriptions';
import { PubSubRedisOptions } from 'graphql-redis-subscriptions';
PubSubRedisOptions is a TypeScript interface. Use `import type` for type-only imports to avoid runtime errors.
withFilter
import { withFilter } from 'graphql-subscriptions';
import { withFilter } from 'graphql-redis-subscriptions';
withFilter is exported from graphql-subscriptions, not from this package.

Demonstrates creating a RedisPubSub instance, using asyncIterator, withFilter for subscription filtering, and publishing events.

import { RedisPubSub } from 'graphql-redis-subscriptions'; import { withFilter } from 'graphql-subscriptions'; // Create a RedisPubSub instance with default connection (localhost:6379) const pubsub = new RedisPubSub(); // Define a topic const CHAT_TOPIC = 'chat'; // In your subscription resolver: const resolvers = { Subscription: { messageAdded: { subscribe: withFilter( () => pubsub.asyncIterator(CHAT_TOPIC), (payload, variables) => payload.messageAdded.roomId === variables.roomId ), }, }, }; // Publishing an event pubsub.publish(CHAT_TOPIC, { messageAdded: { roomId: '123', text: 'Hello!' } }); // Remember to close the connection when done (e.g., in server shutdown) // pubsub.close();
Debug
Known issues
breakingIf you use CommonJS (require), the import will break. Since version 2.x, the package is ESM-only.
fix
Switch to ES modules (import/export) or use dynamic import: const { RedisPubSub } = await import('graphql-redis-subscriptions');
affects: >=2.0.0
deprecatedThe 'triggerTransform' option in PubSubRedisOptions is deprecated and will be removed in a future version.
fix
Avoid using triggerTransform. If you need event name transformation, implement custom logic in your resolvers.
affects: >=2.6.0
gotchaIf you instantiate RedisPubSub with both 'publisher' and 'subscriber' clients, ensure they are connected to the same database and endpoints. Misconfiguration can lead to subscription events not being received.
fix
Use a single connection URI or ensure both publishers and subscribers point to the same Redis instance/cluster.
affects: >=1.0.0
gotchaThe 'reviver' option only works with the default JSON serializer. If you provide a custom serializer, the reviver is ignored.
fix
Either use the default serializer and configure reviver, or implement full custom serialization in your serializer/deserializer.
affects: >=1.0.0
breakingIn version 2.0.0, the exported 'RedisPubSub' changed from a named export to a default export? (Verify). Wait, it's named export in both. Actually, check changelog for exact breaking changes.
fix
Ensure you use named import: import { RedisPubSub } from 'graphql-redis-subscriptions';
affects: ^2.0.0
Errors
Common errors & fixes
Error: Cannot find module 'graphql-redis-subscriptions'
Package not installed or peer dependency missing.
fix
npm install graphql-redis-subscriptions
npm install graphql-subscriptions
TypeError: RedisPubSub is not a constructor
Using CommonJS require instead of ES module import.
fix
Change to ES module import syntax: import { RedisPubSub } from 'graphql-redis-subscriptions';
UnhandledPromiseRejectionWarning: Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED
Redis server is not running or unreachable.
fix
Start Redis server (e.g., redis-server) or check connection configuration.
TypeError: pubsub.asyncIterator is not a function
Using an older version of the package that doesn't support asyncIterator or incorrect import.
fix
Upgrade to v2.x and ensure correct import: import { RedisPubSub } from 'graphql-redis-subscriptions';
Module '"graphql-redis-subscriptions"' has no exported member 'withFilter'.
Trying to import withFilter from the wrong package.
fix
Import withFilter from 'graphql-subscriptions': import { withFilter } from 'graphql-subscriptions';
Upgrade
Version history
2.7.0latest on npm
Audit
Dependencies
graphql-subscriptionsrequiredPeer dependency providing PubSubEngine and withFilter utilities
Agent activity
17 hits · last 30 days
node
16
OpenAI (training)
1
Resources