Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fastify websockets breaking change #553

Open
bhamon opened this issue Apr 15, 2024 · 5 comments
Open

fastify websockets breaking change #553

bhamon opened this issue Apr 15, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@bhamon
Copy link

bhamon commented Apr 15, 2024

A breaking change has been added to @fastify/websockets@10 (fastify/fastify-websocket#289). It breaks the fastify integration.

The wsHandler first parameter type is now WebSocket rather than a NodeJS stream.
To create a stream from it an explicit call to ws.createWebSocketStream(socket) is required.

A dirty patch to make it work with the new version:

    wsHandler: (socket, req) => {
      const connection = ws.createWebSocketStream(socket);
      connection.socket = socket;
      return wsHandler.call(_app, connection, req);
    }

I'm concerned about how to properly propagate errors for the newly created stream.

@enisdenjo enisdenjo added the bug Something isn't working label Apr 19, 2024
@enisdenjo
Copy link
Owner

Hey hey, thanks for reporting this! We could detect the socket location during runtime, but the hard part is actually the TS types...

IDK how to approach this. Maybe release a new major version of graphql-ws that has no support for the legacy fastify? What do you think?

@bhamon
Copy link
Author

bhamon commented Apr 24, 2024

It may be better yes, a runtime check doesn't feel right.
I'm a bit surprised by their change: even if under a new major version it is only referenced as a "fix" on the release. But the correction breaks the interface with much more to do on the user side.

@charsleysa
Copy link

@enisdenjo would you be open to having v10 support behind a config option? e.g. rawWebSocket and when it's set to true the first parameter of the handler is treated as the websocket instead of a connection object.

When the config option is used, the extra data can switch from providing connection to providing socket.

This would keep functionality the same for v9 and below while allowing v10 and above to be supported with only a minor release as these changes are technically not a breaking change due to having to explicitly opt-in.

Example usage for v10:

fastify.get('/graphql', { websocket: true }, makeHandler({ schema, rawWebSocket: true }));

@enisdenjo
Copy link
Owner

@charsleysa the issue is not only in runtime, but also with TS types - they dont work when using the latest fastify websockets.

@CarsonF
Copy link

CarsonF commented Nov 5, 2024

Just hit this. Rock and hard place. A new major doesn't seem appropriate - unless coming with other things. New sub folder would work, but is a maintenance burden. Separately library allows for appropriate major bumps but is a maintenance burden - at least setup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants