Extend test coverage for websockets to cover more possible payloads
@@ -32,6 +32,32 @@ def test_field_can_be_subscribed_using_websocket_connection(client):
ws.send_json({"type": GQL_CONNECTION_TERMINATE})
+def test_field_can_be_subscribed_using_unnamed_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": {
+ "operationName": None,
+ "query": "subscription { 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_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})
@@ -39,7 +65,10 @@ def test_field_can_be_subscribed_using_named_operation_in_websocket_connection(c
{
"type": GQL_START,
"id": "test1",
- "payload": {"query": "subscription PingTest { ping }"},
+ "payload": {
+ "operationName": "PingTest",
+ "query": "subscription PingTest { ping }",
+ },
}
)
response = ws.receive_json()
