graphql-pg-listen-subscriptions
v0.1.0
Published
This package implements the PubSubEngine Interface from the [graphql-subscriptions](https://github.com/apollographql/graphql-subscriptions) package.
Downloads
14
Readme
graphql-pg-listen-subscriptions
This package implements the PubSubEngine Interface from the graphql-subscriptions package.
Why
I've tried a package to implement pg pubsub and GraphQL subscriptions, but it no longer works.
Install
yarn add graphql-pg-listen-subscriptions
Getting Started
import { PgPubsub } from 'graphql-pg-listen-subscriptions'
export const pubsub = new PgPubsub('postgres://user:[email protected]/my-db')
Now, implement your Subscriptions type resolver, using the pubsub.asyncIterator
to map the event you need:
const SOMETHING_CHANGED_TOPIC = 'something_changed'
export const resolvers = {
Subscription: {
somethingChanged: {
subscribe: () => pubsub.asyncIterator(SOMETHING_CHANGED_TOPIC),
},
},
}