{"id":42813,"library":"graphql-postgres-subscriptions","title":"graphql-postgres-subscriptions","description":"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.","status":"maintenance","version":"1.0.5","language":"javascript","source_language":"en","source_url":"https://github.com/GraphQLCollege/graphql-postgres-subscriptions","tags":["javascript"],"install":[{"cmd":"npm install graphql-postgres-subscriptions","lang":"bash","label":"npm"},{"cmd":"yarn add graphql-postgres-subscriptions","lang":"bash","label":"yarn"},{"cmd":"pnpm add graphql-postgres-subscriptions","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Provides PubSubEngine interface and AsyncIterator that this library implements","package":"graphql-subscriptions","optional":false},{"reason":"Peer dependency for GraphQL subscriptions types","package":"graphql","optional":true},{"reason":"Used to connect to PostgreSQL and listen for NOTIFY messages","package":"pg","optional":true}],"imports":[{"note":"ESM default export is not available; named import is correct. CommonJS users need const { PostgresPubSub } = require('graphql-postgres-subscriptions')","wrong":"const PostgresPubSub = require('graphql-postgres-subscriptions')","symbol":"PostgresPubSub","correct":"import { PostgresPubSub } from 'graphql-postgres-subscriptions'"},{"note":"Do not use .default; package does not export default.","wrong":"const PostgresPubSub = require('graphql-postgres-subscriptions').default","symbol":"PostgresPubSub","correct":"const { PostgresPubSub } = require('graphql-postgres-subscriptions')"},{"note":"First argument must be an options object, not a client directly. Second argument is commonMessageHandler inside options object.","wrong":"const pubsub = new PostgresPubSub(client, commonMessageHandler)","symbol":"PostgresPubSub (with connection options)","correct":"const pubsub = new PostgresPubSub({ client, commonMessageHandler })"}],"quickstart":{"code":"import { PostgresPubSub } from 'graphql-postgres-subscriptions';\nimport { Client } from 'pg';\n\nconst client = new Client();\nawait client.connect();\nconst pubsub = new PostgresPubSub({ client });\n\n// Publish and subscribe example\nawait pubsub.publish('POST_CREATED', { id: 1, title: 'Hello' });\nconst subscription = await pubsub.subscribe('POST_CREATED', (payload) => {\n  console.log('Received:', payload);\n});\n// Later: await subscription.unsubscribe();","lang":"typescript","description":"Creates a PostgresPubSub instance with a pg.Client, then publishes and subscribes to events using LISTEN/NOTIFY."},"warnings":[{"fix":"Create a dedicated pg.Client (not from Pool) and pass that to PostgresPubSub.","message":"Do not pass a client from pg.Pool to PostgresPubSub. Pool clients are shared and may miss NOTIFY messages.","severity":"breaking","affected_versions":"all"},{"fix":"Keep published payloads under 8000 bytes, or use a separate mechanism for large payloads.","message":"PostgresPubSub uses LISTEN/NOTIFY which has a payload limit of 8000 bytes. Larger payloads throw an error.","severity":"gotcha","affected_versions":"all"},{"fix":"Always await client.connect() before creating PostgresPubSub.","message":"Client must be connected before creating PostgresPubSub; otherwise subscribe will fail.","severity":"gotcha","affected_versions":"all"},{"fix":"Upgrade to graphql-subscriptions v2 and check for API changes.","message":"Package uses deprecated graphql-subscriptions API (e.g., PubSubEngine). Consider migrating to graphql-subscriptions v2 or newer.","severity":"deprecated","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'0.10.5':71 '1.0.5':20 '14.0.0':73 '2019':26 '6':75 'activ':22 'addit':51 'apollo':13 'asynciter':40 'beyond':53 'compar':42 'depend':68 'graphql':2,5,16,45,69 'graphql-postgres-subscript':1 'graphql-redis-subscript':44 'graphql-subscript':15 'horizont':64 'implement':7,37 'infrastructur':52 'instanc':31 'interfac':41 'javascript':77 'last':24 'leverag':33 'limit':55 'listen/notify':11 'maintain':23 'manag':30 'mechan':36 'multipl':28 'nativ':66 'node':59,74 'peer':67 'postgr':3,34,54,60 'postgresql':9 'pub/sub':35 'pubsubengin':38 'redi':46 'releas':25 'requir':76 'scale':65 'singl':58 'single-nod':57 'stabl':18 'subscript':4,6,17,29,47 'support':27,63,70 'use':8,49 'version':19","created_at":"2026-06-05T16:56:47.209258+00:00","updated_at":"2026-06-05T16:56:47.209258+00:00","problems":[{"fix":"Reduce payload size below 8000 bytes, or split message into multiple publishes.","cause":"Postgres LISTEN/NOTIFY payload limit is 8000 bytes. Published message exceeds limit.","error":"error: payload string too long"},{"fix":"Create a new Client instance and connect it: const client = new Client(); await client.connect();","cause":"Passed a client from pg.Pool instead of a dedicated pg.Client.","error":"TypeError: client is not a connection"},{"fix":"Install graphql-subscriptions: npm install graphql-subscriptions","cause":"Missing peer dependency graphql-subscriptions.","error":"Module not found: Can't resolve 'graphql-subscriptions'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/GraphQLCollege/graphql-postgres-subscriptions#readme","github":"https://github.com/GraphQLCollege/graphql-postgres-subscriptions","docs":null,"changelog":null,"pypi":null,"npm":"graphql-postgres-subscriptions","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database","messaging"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-05","next_check":"2026-09-03","install_tag":null}}