How to use the ariadne.asgi.GraphQL function in ariadne

To help you get started, we’ve selected a few ariadne examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mirumee / ariadne / tests / asgi / test_configuration.py View on Github external
def test_custom_root_value_is_passed_to_subscription_resolvers(schema):
    app = GraphQL(schema, root_value={"test": "TEST-ROOT"})
    client = TestClient(app)
    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 { testRoot }"},
            }
        )
        response = ws.receive_json()
        assert response["type"] == GQL_CONNECTION_ACK
        response = ws.receive_json()
        assert response["type"] == GQL_DATA
        assert response["payload"] == {"data": {"testRoot": "TEST-ROOT"}}
github mirumee / ariadne / tests / asgi / test_configuration.py View on Github external
def test_extension_from_option_are_passed_to_query_executor(schema):
    app = GraphQL(schema, extensions=[CustomExtension])
    client = TestClient(app)
    response = client.post("/", json={"query": '{ hello(name: "BOB") }'})
    assert response.json() == {"data": {"hello": "hello, bob!"}}
github mirumee / ariadne / tests / asgi / test_configuration.py View on Github external
def test_custom_logger_is_used_to_log_subscription_resolver_error(schema, mocker):
    logging_mock = mocker.patch("ariadne.logger.logging")
    app = GraphQL(schema, logger="custom")
    client = TestClient(app)
    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 { resolverError }"},
            }
        )
        response = ws.receive_json()
        assert response["type"] == GQL_CONNECTION_ACK
        response = ws.receive_json()
        assert response["type"] == GQL_DATA
        logging_mock.getLogger.assert_called_once_with("custom")
github mirumee / ariadne / tests / asgi / test_configuration.py View on Github external
def test_custom_logger_is_used_to_log_query_error(schema, mocker):
    logging_mock = mocker.patch("ariadne.logger.logging")
    app = GraphQL(schema, logger="custom")
    execute_failing_query(app)
    logging_mock.getLogger.assert_called_once_with("custom")
github mirumee / ariadne / tests / asgi / test_playground.py View on Github external
def test_playground_html_is_served_on_get_request(schema, snapshot):
    app = GraphQL(schema)
    client = TestClient(app)
    response = client.get("/")
    assert response.status_code == 200
    snapshot.assert_match(response.text)
github mirumee / ariadne / tests / asgi / test_configuration.py View on Github external
def test_custom_root_value_is_passed_to_query_resolvers(schema):
    app = GraphQL(schema, root_value={"test": "TEST-ROOT"})
    client = TestClient(app)
    response = client.post("/", json={"query": "{ testRoot }"})
    assert response.json() == {"data": {"testRoot": "TEST-ROOT"}}
github mirumee / ariadne / tests / asgi / test_configuration.py View on Github external
def test_custom_root_value_function_is_called_with_context_value(schema):
    get_root_value = Mock(return_value=True)
    app = GraphQL(
        schema, context_value={"test": "TEST-CONTEXT"}, root_value=get_root_value
    )
    client = TestClient(app)
    client.post("/", json={"query": "{ status }"})
    get_root_value.assert_called_once_with({"test": "TEST-CONTEXT"}, ANY)
github mirumee / ariadne / tests / asgi / test_configuration.py View on Github external
def test_custom_root_value_function_is_called_by_subscription(schema):
    get_root_value = Mock(return_value=True)
    app = GraphQL(schema, root_value=get_root_value)
    client = TestClient(app)
    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 { ping }"},
            }
        )
        response = ws.receive_json()
        assert response["type"] == GQL_CONNECTION_ACK
        response = ws.receive_json()
        assert response["type"] == GQL_DATA
        get_root_value.assert_called_once()
github mirumee / graphql-workshop / 01-basics-final / example.py View on Github external
@query.field("hello")  # Query.hello
def resolve_hello(*_):
    return "Hello DjangoCon!"


@mutation.field("add")  # Mutation.add
def resolve_add(*_, a: int, b: int):
    return a + b


# Create an executable GraphQL schema
schema = make_executable_schema(type_defs, [query, mutation])

# Create the ASGI app
app = GraphQL(schema, debug=True)
github mirumee / graphql-workshop / 02-object-types / example.py View on Github external
@query.field("books")  # Query.books
def resolve_books(*_):
    return [
        {"title": "The Color of Magic", "year": 1983},
        {"title": "The Light Fantastic", "year": 1986},
        {"title": "Equal Rites", "year": 1987},
    ]


# Create an executable GraphQL schema
schema = make_executable_schema(type_defs, [query])

# Create the ASGI app
app = GraphQL(schema, debug=True)