From 63d2e48a98c65d16ee2f3b2c1b38b71a29888689 Mon Sep 17 00:00:00 2001 From: Houkime <> Date: Wed, 15 May 2024 11:29:20 +0000 Subject: [PATCH] feature(jobs): websocket connection --- selfprivacy_api/app.py | 7 ++++++- tests/test_graphql/test_websocket.py | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 tests/test_graphql/test_websocket.py diff --git a/selfprivacy_api/app.py b/selfprivacy_api/app.py index 64ca85a..2f7e2f7 100644 --- a/selfprivacy_api/app.py +++ b/selfprivacy_api/app.py @@ -3,6 +3,7 @@ from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from strawberry.fastapi import GraphQLRouter +from strawberry.subscriptions import GRAPHQL_TRANSPORT_WS_PROTOCOL, GRAPHQL_WS_PROTOCOL import uvicorn @@ -13,8 +14,12 @@ from selfprivacy_api.migrations import run_migrations app = FastAPI() -graphql_app = GraphQLRouter( +graphql_app: GraphQLRouter = GraphQLRouter( schema, + subscription_protocols=[ + GRAPHQL_TRANSPORT_WS_PROTOCOL, + GRAPHQL_WS_PROTOCOL, + ], ) app.add_middleware( diff --git a/tests/test_graphql/test_websocket.py b/tests/test_graphql/test_websocket.py new file mode 100644 index 0000000..fb2ac33 --- /dev/null +++ b/tests/test_graphql/test_websocket.py @@ -0,0 +1,6 @@ + +def test_websocket_connection_bare(authorized_client): + client =authorized_client + with client.websocket_connect('/graphql', subprotocols=[ "graphql-transport-ws","graphql-ws"] ) as websocket: + assert websocket is not None + assert websocket.scope is not None