@dwwoelfel/pg-pubsub
TypeScript icon, indicating that this package has built-in type declarations

4.4.5-alpha.0 • Public • Published

@graphile/pg-pubsub

This PostGraphile server plugin provides a pubsub instance to schema plugins that uses PostgreSQL LISTEN/NOTIFY to provide realtime features.

Also adds support for @pgSubscriptions directive to easily define your own subscriptions using LISTEN/NOTIFY with makeExtendSchemaPlugin; and adds the --simple-subscriptions feature which, when enabled, adds a simple listen subscription field to your GraphQL API.

It's intended that you use this plugin as a provider of realtime data to other plugins which can use it to add subscription fields to your API.

For full documentation, see: https://www.graphile.org/postgraphile/subscriptions/

Usage

CLI:

yarn add @graphile/pg-pubsub

postgraphile \
  --plugins @graphile/pg-pubsub \
  --subscriptions \
  --simple-subscriptions \
  -c postgres:///mydb

Library:

const express = require("express");
const { postgraphile, makePluginHook } = require("postgraphile");
const { default: PgPubsub } = require("@graphile/pg-pubsub");

const pluginHook = makePluginHook([PgPubsub]);

const postgraphileOptions = {
  pluginHook,
  subscriptions: true, // Enable PostGraphile websocket capabilities
  simpleSubscriptions: true, // Add the `listen` subscription field
  websocketMiddlewares: [
    // Add whatever middlewares you need here, note that they should only
    // manipulate properties on req/res, they must not sent response data. e.g.:
    //
    //   require('express-session')(),
    //   require('passport').initialize(),
    //   require('passport').session(),
  ],
};

const app = express();
app.use(postgraphile(databaseUrl, "app_public", postgraphileOptions));
app.listen(parseInt(process.env.PORT, 10) || 3000);

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
4.4.5-alpha.00latest

Version History

VersionDownloads (Last 7 Days)Published
4.4.5-alpha.00
4.4.4-alpha.00
4.4.3-alpha.00

Package Sidebar

Install

npm i @dwwoelfel/pg-pubsub

Weekly Downloads

0

Version

4.4.5-alpha.0

License

MIT

Unpacked Size

33.9 kB

Total Files

12

Last publish

Collaborators

  • dww