Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@originlabs/graphql-postgres-subscriptions-retry

Package Overview
Dependencies
Maintainers
14
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@originlabs/graphql-postgres-subscriptions-retry - npm Package Compare versions

Comparing version 3.0.0 to 3.1.0

1

index.d.ts

@@ -12,2 +12,3 @@ import { PubSub } from "graphql-subscriptions";

close(): Promise<void>;
asyncIteratorPromised<T>(triggers: string | string[]): Promise<AsyncIterator<T>>;
}

2

package.json
{
"name": "@originlabs/graphql-postgres-subscriptions-retry",
"version": "3.0.0",
"version": "3.1.0",
"main": "index.js",

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -50,9 +50,3 @@ const { PubSub } = require("graphql-subscriptions");

this.pgListen.events.once('connected', () => {
// confusingly, `pgListen.connect()` will reject if the first connection attempt fails
// but then it will retry and emit a `connected` event if it later connects
// see https://github.com/andywer/pg-listen/issues/32
// so we put logic on the `connected` event
Promise.all(this.triggers.map((eventName) => {
return this.pgListen.listenTo(eventName);
})).then(resolve, reject);
this.initTopics(this.triggers).then(resolve, reject);
});

@@ -76,2 +70,12 @@ });

initTopics(triggers) {
// confusingly, `pgListen.connect()` will reject if the first connection attempt fails
// but then it will retry and emit a `connected` event if it later connects
// see https://github.com/andywer/pg-listen/issues/32
// so we put logic on the `connected` event
return Promise.all(triggers.map((eventName) => {
return this.pgListen.listenTo(eventName);
}));
}
async publish(triggerName, payload) {

@@ -115,3 +119,14 @@ if (!this.connected) {

}
/*
* The difference between this function and asyncIterator is that the
* topics can still be empty.
*/
async asyncIteratorPromised(triggers) {
await this.initTopics(Array.isArray(triggers) ? triggers : [triggers] );
return eventEmitterAsyncIterator(
this.pgListen,
triggers,
this.commonMessageHandler
);
}
asyncIterator(triggers) {

@@ -118,0 +133,0 @@ return eventEmitterAsyncIterator(

@@ -186,2 +186,17 @@ // Adapted from https://github.com/apollographql/graphql-subscriptions/blob/master/src/test/tests.ts

});
test("AsyncIteratorPromised should work without having topics on constructor", async (done) => {
const eventName = "test2";
const ps = new PostgresPubSub();
await ps.connect();
const iterator = await ps.asyncIteratorPromised(["test", "test2"]);
const spy = jest.fn();
iterator.next().then(() => {
spy();
expect(spy).toHaveBeenCalled();
done();
}).catch(done);
ps.publish(eventName, { test: true });
});
});

@@ -46,3 +46,3 @@ Forked from GraphQLCollege/graphql-postgres-subscriptions, where we replaced `pg-ipc` with `pg-listen` so that the database connection with retry and reconnect.

**Important**: If you want to use the asyncIterator (which is used by graphql subscriptions) you need to pass them as an array of topics on the options parameter. This should be an array of all the topics/channels you want to subscribe to. The reason we need to know these ahead of time, is because otherwise it would be an async operation to add them or create the async iterator.
**Important**: If you want to use the asyncIterator (which is used by graphql subscriptions) you need to pass them as an array of topics on the options parameter. This should be an array of all the topics/channels you want to subscribe to. The reason we need to know these ahead of time, is because otherwise it would be an async operation to add them or create the async iterator or use the `asyncIteratorPromised` function instead.

@@ -49,0 +49,0 @@ ```js

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc