Close socket if handle_init returns an :error#18
Open
maxsalven wants to merge 6 commits into
Open
Conversation
|
@maxsalven this is a good fix. Thank you! Just bumping in the hopes it gets picked up. Might also be good to be able to pass a custom error code? vs just defaulting to 4403 |
Contributor
|
+1 for this fix. The graphql errors in the payload array is interesting. Since this is just protocol negotiation and no graphql has been invoked yet it does not make much sense to return graphql errors. If an empty array is passed ( |
|
This would be a great improvement. I was mostly surprised to see the connection was left open when returning a |
bolek
added a commit
to tolemi-inc/absinthe_graphql_ws
that referenced
this pull request
Mar 7, 2025
Waiting for this or similar to get merged absinthe-graphql#18
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The current docs suggest returning
{:error, %{}, socket}fromhandle_init.https://github.com/geometerio/absinthe_graphql_ws/blob/b98d3deb15febd856725f69b7a54c38e3b67ab3b/lib/absinthe/graphql_ws/socket.ex#L176-L178
This ends up creating an invalid error message:
https://github.com/geometerio/absinthe_graphql_ws/blob/b98d3deb15febd856725f69b7a54c38e3b67ab3b/lib/absinthe/graphql_ws/transport.ex#L129-L130
https://github.com/geometerio/absinthe_graphql_ws/blob/b98d3deb15febd856725f69b7a54c38e3b67ab3b/lib/absinthe/graphql_ws/message/error.ex#L9-L11
The error message will be
type: "error", id: %{}, payload: %{}, when the spec expects the id to be a string, and payload to be an array of graphql errors. The client currently throws an error when it sees this invalid message.Even if you fix this, the spec does not expect an error message in response to
connection_init, and the official client will also throw an error.The reference implementation closes the connection with code 4403 if handling
connection_initfails:https://github.com/enisdenjo/graphql-ws/blob/799cfc7bbe0f6d1a5c90b4880f02c58c5c3a06d4/src/server.ts#L612-L614
https://github.com/enisdenjo/graphql-ws/blob/799cfc7bbe0f6d1a5c90b4880f02c58c5c3a06d4/src/__tests__/server.ts#L437-L458
This is critical for token refresh based workflows (e.g. the token you included in
connectionParamson the client is stale, and you need to check for 4403 Forbidden to refresh it).This PR matches the spec. I'm not sure how to adapt the tests to check for this, suggestions welcome!