Skip to content

Commit

Permalink
build(deps): bump ws from 7.5.5 to 8.2.2 (#566)
Browse files Browse the repository at this point in the history
* build(deps): bump ws from 7.5.5 to 8.2.2

Bumps [ws](https://github.com/websockets/ws) from 7.5.5 to 8.2.2.
- [Release notes](https://github.com/websockets/ws/releases)
- [Commits](websockets/ws@7.5.5...8.2.2)

---
updated-dependencies:
- dependency-name: ws
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>

* fix: ws@8 fixes

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Simone Busoli <[email protected]>
  • Loading branch information
dependabot[bot] and simoneb authored Sep 23, 2021
1 parent 037cc1f commit 5df27f2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 27 deletions.
8 changes: 4 additions & 4 deletions lib/subscription-connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,20 @@ module.exports = class SubscriptionConnection {
}

async handleConnection () {
for await (const [message] of on(this.socket, 'message')) {
for await (const [message, isBinary] of on(this.socket, 'message')) {
try {
await this.handleMessage(message)
await this.handleMessage(message, isBinary)
} catch (err) {
this.fastify.log.error(err)
this.handleConnectionClose()
}
}
}

async handleMessage (message) {
async handleMessage (message, isBinary) {
let data
try {
data = sJSON.parse(message)
data = sJSON.parse(isBinary ? message : message.toString())
} catch (e) {
this.sendMessage(GQL_ERROR, null, 'Message must be a JSON string')
return
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"single-user-cache": "^0.5.0",
"tiny-lru": "^7.0.6",
"undici": "^4.1.0",
"ws": "^7.5.2"
"ws": "^8.2.2"
},
"tsd": {
"directory": "test/types"
Expand Down
47 changes: 25 additions & 22 deletions test/subscription-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ test('subscription client calls the publish method with the correct payload', (t
const port = server.address().port

server.on('connection', function connection (ws) {
ws.on('message', function incoming (message) {
const data = JSON.parse(message)
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: undefined, type: 'connection_ack' }))
} else if (data.type === 'start') {
Expand Down Expand Up @@ -46,8 +46,8 @@ test('subscription client calls the publish method with null after GQL_COMPLETE
const port = server.address().port

server.on('connection', function connection (ws) {
ws.on('message', function incoming (message) {
const data = JSON.parse(message)
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: undefined, type: 'connection_ack' }))
} else if (data.type === 'start') {
Expand Down Expand Up @@ -99,13 +99,16 @@ test('subscription client tries to reconnect when server closes', (t) => {
function connectionCallback () {
if (shouldCloseServer) {
server.close()
for (const ws of server.clients) {
ws.terminate()
}
shouldCloseServer = false
server = new WS.Server({ port }, () => {
createSubscription()
})
server.on('connection', function connection (ws) {
ws.on('message', (message) => {
const data = JSON.parse(message)
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: undefined, type: 'connection_ack' }))
} else if (data.type === 'start') {
Expand Down Expand Up @@ -150,8 +153,8 @@ test('subscription client multiple subscriptions is handled by one operation', t
const port = server.address().port

server.on('connection', function connection (ws) {
ws.on('message', function incoming (message) {
const data = JSON.parse(message)
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: undefined, type: 'connection_ack' }))
} else if (data.type === 'start') {
Expand Down Expand Up @@ -182,8 +185,8 @@ test('subscription client multiple subscriptions unsubscribe removes only one su
const port = server.address().port

server.on('connection', function connection (ws) {
ws.on('message', function incoming (message) {
const data = JSON.parse(message)
ws.on('message', function incoming (message, isBinary) {
const data = JSON.parse(isBinary ? message : message.toString())
if (data.type === 'stop') {
ws.send(JSON.stringify({ id: '1', type: 'complete' }))
}
Expand Down Expand Up @@ -220,8 +223,8 @@ test('subscription client closes the connection after GQL_CONNECTION_ERROR type
const port = server.address().port

server.on('connection', function connection (ws) {
ws.on('message', function incoming (message) {
const data = JSON.parse(message)
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_error' }))
}
Expand All @@ -248,8 +251,8 @@ test('subscription client connectionInitPayload is correctly passed', (t) => {
const port = server.address().port

server.on('connection', function connection (ws) {
ws.on('message', function incoming (message) {
const data = JSON.parse(message)
ws.on('message', function incoming (message, isBinary) {
const data = JSON.parse(isBinary ? message : message.toString())
if (data.type === 'connection_init') {
t.same(data.payload, connectionInitPayload)
client.close()
Expand Down Expand Up @@ -294,8 +297,8 @@ test('subscription client sending empty object payload on connection init', (t)
const port = server.address().port

server.on('connection', function connection (ws) {
ws.on('message', function incoming (message) {
const data = JSON.parse(message)
ws.on('message', function incoming (message, isBinary) {
const data = JSON.parse(isBinary ? message : message.toString())
if (data.type === 'connection_init') {
t.same(data.payload, {})
ws.send(JSON.stringify({ id: '1', type: 'complete' }))
Expand Down Expand Up @@ -329,8 +332,8 @@ test('subscription client not throwing error on GQL_CONNECTION_KEEP_ALIVE type p
})

server.on('connection', function connection (ws) {
ws.on('message', function incoming (message) {
const data = JSON.parse(message)
ws.on('message', function incoming (message, isBinary) {
const data = JSON.parse(isBinary ? message : message.toString())
if (data.type === 'start') {
ws.send(JSON.stringify({ id: '1', type: 'complete' }))
}
Expand Down Expand Up @@ -369,8 +372,8 @@ test('subscription client should throw on createSubscription if connection is no
const port = server.address().port

server.on('connection', function connection (ws) {
ws.on('message', function incoming (message) {
const data = JSON.parse(message)
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: undefined, type: 'connection_error' }))
}
Expand Down Expand Up @@ -400,8 +403,8 @@ test('subscription client should pass the error payload to failedConnectionCallb
const errorPayload = { message: 'error' }

server.on('connection', function connection (ws) {
ws.on('message', function incoming (message) {
const data = JSON.parse(message)
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: undefined, type: 'connection_error', payload: errorPayload }))
}
Expand Down

0 comments on commit 5df27f2

Please sign in to comment.