v0.344.0 hardens the legacy graphql-ws protocol and the WebSocket origin check
graphql-ws connections must send connection_init in time
connection_init_wait_timeout now applies to the legacy graphql-ws protocol
as well as graphql-transport-ws . A graphql-ws connection that doesnβt send
connection_init within the timeout, one minute by default, is closed with code
4408 βConnection initialisation timeoutβ. Before, such a connection stayed
open indefinitely.
Clients built on subscriptions-transport-ws send connection_init as soon as
they connect, so they arenβt affected. If your clients need longer, raise the
timeout:
from datetime import timedelta
from strawberry.asgi import GraphQL
app = GraphQL(schema, connection_init_wait_timeout=timedelta(minutes=5)) is_websocket_origin_allowed must be a regular method
An override of is_websocket_origin_allowed written as async def now rejects
every cross-origin WebSocket handshake it is asked about, and Strawberry logs an
error naming the method on the strawberry.ws logger. Before, the coroutine it
returned counted as True , so the rule never ran and every origin was accepted.
Write the override as a regular method:
class MyGraphQL(GraphQL): def is_websocket_origin_allowed(self, request, origin: str) -> bool: return origin.endswith(".example.com") If the rule needs data from a database or another service, load it ahead of time, for example at startup, and check against it here.
Repeated connection_init messages on graphql-ws are ignored
A graphql-ws client that sends connection_init again on an open connection
no longer re-runs on_ws_connect or changes connection_params . To change
credentials, open a new connection.