Add extra test case for subscription named operation
@@ -9,7 +9,7 @@ from ariadne.asgi import (
)
-def test_ping_can_be_subscribed_using_websocket_connection(client):
+def test_field_can_be_subscribed_using_websocket_connection(client):
with client.websocket_connect("/", "graphql-ws") as ws:
ws.send_json({"type": GQL_CONNECTION_INIT})
ws.send_json(
@@ -32,6 +32,29 @@ def test_ping_can_be_subscribed_using_websocket_connection(client):
ws.send_json({"type": GQL_CONNECTION_TERMINATE})
+def test_field_can_be_subscribed_using_named_operation_in_websocket_connection(client):
+ with client.websocket_connect("/", "graphql-ws") as ws:
+ ws.send_json({"type": GQL_CONNECTION_INIT})
+ ws.send_json(
+ {
+ "type": GQL_START,
+ "id": "test1",
+ "payload": {"query": "subscription PingTest { ping }"},
+ }
+ )
+ response = ws.receive_json()
+ assert response["type"] == GQL_CONNECTION_ACK
+ response = ws.receive_json()
+ assert response["type"] == GQL_DATA
+ assert response["id"] == "test1"
+ assert response["payload"]["data"] == {"ping": "pong"}
+ ws.send_json({"type": GQL_STOP, "id": "test1"})
+ response = ws.receive_json()
+ assert response["type"] == GQL_COMPLETE
+ assert response["id"] == "test1"
+ ws.send_json({"type": GQL_CONNECTION_TERMINATE})
+
+
def test_immediate_disconnect(client):
with client.websocket_connect("/", "graphql-ws") as ws:
ws.send_json({"type": GQL_CONNECTION_INIT})
