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

fix: make payload:null handling in connection_init consistent between protocols #3744

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ async def handle_connection_init(self, message: ConnectionInitMessage) -> None:
self.connection_init_timeout_task.cancel()

payload = message.get("payload", {})

if payload is None:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not breaking for graphql_transport_ws, because it was required to be dict.

It's possible to make other way around and allow null in graphql_transport_ws, like in graphql_ws.
But since it's "recommended" protocol I decided to change graphql_ws and not the other way around.

payload = {}
if not isinstance(payload, dict):
await self.websocket.close(
code=4400, reason="Invalid connection init payload"
Expand Down
4 changes: 3 additions & 1 deletion strawberry/subscriptions/protocols/graphql_ws/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ async def handle_message(

async def handle_connection_init(self, message: ConnectionInitMessage) -> None:
payload = message.get("payload")
if payload is not None and not isinstance(payload, dict):
if payload is None:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For graphql_ws before this PR connection_params could be null, if payload is null.
So this may be a slightly breaking change.

payload = {}
if not isinstance(payload, dict):
await self.send_message({"type": "connection_error"})
await self.websocket.close(code=1000, reason="")
return
Expand Down
Loading