![Create React App Officially Deprecated Amid React 19 Compatibility Issues](https://cdn.sanity.io/images/cgdhsj6q/production/04fa08cf844d798abc0e1a6391c129363cc7e2ab-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
@ethicdevs/graphql-postgres-subscriptions
Advanced tools
[![Build Status](https://travis-ci.org/GraphQLCollege/graphql-postgres-subscriptions.svg?branch=master)](https://travis-ci.org/GraphQLCollege/graphql-postgres-subscriptions)
A graphql subscriptions implementation using postgres and apollo's graphql-subscriptions.
This package implements the PubSubEngine Interface from the graphql-subscriptions package and also the new AsyncIterator interface. It allows you to connect your subscriptions manger to a postgres based Pub Sub mechanism to support multiple subscription manager instances.
FORK NOTE: Forked to add a $disconnect
method so its possible to cleanly close the client/pg-ipc instances and do not keep open handles around (jest).
yarn add @ethicdevs/graphql-postgres-subscriptions
or npm install @ethicdevs/graphql-postgres-subscriptions --save
Example app: https://github.com/GraphQLCollege/apollo-subscriptions-example
First of all, follow the instructions in graphql-subscriptions to add subscriptions to your app.
Afterwards replace PubSub
with PostgresPubSub
:
// Before
import { PubSub } from "graphql-subscriptions";
export const pubsub = new PubSub();
// After
import { PostgresPubSub } from "@ethicdevs/graphql-postgres-subscriptions";
export const pubsub = new PostgresPubSub();
This library uses node-postgres
to connect to PostgreSQL. If you want to customize connection options, please refer to their connection docs.
You have three options:
If you don's send any argument to new PostgresPubSub()
, we'll create a postgres
client with no arguments.
You can also pass node-postgres connection options to PostgresPubSub
.
You can instantiate your own client
and pass it to PostgresPubSub
. Like this:
import { PostgresPubSub } from "@ethicdevs/graphql-postgres-subscriptions";
import { Client } from "pg";
const client = new Client();
await client.connect();
const pubsub = new PostgresPubSub({ client });
Important: Don't pass clients from pg
's Pool
to PostgresPubSub
. As node-postgres creator states in this StackOverflow answer, the client needs to be around and not shared so pg can properly handle NOTIFY
messages (which this library uses under the hood)
The second argument to new PostgresPubSub()
is the commonMessageHandler
. The common message handler gets called with the received message from PostgreSQL.
You can transform the message before it is passed to the individual filter/resolver methods of the subscribers.
This way it is for example possible to inject one instance of a DataLoader which can be used in all filter/resolver methods.
const getDataLoader = () => new DataLoader(...)
const commonMessageHandler = ({attributes: {id}, data}) => ({id, dataLoader: getDataLoader()})
const pubsub = new PostgresPubSub({ client, commonMessageHandler });
export const resolvers = {
Subscription: {
somethingChanged: {
resolve: ({ id, dataLoader }) => dataLoader.load(id),
},
},
};
PostgresPubSub
instances emit a special event called "error"
. This event's payload is an instance of Javascript's Error
. You can get the error's text using error.message
.
const ps = new PostgresPubSub({ client });
ps.subscribe("error", (err) => {
console.log(err.message); // -> "payload string too long"
}).then(() => ps.publish("a", "a".repeat(9000)));
For example you can log all error messages (including stack traces and friends) using something like this:
ps.subscribe("error", console.error);
This will cancel all the subscriptions, close the pg-ipc channels then close the pg client connection properly.
ps.$disconnect();
This project has an integration test suite that uses jest
to make sure everything works correctly.
We use Docker to spin up a PostgreSQL instance before running the tests. To run them, type the following commands:
docker-compose build
docker-compose run test
FAQs
[![Build Status](https://travis-ci.org/GraphQLCollege/graphql-postgres-subscriptions.svg?branch=master)](https://travis-ci.org/GraphQLCollege/graphql-postgres-subscriptions)
The npm package @ethicdevs/graphql-postgres-subscriptions receives a total of 1 weekly downloads. As such, @ethicdevs/graphql-postgres-subscriptions popularity was classified as not popular.
We found that @ethicdevs/graphql-postgres-subscriptions demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.