Registry / database / graphql-postgres-subscriptions

graphql-postgres-subscriptions

JSON →
library1.0.5jsnpmunverified

GraphQL subscriptions implementation using PostgreSQL's LISTEN/NOTIFY and apollo's graphql-subscriptions. Stable version 1.0.5, not actively maintained (last release 2019). Supports multiple subscription manager instances by leveraging Postgres pub/sub mechanism. Implements PubSubEngine and AsyncIterator interfaces. Compared to graphql-redis-subscriptions, it uses no additional infrastructure beyond Postgres. Limited to single-node Postgres; does not support horizontal scaling natively. Peer dependency graphql supports ^0.10.5 to ^14.0.0. Node >=6 required.

npm install graphql-postgres-subscriptions
INSTALL
IMPORT
SIG · GRAPHQL-POSTGRES-S
G
graphql-postgres-subscriptions
databasejavascriptv1.0.5
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.

PostgresPubSub
import { PostgresPubSub } from 'graphql-postgres-subscriptions'
const PostgresPubSub = require('graphql-postgres-subscriptions')
ESM default export is not available; named import is correct. CommonJS users need const { PostgresPubSub } = require('graphql-postgres-subscriptions')
PostgresPubSub
const { PostgresPubSub } = require('graphql-postgres-subscriptions')
const PostgresPubSub = require('graphql-postgres-subscriptions').default
Do not use .default; package does not export default.
PostgresPubSub (with connection options)
const pubsub = new PostgresPubSub({ client, commonMessageHandler })
const pubsub = new PostgresPubSub(client, commonMessageHandler)
First argument must be an options object, not a client directly. Second argument is commonMessageHandler inside options object.

Creates a PostgresPubSub instance with a pg.Client, then publishes and subscribes to events using LISTEN/NOTIFY.

import { PostgresPubSub } from 'graphql-postgres-subscriptions'; import { Client } from 'pg'; const client = new Client(); await client.connect(); const pubsub = new PostgresPubSub({ client }); // Publish and subscribe example await pubsub.publish('POST_CREATED', { id: 1, title: 'Hello' }); const subscription = await pubsub.subscribe('POST_CREATED', (payload) => { console.log('Received:', payload); }); // Later: await subscription.unsubscribe();
Debug
Known issues
breakingDo not pass a client from pg.Pool to PostgresPubSub. Pool clients are shared and may miss NOTIFY messages.
fix
Create a dedicated pg.Client (not from Pool) and pass that to PostgresPubSub.
affects: all
gotchaPostgresPubSub uses LISTEN/NOTIFY which has a payload limit of 8000 bytes. Larger payloads throw an error.
fix
Keep published payloads under 8000 bytes, or use a separate mechanism for large payloads.
affects: all
gotchaClient must be connected before creating PostgresPubSub; otherwise subscribe will fail.
fix
Always await client.connect() before creating PostgresPubSub.
affects: all
deprecatedPackage uses deprecated graphql-subscriptions API (e.g., PubSubEngine). Consider migrating to graphql-subscriptions v2 or newer.
fix
Upgrade to graphql-subscriptions v2 and check for API changes.
affects: >=1.0.0
Errors
Common errors & fixes
error: payload string too long
Postgres LISTEN/NOTIFY payload limit is 8000 bytes. Published message exceeds limit.
fix
Reduce payload size below 8000 bytes, or split message into multiple publishes.
TypeError: client is not a connection
Passed a client from pg.Pool instead of a dedicated pg.Client.
fix
Create a new Client instance and connect it: const client = new Client(); await client.connect();
Module not found: Can't resolve 'graphql-subscriptions'
Missing peer dependency graphql-subscriptions.
fix
Install graphql-subscriptions: npm install graphql-subscriptions
Upgrade
Version history
1.0.5latest on npm
Audit
Dependencies
graphql-subscriptionsrequiredProvides PubSubEngine interface and AsyncIterator that this library implements
graphqloptionalPeer dependency for GraphQL subscriptions types
pgoptionalUsed to connect to PostgreSQL and listen for NOTIFY messages
Agent activity
19 hits · last 30 days
node
16
OpenAI (training)
2
Resources
graphql-postgres-subscriptions — npm install graphql-postgres-subscriptions · libregistry