Graphql Postgres Subscriptions
GraphQL PubSubEngine implementation using Postgres NOTIFY
, LISTEN
, and UNLISTEN
.
Quickstart
This package has peer dependencies with brianc/node-postgres (pg
) and graphql/graphql-js (graphql
).
Install the package:
yarn add @udia/graphql-postgres-subscriptions
npm install @udia/graphql-postgres-subscriptions --save
Sample PostgresPubSub Usage
; // create your postgres client and connect to the databaseconst pgClient = ...pgClientOptions ;await pgClient; // Instantiate your PubSub engineconst pubSub = pgClient;
Optional, pass in JSON Reviver
// Optional JSON reviver functionconst dateReviver = { const isISO8601Z = /^--T::Z$/; if typeof value === "string" && isISO8601Z const tempDateNumber = Date; if ! return tempDateNumber; return value;};const pubSub = pgClient dateReviver;pubSub; // will notify with Date instead of string
Testing/Development
This project performs integration tests with a postgres database. This can be run with Docker by executing: docker-compose build && docker-compose run test
or this can be run with a standalone postgres database by configuring your environment variables in testHelper.ts.
About
- Written in TypeScript, static type guarantees
- Inspired by GraphQLCollege/graphql-postgres-subscriptions
- Removed dependency on emilbayes/pg-ipc due to JSON reviving functionality
- Full implementation example and app demo at udia-software/udia
License
This is free software, licensed under MIT License.
The MIT License Copyright (c) 2018 Udia Software Incorporated Permission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included inall copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS INTHE SOFTWARE.