meshql-pubsub (@meshql/pubsub)
Pub/sub backends for MeshQL real-time subscriptions (v0.9.0).
Install
Section titled “Install”npm install meshql-pubsub# ornpx jsr add @meshql/pubsubPublished on npm as meshql-pubsub and JSR as @meshql/pubsub.
Backends
Section titled “Backends”| Backend | Import | Use case |
|---|---|---|
| In-memory | @meshql/pubsub |
Dev, single-node |
| Redis | @meshql/pubsub/redis |
Production, multi-node |
| Postgres | @meshql/pubsub/postgres |
Zero extra infra (LISTEN/NOTIFY) |
Example (in-memory)
Section titled “Example (in-memory)”import { InMemoryPubSubStore, entityRecordChannel, notifyEntityUpdate,} from "@meshql/pubsub";
const pubsub = new InMemoryPubSubStore();
pubsub.subscribe(entityRecordChannel("post", 1), (message) => { console.log("update", message.payload);});
notifyEntityUpdate(pubsub, "post", 1);import { createRedisPubSubStore } from "@meshql/pubsub/redis";
const pubsub = createRedisPubSubStore({ url: process.env.REDIS_URL!,});Postgres
Section titled “Postgres”import { Pool } from "pg";import { createPostgresPubSubStore } from "@meshql/pubsub/postgres";
const pool = new Pool({ connectionString: process.env.DATABASE_URL });const pubsub = createPostgresPubSubStore({ pool });Pairs with @meshql/sse for browser subscriptions. See From GraphQL — Subscriptions.