Repository: mirumee/ariadne
Pull request #1124 (2023-10-10 01:39:44)

Move WebSocketConnectionError to exceptions (#1026)
Addressing issue #1026 

There was a request for this, and it seems clearer to have the WebSocketConnectionError with the other exceptions rather than with the types. 

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/mirumee/ariadne/pull/1124?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mirumee) Report
> Merging [#1124](https://app.codecov.io/gh/mirumee/ariadne/pull/1124?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mirumee) (945b41b) into [master](https://app.codecov.io/gh/mirumee/ariadne/commit/a9cca4f6d8ce07b33d5fb5c6df991bd031d1168b?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mirumee) (a9cca4f) will **increase** coverage by `0.00%`.
> The diff coverage is `70.00%`.

```diff
@@           Coverage Diff           @@
##           master    #1124   +/-   ##
=======================================
  Coverage   97.82%   97.82%           
=======================================
  Files         115      115           
  Lines        7762     7763    +1     
=======================================
+ Hits         7593     7594    +1     
  Misses        169      169           
```


| [Files](https://app.codecov.io/gh/mirumee/ariadne/pull/1124?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mirumee) | Coverage Δ | |
|---|---|---|
| [ariadne/asgi/handlers/graphql\_ws.py](https://app.codecov.io/gh/mirumee/ariadne/pull/1124?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mirumee#diff-YXJpYWRuZS9hc2dpL2hhbmRsZXJzL2dyYXBocWxfd3MucHk=) | `98.71% <100.00%> (+<0.01%)` | :arrow_up: |
| [ariadne/types.py](https://app.codecov.io/gh/mirumee/ariadne/pull/1124?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mirumee#diff-YXJpYWRuZS90eXBlcy5weQ==) | `98.38% <ø> (+4.18%)` | :arrow_up: |
| [tests/asgi/test\_websockets\_graphql\_transport\_ws.py](https://app.codecov.io/gh/mirumee/ariadne/pull/1124?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mirumee#diff-dGVzdHMvYXNnaS90ZXN0X3dlYnNvY2tldHNfZ3JhcGhxbF90cmFuc3BvcnRfd3MucHk=) | `100.00% <100.00%> (ø)` | |
| [tests/asgi/test\_websockets\_graphql\_ws.py](https://app.codecov.io/gh/mirumee/ariadne/pull/1124?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mirumee#diff-dGVzdHMvYXNnaS90ZXN0X3dlYnNvY2tldHNfZ3JhcGhxbF93cy5weQ==) | `100.00% <100.00%> (ø)` | |
| [ariadne/exceptions.py](https://app.codecov.io/gh/mirumee/ariadne/pull/1124?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mirumee#diff-YXJpYWRuZS9leGNlcHRpb25zLnB5) | `88.00% <57.14%> (-12.00%)` | :arrow_down: |

:mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mirumee)

rafalp: Looking good. Thank you!

Patch:
diff --git a/ariadne/asgi/__init__.py b/ariadne/asgi/__init__.py
index 2e25d6c..07da1f6 100644
--- a/ariadne/asgi/__init__.py
+++ b/ariadne/asgi/__init__.py
@@ -1,3 +1,4 @@
+from ..exceptions import WebSocketConnectionError
 from ..types import (
     Extensions,
     MiddlewareList,
@@ -7,7 +8,6 @@ from ..types import (
     OnDisconnect,
     OnOperation,
     Operation,
-    WebSocketConnectionError,
 )
 from .graphql import GraphQL
 
diff --git a/ariadne/asgi/handlers/graphql_ws.py b/ariadne/asgi/handlers/graphql_ws.py
index 26177f7..1d5f0e3 100644
--- a/ariadne/asgi/handlers/graphql_ws.py
+++ b/ariadne/asgi/handlers/graphql_ws.py
@@ -7,11 +7,11 @@ from graphql.language import OperationType
 from starlette.types import Receive, Scope, Send
 from starlette.websockets import WebSocket, WebSocketDisconnect, WebSocketState
 
+from ...exceptions import WebSocketConnectionError
 from ...graphql import parse_query, subscribe, validate_data
 from ...logger import log_error
 from ...types import (
     Operation,
-    WebSocketConnectionError,
 )
 from ...utils import get_operation_type
 from .base import GraphQLWebsocketHandler
diff --git a/ariadne/exceptions.py b/ariadne/exceptions.py
index 450b53f..514e401 100644
--- a/ariadne/exceptions.py
+++ b/ariadne/exceptions.py
@@ -62,3 +62,15 @@ class GraphQLFileSyntaxError(Exception):
     def __str__(self):
         """Returns error message."""
         return self.message
+
+
+class WebSocketConnectionError(Exception):
+    """Special error class enabling custom error reporting for on_connect"""
+
+    def __init__(self, payload: Optional[Union[dict, str]] = None) -> None:
+        if isinstance(payload, dict):
+            self.payload = payload
+        elif payload:
+            self.payload = {"message": str(payload)}
+        else:
+            self.payload = {"message": "Unexpected error has occurred."}
diff --git a/ariadne/types.py b/ariadne/types.py
index b9fd827..738bece 100644
--- a/ariadne/types.py
+++ b/ariadne/types.py
@@ -47,7 +47,6 @@ __all__ = [
     "OnDisconnect",
     "OnOperation",
     "OnComplete",
-    "WebSocketConnectionError",
     "Extension",
     "SchemaBindable",
 ]
@@ -503,18 +502,6 @@ Called with two arguments:
 OnComplete = Callable[[WebSocket, Operation], Any]
 
 
-class WebSocketConnectionError(Exception):
-    """Special error class enabling custom error reporting for on_connect"""
-
-    def __init__(self, payload: Optional[Union[dict, str]] = None) -> None:
-        if isinstance(payload, dict):
-            self.payload = payload
-        elif payload:
-            self.payload = {"message": str(payload)}
-        else:
-            self.payload = {"message": "Unexpected error has occurred."}
-
-
 class Extension:
     """Base class for extensions.
 


Test patch:
diff --git a/tests/asgi/test_websockets_graphql_transport_ws.py b/tests/asgi/test_websockets_graphql_transport_ws.py
index 649070c..38489f3 100644
--- a/tests/asgi/test_websockets_graphql_transport_ws.py
+++ b/tests/asgi/test_websockets_graphql_transport_ws.py
@@ -9,7 +9,7 @@ from starlette.websockets import WebSocketDisconnect
 
 from ariadne.asgi import GraphQL
 from ariadne.asgi.handlers import GraphQLTransportWSHandler
-from ariadne.types import WebSocketConnectionError
+from ariadne.exceptions import WebSocketConnectionError
 from ariadne.utils import get_operation_type
 
 
diff --git a/tests/asgi/test_websockets_graphql_ws.py b/tests/asgi/test_websockets_graphql_ws.py
index f0d8a11..abc2e2f 100644
--- a/tests/asgi/test_websockets_graphql_ws.py
+++ b/tests/asgi/test_websockets_graphql_ws.py
@@ -7,7 +7,7 @@ from starlette.testclient import TestClient
 
 from ariadne.asgi import GraphQL
 from ariadne.asgi.handlers import GraphQLWSHandler
-from ariadne.types import WebSocketConnectionError
+from ariadne.exceptions import WebSocketConnectionError
 
 
 def test_field_can_be_subscribed_using_websocket_connection(client):