-
-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(subscriptions): pg-pubsub module (#400)
- Loading branch information
Showing
20 changed files
with
2,951 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# The MIT License (MIT) | ||
|
||
Copyright © `2019` Benjie Gillam | ||
|
||
Permission is hereby granted, free of charge, to any person | ||
obtaining a copy of this software and associated documentation | ||
files (the “Software”), to deal in the Software without | ||
restriction, including without limitation the rights to use, | ||
copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the | ||
Software is furnished to do so, subject to the following | ||
conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
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 IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# @graphile/pg-pubsub | ||
|
||
This PostGraphile [server | ||
plugin](https://www.graphile.org/postgraphile/plugins/) provides a `pubsub` | ||
instance to [schema | ||
plugins](https://www.graphile.org/postgraphile/extending/) 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: | ||
|
||
```js | ||
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); | ||
``` |
Oops, something went wrong.