From 0f873b4996b01d12d9eb4d6a881d3ae201390b91 Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Mon, 18 Mar 2024 18:34:57 +0100 Subject: [PATCH 1/5] Update to @fastify/websocket v10 Signed-off-by: Matteo Collina --- index.d.ts | 4 ++-- lib/subscription.js | 10 ++++------ package.json | 2 +- test/subscription.js | 6 +++--- test/types/index.ts | 8 ++++---- 5 files changed, 14 insertions(+), 16 deletions(-) diff --git a/index.d.ts b/index.d.ts index 2610c694..9b6006dd 100644 --- a/index.d.ts +++ b/index.d.ts @@ -16,7 +16,7 @@ import { FormattedExecutionResult, ParseOptions, } from "graphql"; -import { SocketStream } from "@fastify/websocket" +import type { WebSocket } from "ws"; import { IncomingMessage, OutgoingHttpHeaders } from "http"; import { Readable } from "stream"; @@ -458,7 +458,7 @@ declare namespace mercurius { ) => void ) => void; context?: ( - connection: SocketStream, + sockeet: WebSocket, request: FastifyRequest ) => Record | Promise>; onConnect?: (data: { diff --git a/lib/subscription.js b/lib/subscription.js index c35cb590..4b8ebd38 100644 --- a/lib/subscription.js +++ b/lib/subscription.js @@ -7,9 +7,7 @@ const SubscriptionConnection = require('./subscription-connection') const { getProtocolByName } = require('./subscription-protocol') function createConnectionHandler ({ subscriber, fastify, onConnect, onDisconnect, entityResolversFactory, subscriptionContextFn, keepAlive, fullWsTransport, errorFormatter }) { - return async (connection, request) => { - const { socket } = connection - + return async (socket, request) => { if (socket.protocol === undefined || getProtocolByName(socket.protocol) === null) { request.log.warn('wrong websocket protocol') // Close the connection with an error code, ws v2 ensures that the @@ -35,7 +33,7 @@ function createConnectionHandler ({ subscriber, fastify, onConnect, onDisconnect let resolveContext if (subscriptionContextFn) { - resolveContext = () => subscriptionContextFn(connection, request) + resolveContext = () => subscriptionContextFn(socket, request) } const subscriptionConnection = new SubscriptionConnection(socket, { @@ -52,10 +50,10 @@ function createConnectionHandler ({ subscriber, fastify, onConnect, onDisconnect }) /* istanbul ignore next */ - connection.socket.on('error', () => { + socket.on('error', () => { subscriptionConnection.close() }) - connection.socket.on('close', () => { + socket.on('close', () => { subscriptionConnection.close() }) } diff --git a/package.json b/package.json index 52aca5dd..b419e59f 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,7 @@ "dependencies": { "@fastify/error": "^3.0.0", "@fastify/static": "^7.0.0", - "@fastify/websocket": "^8.0.0", + "@fastify/websocket": "^10.0.0", "fastify-plugin": "^4.2.0", "graphql-jit": "^0.8.0", "mqemitter": "^5.0.0", diff --git a/test/subscription.js b/test/subscription.js index 99dd7ccc..12d1c290 100644 --- a/test/subscription.js +++ b/test/subscription.js @@ -1968,9 +1968,9 @@ test('subscription server works with fastify websocket', t => { }) app.register(async function (app) { - app.get('/fastify-websocket', { websocket: true }, (connection, req) => { - connection.socket.on('message', message => { - connection.socket.send('hi from server') + app.get('/fastify-websocket', { websocket: true }, (socket, req) => { + socket.on('message', message => { + socket.send('hi from server') }) }) }) diff --git a/test/types/index.ts b/test/types/index.ts index 3c86cde9..b941f5ba 100644 --- a/test/types/index.ts +++ b/test/types/index.ts @@ -293,8 +293,8 @@ app.register(mercurius, { next(true) next(false) }, - context: (connection, request) => { - connection.socket + context: (socket, request) => { + socket.send('hello') request.headers return {} }, @@ -319,8 +319,8 @@ app.register(mercurius, { schema, resolvers, subscription: { - context: async (connection, request) => { - connection.socket + context: async (socket, request) => { + socket.send('hello') request.headers return {} }, From 97e121ad12a8f98032ef946c32d394814b7206cc Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Mon, 18 Mar 2024 18:57:35 +0100 Subject: [PATCH 2/5] drop node 16 Signed-off-by: Matteo Collina --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 68af50dc..4d8500f2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,7 +5,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - node-version: [16.x, 18.x, 20.x] + node-version: [18.x, 20.x] os: [ubuntu-latest, windows-latest, macOS-latest] steps: - uses: actions/checkout@v4 From e46bf33bc5775bdf7f6a3101bd3b776079ff1648 Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Mon, 18 Mar 2024 19:07:11 +0100 Subject: [PATCH 3/5] fixup Signed-off-by: Matteo Collina --- .github/workflows/ci.yml | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4d8500f2..68af50dc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,7 +5,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - node-version: [18.x, 20.x] + node-version: [16.x, 18.x, 20.x] os: [ubuntu-latest, windows-latest, macOS-latest] steps: - uses: actions/checkout@v4 diff --git a/package.json b/package.json index b419e59f..c5aae2ad 100644 --- a/package.json +++ b/package.json @@ -62,7 +62,7 @@ "@fastify/static": "^7.0.0", "@fastify/websocket": "^10.0.0", "fastify-plugin": "^4.2.0", - "graphql-jit": "^0.8.0", + "graphql-jit": "0.8.4", "mqemitter": "^5.0.0", "p-map": "^4.0.0", "readable-stream": "^4.0.0", From bf5341e91e50da342392fb145c06f539f58690e1 Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Mon, 18 Mar 2024 19:10:25 +0100 Subject: [PATCH 4/5] Update index.d.ts Co-authored-by: Jonny Green --- index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index 9b6006dd..55ded720 100644 --- a/index.d.ts +++ b/index.d.ts @@ -458,7 +458,7 @@ declare namespace mercurius { ) => void ) => void; context?: ( - sockeet: WebSocket, + socket: WebSocket, request: FastifyRequest ) => Record | Promise>; onConnect?: (data: { From 5513c6ec51f7cd7bcbb111139d3f6cb5db2e005b Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Tue, 19 Mar 2024 11:27:24 +0100 Subject: [PATCH 5/5] double test timeout Signed-off-by: Matteo Collina --- .taprc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.taprc b/.taprc index 6782c41f..611421b0 100644 --- a/.taprc +++ b/.taprc @@ -2,4 +2,4 @@ ts: false jsx: false flow: false coverage: true -timeout: 60 +timeout: 120