We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Subscription example does not work - TypeError: get_context() missing 1 required positional argument: 'response'
## Describe the Bug

When trying to run the first subscription example from the [Documentation](https://strawberry.rocks/docs/general/subscriptions) the following error occurs as soon as the subscription is sent from GraphiQL:

```
Running strawberry on http://0.0.0.0:8000/graphql 🍓
[2023-04-30 17:58:55]: No operation name
subscription {
  count(target: 5)
}

ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "/Users/user/Library/Python/3.9/lib/python/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 254, in run_asgi
    result = await self.app(self.scope, self.asgi_receive, self.asgi_send)
  File "/Users/user/Library/Python/3.9/lib/python/site-packages/uvicorn/middleware/proxy_headers.py", line 78, in __call__
    return await self.app(scope, receive, send)
  File "/Users/user/Library/Python/3.9/lib/python/site-packages/starlette/applications.py", line 122, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/Users/user/Library/Python/3.9/lib/python/site-packages/starlette/middleware/errors.py", line 149, in __call__
    await self.app(scope, receive, send)
  File "/Users/user/Library/Python/3.9/lib/python/site-packages/starlette/middleware/cors.py", line 76, in __call__
    await self.app(scope, receive, send)
  File "/Users/user/Library/Python/3.9/lib/python/site-packages/starlette/middleware/exceptions.py", line 79, in __call__
    raise exc
  File "/Users/user/Library/Python/3.9/lib/python/site-packages/starlette/middleware/exceptions.py", line 68, in __call__
    await self.app(scope, receive, sender)
  File "/Users/user/Library/Python/3.9/lib/python/site-packages/starlette/routing.py", line 718, in __call__
    await route.handle(scope, receive, send)
  File "/Users/user/Library/Python/3.9/lib/python/site-packages/starlette/routing.py", line 341, in handle
    await self.app(scope, receive, send)
  File "/Users/user/Library/Python/3.9/lib/python/site-packages/strawberry/asgi/__init__.py", line 118, in __call__
    await self.graphql_transport_ws_handler_class(
  File "/Users/user/Library/Python/3.9/lib/python/site-packages/strawberry/subscriptions/protocols/graphql_transport_ws/handlers.py", line 78, in handle
    return await self.handle_request()
  File "/Users/user/Library/Python/3.9/lib/python/site-packages/strawberry/asgi/handlers/graphql_transport_ws_handler.py", line 58, in handle_request
    await self.handle_message(message)
  File "/Users/user/Library/Python/3.9/lib/python/site-packages/strawberry/subscriptions/protocols/graphql_transport_ws/handlers.py", line 125, in handle_message
    await handler(handler_arg)
  File "/Users/user/Library/Python/3.9/lib/python/site-packages/strawberry/subscriptions/protocols/graphql_transport_ws/handlers.py", line 181, in handle_subscribe
    context = await self.get_context()
  File "/Users/user/Library/Python/3.9/lib/python/site-packages/strawberry/asgi/handlers/graphql_transport_ws_handler.py", line 36, in get_context
    return await self._get_context(request=self._ws)
TypeError: get_context() missing 1 required positional argument: 'response'
ERROR:    closing handshake failed
Traceback (most recent call last):
  File "/Users/user/Library/Python/3.9/lib/python/site-packages/websockets/legacy/server.py", line 248, in handler
    await self.close()
  File "/Users/user/Library/Python/3.9/lib/python/site-packages/websockets/legacy/protocol.py", line 766, in close
    await self.write_close_frame(Close(code, reason))
  File "/Users/user/Library/Python/3.9/lib/python/site-packages/websockets/legacy/protocol.py", line 1232, in write_close_frame
    await self.write_frame(True, OP_CLOSE, data, _state=State.CLOSING)
  File "/Users/user/Library/Python/3.9/lib/python/site-packages/websockets/legacy/protocol.py", line 1205, in write_frame
    await self.drain()
  File "/Users/user/Library/Python/3.9/lib/python/site-packages/websockets/legacy/protocol.py", line 1194, in drain
    await self.ensure_open()
  File "/Users/user/Library/Python/3.9/lib/python/site-packages/websockets/legacy/protocol.py", line 935, in ensure_open
    raise self.connection_closed_exc()
websockets.exceptions.ConnectionClosedError: sent 1000 (OK); no close frame received
```

## System Information

 - Operating system: `macOS 13.2 (MacBook Pro M2 Chip - ARM64)`
 - Strawberry version (if applicable): `0.175.0`, also tested: `0.173.1`

## Additional Context

- Start command: `python3 -m strawberry server app`
- Python version: `3.9.0`

<!-- POLAR PLEDGE BADGE START -->
## Upvote & Fund

- We're using [Polar.sh](https://polar.sh/strawberry-graphql) so you can upvote and help fund this issue.
- We receive the funding once the issue is completed & confirmed by you.
- Thank you in advance for helping prioritize & fund our backlog.

<a href="https://polar.sh/strawberry-graphql/strawberry/issues/2738">
<picture>
  <source media="(prefers-color-scheme: dark)" srcset="https://polar.sh/api/github/strawberry-graphql/strawberry/issues/2738/pledge.svg?darkmode=1">
  <img alt="Fund with Polar" src="https://polar.sh/api/github/strawberry-graphql/strawberry/issues/2738/pledge.svg">
</picture>
</a>
<!-- POLAR PLEDGE BADGE END -->


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `strawberry/asgi/handlers/graphql_ws_handler.py`
Content:
```
1 from __future__ import annotations
2 
3 from contextlib import suppress
4 from typing import TYPE_CHECKING, Any, Optional
5 
6 from starlette.websockets import WebSocketDisconnect, WebSocketState
7 
8 from strawberry.subscriptions import GRAPHQL_WS_PROTOCOL
9 from strawberry.subscriptions.protocols.graphql_ws.handlers import BaseGraphQLWSHandler
10 
11 if TYPE_CHECKING:
12     from starlette.websockets import WebSocket
13 
14     from strawberry.schema import BaseSchema
15     from strawberry.subscriptions.protocols.graphql_ws.types import OperationMessage
16 
17 
18 class GraphQLWSHandler(BaseGraphQLWSHandler):
19     def __init__(
20         self,
21         schema: BaseSchema,
22         debug: bool,
23         keep_alive: bool,
24         keep_alive_interval: float,
25         get_context,
26         get_root_value,
27         ws: WebSocket,
28     ):
29         super().__init__(schema, debug, keep_alive, keep_alive_interval)
30         self._get_context = get_context
31         self._get_root_value = get_root_value
32         self._ws = ws
33 
34     async def get_context(self) -> Any:
35         return await self._get_context(request=self._ws)
36 
37     async def get_root_value(self) -> Any:
38         return await self._get_root_value(request=self._ws)
39 
40     async def send_json(self, data: OperationMessage) -> None:
41         await self._ws.send_json(data)
42 
43     async def close(self, code: int = 1000, reason: Optional[str] = None) -> None:
44         await self._ws.close(code=code, reason=reason)
45 
46     async def handle_request(self) -> Any:
47         await self._ws.accept(subprotocol=GRAPHQL_WS_PROTOCOL)
48 
49         try:
50             while self._ws.application_state != WebSocketState.DISCONNECTED:
51                 try:
52                     message = await self._ws.receive_json()
53                 except KeyError:
54                     # Ignore non-text messages
55                     continue
56                 else:
57                     await self.handle_message(message)
58         except WebSocketDisconnect:  # pragma: no cover
59             pass
60         finally:
61             if self.keep_alive_task:
62                 self.keep_alive_task.cancel()
63                 with suppress(BaseException):
64                     await self.keep_alive_task
65 
66             for operation_id in list(self.subscriptions.keys()):
67                 await self.cleanup_operation(operation_id)
68
```

Path: `strawberry/asgi/handlers/graphql_transport_ws_handler.py`
Content:
```
1 from __future__ import annotations
2 
3 from typing import TYPE_CHECKING, Any
4 
5 from starlette.websockets import WebSocketDisconnect, WebSocketState
6 
7 from strawberry.subscriptions import GRAPHQL_TRANSPORT_WS_PROTOCOL
8 from strawberry.subscriptions.protocols.graphql_transport_ws.handlers import (
9     BaseGraphQLTransportWSHandler,
10 )
11 
12 if TYPE_CHECKING:
13     from datetime import timedelta
14 
15     from starlette.websockets import WebSocket
16 
17     from strawberry.schema import BaseSchema
18 
19 
20 class GraphQLTransportWSHandler(BaseGraphQLTransportWSHandler):
21     def __init__(
22         self,
23         schema: BaseSchema,
24         debug: bool,
25         connection_init_wait_timeout: timedelta,
26         get_context,
27         get_root_value,
28         ws: WebSocket,
29     ):
30         super().__init__(schema, debug, connection_init_wait_timeout)
31         self._get_context = get_context
32         self._get_root_value = get_root_value
33         self._ws = ws
34 
35     async def get_context(self) -> Any:
36         return await self._get_context(request=self._ws)
37 
38     async def get_root_value(self) -> Any:
39         return await self._get_root_value(request=self._ws)
40 
41     async def send_json(self, data: dict) -> None:
42         await self._ws.send_json(data)
43 
44     async def close(self, code: int, reason: str) -> None:
45         await self._ws.close(code=code, reason=reason)
46 
47     async def handle_request(self) -> None:
48         await self._ws.accept(subprotocol=GRAPHQL_TRANSPORT_WS_PROTOCOL)
49 
50         try:
51             while self._ws.application_state != WebSocketState.DISCONNECTED:
52                 try:
53                     message = await self._ws.receive_json()
54                 except KeyError:
55                     error_message = "WebSocket message type must be text"
56                     await self.handle_invalid_message(error_message)
57                 else:
58                     await self.handle_message(message)
59         except WebSocketDisconnect:  # pragma: no cover
60             pass
61         finally:
62             for operation_id in list(self.subscriptions.keys()):
63                 await self.cleanup_operation(operation_id)
64             await self.reap_completed_tasks()
65
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/strawberry/asgi/handlers/graphql_transport_ws_handler.py b/strawberry/asgi/handlers/graphql_transport_ws_handler.py
--- a/strawberry/asgi/handlers/graphql_transport_ws_handler.py
+++ b/strawberry/asgi/handlers/graphql_transport_ws_handler.py
@@ -33,7 +33,7 @@
         self._ws = ws
 
     async def get_context(self) -> Any:
-        return await self._get_context(request=self._ws)
+        return await self._get_context(request=self._ws, response=None)
 
     async def get_root_value(self) -> Any:
         return await self._get_root_value(request=self._ws)
diff --git a/strawberry/asgi/handlers/graphql_ws_handler.py b/strawberry/asgi/handlers/graphql_ws_handler.py
--- a/strawberry/asgi/handlers/graphql_ws_handler.py
+++ b/strawberry/asgi/handlers/graphql_ws_handler.py
@@ -32,7 +32,7 @@
         self._ws = ws
 
     async def get_context(self) -> Any:
-        return await self._get_context(request=self._ws)
+        return await self._get_context(request=self._ws, response=None)
 
     async def get_root_value(self) -> Any:
         return await self._get_root_value(request=self._ws)

{"golden_diff": "diff --git a/strawberry/asgi/handlers/graphql_transport_ws_handler.py b/strawberry/asgi/handlers/graphql_transport_ws_handler.py\n--- a/strawberry/asgi/handlers/graphql_transport_ws_handler.py\n+++ b/strawberry/asgi/handlers/graphql_transport_ws_handler.py\n@@ -33,7 +33,7 @@\n         self._ws = ws\n \n     async def get_context(self) -> Any:\n-        return await self._get_context(request=self._ws)\n+        return await self._get_context(request=self._ws, response=None)\n \n     async def get_root_value(self) -> Any:\n         return await self._get_root_value(request=self._ws)\ndiff --git a/strawberry/asgi/handlers/graphql_ws_handler.py b/strawberry/asgi/handlers/graphql_ws_handler.py\n--- a/strawberry/asgi/handlers/graphql_ws_handler.py\n+++ b/strawberry/asgi/handlers/graphql_ws_handler.py\n@@ -32,7 +32,7 @@\n         self._ws = ws\n \n     async def get_context(self) -> Any:\n-        return await self._get_context(request=self._ws)\n+        return await self._get_context(request=self._ws, response=None)\n \n     async def get_root_value(self) -> Any:\n         return await self._get_root_value(request=self._ws)\n", "issue": "Subscription example does not work - TypeError: get_context() missing 1 required positional argument: 'response'\n## Describe the Bug\r\n\r\nWhen trying to run the first subscription example from the [Documentation](https://strawberry.rocks/docs/general/subscriptions) the following error occurs as soon as the subscription is sent from GraphiQL:\r\n\r\n```\r\nRunning strawberry on http://0.0.0.0:8000/graphql \ud83c\udf53\r\n[2023-04-30 17:58:55]: No operation name\r\nsubscription {\r\n  count(target: 5)\r\n}\r\n\r\nERROR:    Exception in ASGI application\r\nTraceback (most recent call last):\r\n  File \"/Users/user/Library/Python/3.9/lib/python/site-packages/uvicorn/protocols/websockets/websockets_impl.py\", line 254, in run_asgi\r\n    result = await self.app(self.scope, self.asgi_receive, self.asgi_send)\r\n  File \"/Users/user/Library/Python/3.9/lib/python/site-packages/uvicorn/middleware/proxy_headers.py\", line 78, in __call__\r\n    return await self.app(scope, receive, send)\r\n  File \"/Users/user/Library/Python/3.9/lib/python/site-packages/starlette/applications.py\", line 122, in __call__\r\n    await self.middleware_stack(scope, receive, send)\r\n  File \"/Users/user/Library/Python/3.9/lib/python/site-packages/starlette/middleware/errors.py\", line 149, in __call__\r\n    await self.app(scope, receive, send)\r\n  File \"/Users/user/Library/Python/3.9/lib/python/site-packages/starlette/middleware/cors.py\", line 76, in __call__\r\n    await self.app(scope, receive, send)\r\n  File \"/Users/user/Library/Python/3.9/lib/python/site-packages/starlette/middleware/exceptions.py\", line 79, in __call__\r\n    raise exc\r\n  File \"/Users/user/Library/Python/3.9/lib/python/site-packages/starlette/middleware/exceptions.py\", line 68, in __call__\r\n    await self.app(scope, receive, sender)\r\n  File \"/Users/user/Library/Python/3.9/lib/python/site-packages/starlette/routing.py\", line 718, in __call__\r\n    await route.handle(scope, receive, send)\r\n  File \"/Users/user/Library/Python/3.9/lib/python/site-packages/starlette/routing.py\", line 341, in handle\r\n    await self.app(scope, receive, send)\r\n  File \"/Users/user/Library/Python/3.9/lib/python/site-packages/strawberry/asgi/__init__.py\", line 118, in __call__\r\n    await self.graphql_transport_ws_handler_class(\r\n  File \"/Users/user/Library/Python/3.9/lib/python/site-packages/strawberry/subscriptions/protocols/graphql_transport_ws/handlers.py\", line 78, in handle\r\n    return await self.handle_request()\r\n  File \"/Users/user/Library/Python/3.9/lib/python/site-packages/strawberry/asgi/handlers/graphql_transport_ws_handler.py\", line 58, in handle_request\r\n    await self.handle_message(message)\r\n  File \"/Users/user/Library/Python/3.9/lib/python/site-packages/strawberry/subscriptions/protocols/graphql_transport_ws/handlers.py\", line 125, in handle_message\r\n    await handler(handler_arg)\r\n  File \"/Users/user/Library/Python/3.9/lib/python/site-packages/strawberry/subscriptions/protocols/graphql_transport_ws/handlers.py\", line 181, in handle_subscribe\r\n    context = await self.get_context()\r\n  File \"/Users/user/Library/Python/3.9/lib/python/site-packages/strawberry/asgi/handlers/graphql_transport_ws_handler.py\", line 36, in get_context\r\n    return await self._get_context(request=self._ws)\r\nTypeError: get_context() missing 1 required positional argument: 'response'\r\nERROR:    closing handshake failed\r\nTraceback (most recent call last):\r\n  File \"/Users/user/Library/Python/3.9/lib/python/site-packages/websockets/legacy/server.py\", line 248, in handler\r\n    await self.close()\r\n  File \"/Users/user/Library/Python/3.9/lib/python/site-packages/websockets/legacy/protocol.py\", line 766, in close\r\n    await self.write_close_frame(Close(code, reason))\r\n  File \"/Users/user/Library/Python/3.9/lib/python/site-packages/websockets/legacy/protocol.py\", line 1232, in write_close_frame\r\n    await self.write_frame(True, OP_CLOSE, data, _state=State.CLOSING)\r\n  File \"/Users/user/Library/Python/3.9/lib/python/site-packages/websockets/legacy/protocol.py\", line 1205, in write_frame\r\n    await self.drain()\r\n  File \"/Users/user/Library/Python/3.9/lib/python/site-packages/websockets/legacy/protocol.py\", line 1194, in drain\r\n    await self.ensure_open()\r\n  File \"/Users/user/Library/Python/3.9/lib/python/site-packages/websockets/legacy/protocol.py\", line 935, in ensure_open\r\n    raise self.connection_closed_exc()\r\nwebsockets.exceptions.ConnectionClosedError: sent 1000 (OK); no close frame received\r\n```\r\n\r\n## System Information\r\n\r\n - Operating system: `macOS 13.2 (MacBook Pro M2 Chip - ARM64)`\r\n - Strawberry version (if applicable): `0.175.0`, also tested: `0.173.1`\r\n\r\n## Additional Context\r\n\r\n- Start command: `python3 -m strawberry server app`\r\n- Python version: `3.9.0`\n\n<!-- POLAR PLEDGE BADGE START -->\n## Upvote & Fund\n\n- We're using [Polar.sh](https://polar.sh/strawberry-graphql) so you can upvote and help fund this issue.\n- We receive the funding once the issue is completed & confirmed by you.\n- Thank you in advance for helping prioritize & fund our backlog.\n\n<a href=\"https://polar.sh/strawberry-graphql/strawberry/issues/2738\">\n<picture>\n  <source media=\"(prefers-color-scheme: dark)\" srcset=\"https://polar.sh/api/github/strawberry-graphql/strawberry/issues/2738/pledge.svg?darkmode=1\">\n  <img alt=\"Fund with Polar\" src=\"https://polar.sh/api/github/strawberry-graphql/strawberry/issues/2738/pledge.svg\">\n</picture>\n</a>\n<!-- POLAR PLEDGE BADGE END -->\n\n", "before_files": [{"content": "from __future__ import annotations\n\nfrom contextlib import suppress\nfrom typing import TYPE_CHECKING, Any, Optional\n\nfrom starlette.websockets import WebSocketDisconnect, WebSocketState\n\nfrom strawberry.subscriptions import GRAPHQL_WS_PROTOCOL\nfrom strawberry.subscriptions.protocols.graphql_ws.handlers import BaseGraphQLWSHandler\n\nif TYPE_CHECKING:\n    from starlette.websockets import WebSocket\n\n    from strawberry.schema import BaseSchema\n    from strawberry.subscriptions.protocols.graphql_ws.types import OperationMessage\n\n\nclass GraphQLWSHandler(BaseGraphQLWSHandler):\n    def __init__(\n        self,\n        schema: BaseSchema,\n        debug: bool,\n        keep_alive: bool,\n        keep_alive_interval: float,\n        get_context,\n        get_root_value,\n        ws: WebSocket,\n    ):\n        super().__init__(schema, debug, keep_alive, keep_alive_interval)\n        self._get_context = get_context\n        self._get_root_value = get_root_value\n        self._ws = ws\n\n    async def get_context(self) -> Any:\n        return await self._get_context(request=self._ws)\n\n    async def get_root_value(self) -> Any:\n        return await self._get_root_value(request=self._ws)\n\n    async def send_json(self, data: OperationMessage) -> None:\n        await self._ws.send_json(data)\n\n    async def close(self, code: int = 1000, reason: Optional[str] = None) -> None:\n        await self._ws.close(code=code, reason=reason)\n\n    async def handle_request(self) -> Any:\n        await self._ws.accept(subprotocol=GRAPHQL_WS_PROTOCOL)\n\n        try:\n            while self._ws.application_state != WebSocketState.DISCONNECTED:\n                try:\n                    message = await self._ws.receive_json()\n                except KeyError:\n                    # Ignore non-text messages\n                    continue\n                else:\n                    await self.handle_message(message)\n        except WebSocketDisconnect:  # pragma: no cover\n            pass\n        finally:\n            if self.keep_alive_task:\n                self.keep_alive_task.cancel()\n                with suppress(BaseException):\n                    await self.keep_alive_task\n\n            for operation_id in list(self.subscriptions.keys()):\n                await self.cleanup_operation(operation_id)\n", "path": "strawberry/asgi/handlers/graphql_ws_handler.py"}, {"content": "from __future__ import annotations\n\nfrom typing import TYPE_CHECKING, Any\n\nfrom starlette.websockets import WebSocketDisconnect, WebSocketState\n\nfrom strawberry.subscriptions import GRAPHQL_TRANSPORT_WS_PROTOCOL\nfrom strawberry.subscriptions.protocols.graphql_transport_ws.handlers import (\n    BaseGraphQLTransportWSHandler,\n)\n\nif TYPE_CHECKING:\n    from datetime import timedelta\n\n    from starlette.websockets import WebSocket\n\n    from strawberry.schema import BaseSchema\n\n\nclass GraphQLTransportWSHandler(BaseGraphQLTransportWSHandler):\n    def __init__(\n        self,\n        schema: BaseSchema,\n        debug: bool,\n        connection_init_wait_timeout: timedelta,\n        get_context,\n        get_root_value,\n        ws: WebSocket,\n    ):\n        super().__init__(schema, debug, connection_init_wait_timeout)\n        self._get_context = get_context\n        self._get_root_value = get_root_value\n        self._ws = ws\n\n    async def get_context(self) -> Any:\n        return await self._get_context(request=self._ws)\n\n    async def get_root_value(self) -> Any:\n        return await self._get_root_value(request=self._ws)\n\n    async def send_json(self, data: dict) -> None:\n        await self._ws.send_json(data)\n\n    async def close(self, code: int, reason: str) -> None:\n        await self._ws.close(code=code, reason=reason)\n\n    async def handle_request(self) -> None:\n        await self._ws.accept(subprotocol=GRAPHQL_TRANSPORT_WS_PROTOCOL)\n\n        try:\n            while self._ws.application_state != WebSocketState.DISCONNECTED:\n                try:\n                    message = await self._ws.receive_json()\n                except KeyError:\n                    error_message = \"WebSocket message type must be text\"\n                    await self.handle_invalid_message(error_message)\n                else:\n                    await self.handle_message(message)\n        except WebSocketDisconnect:  # pragma: no cover\n            pass\n        finally:\n            for operation_id in list(self.subscriptions.keys()):\n                await self.cleanup_operation(operation_id)\n            await self.reap_completed_tasks()\n", "path": "strawberry/asgi/handlers/graphql_transport_ws_handler.py"}], "after_files": [{"content": "from __future__ import annotations\n\nfrom contextlib import suppress\nfrom typing import TYPE_CHECKING, Any, Optional\n\nfrom starlette.websockets import WebSocketDisconnect, WebSocketState\n\nfrom strawberry.subscriptions import GRAPHQL_WS_PROTOCOL\nfrom strawberry.subscriptions.protocols.graphql_ws.handlers import BaseGraphQLWSHandler\n\nif TYPE_CHECKING:\n    from starlette.websockets import WebSocket\n\n    from strawberry.schema import BaseSchema\n    from strawberry.subscriptions.protocols.graphql_ws.types import OperationMessage\n\n\nclass GraphQLWSHandler(BaseGraphQLWSHandler):\n    def __init__(\n        self,\n        schema: BaseSchema,\n        debug: bool,\n        keep_alive: bool,\n        keep_alive_interval: float,\n        get_context,\n        get_root_value,\n        ws: WebSocket,\n    ):\n        super().__init__(schema, debug, keep_alive, keep_alive_interval)\n        self._get_context = get_context\n        self._get_root_value = get_root_value\n        self._ws = ws\n\n    async def get_context(self) -> Any:\n        return await self._get_context(request=self._ws, response=None)\n\n    async def get_root_value(self) -> Any:\n        return await self._get_root_value(request=self._ws)\n\n    async def send_json(self, data: OperationMessage) -> None:\n        await self._ws.send_json(data)\n\n    async def close(self, code: int = 1000, reason: Optional[str] = None) -> None:\n        await self._ws.close(code=code, reason=reason)\n\n    async def handle_request(self) -> Any:\n        await self._ws.accept(subprotocol=GRAPHQL_WS_PROTOCOL)\n\n        try:\n            while self._ws.application_state != WebSocketState.DISCONNECTED:\n                try:\n                    message = await self._ws.receive_json()\n                except KeyError:\n                    # Ignore non-text messages\n                    continue\n                else:\n                    await self.handle_message(message)\n        except WebSocketDisconnect:  # pragma: no cover\n            pass\n        finally:\n            if self.keep_alive_task:\n                self.keep_alive_task.cancel()\n                with suppress(BaseException):\n                    await self.keep_alive_task\n\n            for operation_id in list(self.subscriptions.keys()):\n                await self.cleanup_operation(operation_id)\n", "path": "strawberry/asgi/handlers/graphql_ws_handler.py"}, {"content": "from __future__ import annotations\n\nfrom typing import TYPE_CHECKING, Any\n\nfrom starlette.websockets import WebSocketDisconnect, WebSocketState\n\nfrom strawberry.subscriptions import GRAPHQL_TRANSPORT_WS_PROTOCOL\nfrom strawberry.subscriptions.protocols.graphql_transport_ws.handlers import (\n    BaseGraphQLTransportWSHandler,\n)\n\nif TYPE_CHECKING:\n    from datetime import timedelta\n\n    from starlette.websockets import WebSocket\n\n    from strawberry.schema import BaseSchema\n\n\nclass GraphQLTransportWSHandler(BaseGraphQLTransportWSHandler):\n    def __init__(\n        self,\n        schema: BaseSchema,\n        debug: bool,\n        connection_init_wait_timeout: timedelta,\n        get_context,\n        get_root_value,\n        ws: WebSocket,\n    ):\n        super().__init__(schema, debug, connection_init_wait_timeout)\n        self._get_context = get_context\n        self._get_root_value = get_root_value\n        self._ws = ws\n\n    async def get_context(self) -> Any:\n        return await self._get_context(request=self._ws, response=None)\n\n    async def get_root_value(self) -> Any:\n        return await self._get_root_value(request=self._ws)\n\n    async def send_json(self, data: dict) -> None:\n        await self._ws.send_json(data)\n\n    async def close(self, code: int, reason: str) -> None:\n        await self._ws.close(code=code, reason=reason)\n\n    async def handle_request(self) -> None:\n        await self._ws.accept(subprotocol=GRAPHQL_TRANSPORT_WS_PROTOCOL)\n\n        try:\n            while self._ws.application_state != WebSocketState.DISCONNECTED:\n                try:\n                    message = await self._ws.receive_json()\n                except KeyError:\n                    error_message = \"WebSocket message type must be text\"\n                    await self.handle_invalid_message(error_message)\n                else:\n                    await self.handle_message(message)\n        except WebSocketDisconnect:  # pragma: no cover\n            pass\n        finally:\n            for operation_id in list(self.subscriptions.keys()):\n                await self.cleanup_operation(operation_id)\n            await self.reap_completed_tasks()\n", "path": "strawberry/asgi/handlers/graphql_transport_ws_handler.py"}]}