strawberry.channels.GraphQLWSConsumer

A channels websocket consumer for GraphQL.

This handles the connections, then hands off to the appropriate handler based on the subprotocol.

To use this, place it in your ProtocolTypeRouter for your channels project, e.g:

from strawberry.channels import GraphQLHttpRouter
from channels.routing import ProtocolTypeRouter
from django.core.asgi import get_asgi_application
application = ProtocolTypeRouter({
"http": URLRouter([
re_path("^graphql", GraphQLHTTPRouter(schema=schema)),
re_path("^", get_asgi_application()),
]),
"websocket": URLRouter([
re_path("^ws/graphql", GraphQLWebSocketRouter(schema=schema)),
]),
})

Constructor:

Signature:

def __init__(
self,
schema: BaseSchema,
keep_alive: bool = False,
keep_alive_interval: float = 1,
debug: bool = False,
subscription_protocols: Tuple[str, str] = (GRAPHQL_TRANSPORT_WS_PROTOCOL, GRAPHQL_WS_PROTOCOL),
connection_init_wait_timeout: datetime.timedelta | None = None,
) -> None:
...

Parameters:

  1. schema:

    Type
    BaseSchema
  2. keep_alive:

    Type
    bool
    Default
    False
  3. keep_alive_interval:

    Type
    float
    Default
    1
  4. debug:

    Type
    bool
    Default
    False
  5. subscription_protocols:

    Type
    Tuple[str, str]
    Default
    (GRAPHQL_TRANSPORT_WS_PROTOCOL, GRAPHQL_WS_PROTOCOL)
  6. connection_init_wait_timeout:

    Type
    datetime.timedelta | None
    Default
    None

Methods:

Attributes:

  1. graphql_transport_ws_handler_class:

  2. graphql_ws_handler_class:

  3. connection_init_wait_timeout:

  4. schema:

  5. keep_alive:

  6. keep_alive_interval:

  7. debug:

  8. protocols: