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

mercurius

Package Overview
Dependencies
Maintainers
2
Versions
117
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mercurius - npm Package Compare versions

Comparing version 8.7.0 to 8.8.0

1

docs/api/options.md

@@ -76,2 +76,3 @@ # mercurius

- `service.maxHeaderSize`: The maximum length of request headers in bytes. (Default: `16384` - 16KiB)
- `service.keepAlive`: The amount of time pass between the keep-alive messages sent from the gateway to the service, if `undefined`, no keep-alive messages will be sent. (Default: `undefined`)
- `service.wsUrl`: The url of the websocket endpoint

@@ -78,0 +79,0 @@ - `service.wsConnectionParams`: `Function` or `Object`

3

examples/gateway-subscription.js

@@ -273,3 +273,4 @@ 'use strict'

protocols: ['graphql-transport-ws'] // optional, if not set, will use the default protocol (graphql-ws)
}
},
keepAlive: 3000
}]

@@ -276,0 +277,0 @@ }

@@ -383,3 +383,3 @@ import {

name: string;
url: string;
url: string | string[];
schema?: string;

@@ -386,0 +386,0 @@ wsUrl?: string;

@@ -55,3 +55,4 @@ 'use strict'

let opts = {
serviceName: service.name
serviceName: service.name,
keepAlive: service.keepAlive
}

@@ -58,0 +59,0 @@ if (typeof service.wsConnectionParams === 'object') {

@@ -30,3 +30,4 @@ 'use strict'

connectionInitPayload,
rewriteConnectionInitPayload
rewriteConnectionInitPayload,
keepAlive
} = config

@@ -43,2 +44,3 @@

this.rewriteConnectionInitPayload = rewriteConnectionInitPayload
this.keepAlive = keepAlive

@@ -52,2 +54,3 @@ if (Array.isArray(protocols) && protocols.length > 0) {

this.protocolMessageTypes = getProtocolByName(this.protocols[0])
this.keepAliveInterval = undefined

@@ -71,2 +74,5 @@ if (this.protocolMessageTypes === null) {

this.sendMessage(null, this.protocolMessageTypes.GQL_CONNECTION_INIT, payload)
if (this.keepAlive) {
this.startKeepAliveInterval()
}
} catch (err) {

@@ -100,2 +106,6 @@ this.close(this.tryReconnect, false)

if (this.keepAlive && this.keepAliveTimeoutId) {
this.stopKeepAliveInterval()
}
this.socket.close()

@@ -300,4 +310,15 @@ this.socket = null

}
startKeepAliveInterval () {
this.keepAliveTimeoutId = setInterval(() => {
this.sendMessage(null, this.protocolMessageTypes.GQL_CONNECTION_KEEP_ALIVE)
}, this.keepAlive)
this.keepAliveTimeoutId.unref()
}
stopKeepAliveInterval () {
clearTimeout(this.keepAliveTimeoutId)
}
}
module.exports = SubscriptionClient
{
"name": "mercurius",
"version": "8.7.0",
"version": "8.8.0",
"description": "Fastify GraphQL adapter with gateway and subscription support",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -370,2 +370,30 @@ 'use strict'

test('subscription client sends GQL_CONNECTION_KEEP_ALIVE when the keep alive option is active', (t) => {
const server = new WS.Server({ port: 0 })
const port = server.address().port
const clock = FakeTimers.createClock()
server.on('connection', function connection (ws) {
ws.on('message', function incoming (message, isBinary) {
const data = JSON.parse(isBinary ? message : message.toString())
if (data.type === 'connection_init') {
ws.send(JSON.stringify({ id: '1', type: 'connection_ack' }))
} else if (data.type === 'start') {
ws.send(JSON.stringify({ id: '2', type: 'complete' }))
} else if (data.type === 'ka') {
client.close()
server.close()
t.end()
}
})
})
const client = new SubscriptionClient(`ws://localhost:${port}`, {
reconnect: false,
serviceName: 'test-service',
keepAlive: 1000
})
clock.tick(1000)
})
test('subscription client not throwing error on GQL_CONNECTION_KEEP_ALIVE type payload received', (t) => {

@@ -372,0 +400,0 @@ const clock = FakeTimers.createClock()

@@ -326,2 +326,18 @@ import { expectAssignable, expectError } from 'tsd'

// Gateway mode with load balanced services
gateway.register(mercurius, {
gateway: {
services: [
{
name: 'user',
url: ['http://localhost:4001/graphql', 'http://localhost:4002/graphql']
},
{
name: 'post',
url: 'http://localhost:4003/graphql'
}
]
}
})
// Executable schema

@@ -328,0 +344,0 @@

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