@originlabs/graphql-postgres-subscriptions-retry
Advanced tools
Comparing version 2.1.0 to 2.1.1
{ | ||
"name": "@originlabs/graphql-postgres-subscriptions-retry", | ||
"version": "2.1.0", | ||
"version": "2.1.1", | ||
"main": "index.js", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -33,7 +33,18 @@ const { PubSub } = require("graphql-subscriptions"); | ||
async connect() { | ||
await this.pgListen.connect(); | ||
await Promise.all(this.triggers.map((eventName) => { | ||
return this.pgListen.listenTo(eventName); | ||
})); | ||
this.connected = true; | ||
console.log('calling connect') | ||
// 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 | ||
this.pgListen.events.on('connected', async () => { | ||
await Promise.all(this.triggers.map((eventName) => { | ||
return this.pgListen.listenTo(eventName); | ||
})); | ||
this.connected = true; | ||
}); | ||
try { | ||
await this.pgListen.connect(); | ||
} catch (e) { | ||
if (!e.message.includes('ECONNREFUSED')) throw e; | ||
} | ||
} | ||
@@ -71,3 +82,3 @@ | ||
if (!this.connected) { | ||
console.log('attempted to publish an event via pubsub, but client is not yet connected') | ||
console.log('attempted to unsubscribe to events via pubsub, but client is not yet connected') | ||
} | ||
@@ -74,0 +85,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25955
12
330