Skip to content

Subscriptions testing #513

Answered by rafalp
sztadii asked this question in Q&A
Mar 25, 2021 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

Ariadne's test suite contains examples of how subscriptions can be tested:

from starlette.testclient import TestClient

from ariadne.asgi import (
    GQL_CONNECTION_ACK,
    GQL_CONNECTION_ERROR,
    GQL_CONNECTION_INIT,
    GQL_CONNECTION_TERMINATE,
    GQL_START,
    GQL_DATA,
    GQL_STOP,
    GQL_COMPLETE,
    GraphQL,
    WebSocketConnectionError,
)


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(
            {
                "type": GQL_START,
                "id": "test1",
                "payload": {"query": "subscription { p…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@sztadii
Comment options

Answer selected by rafalp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #510 on March 25, 2021 10:20.