From 5a18fc393449e7aeaf5154a627d357f3b4ed6b5a Mon Sep 17 00:00:00 2001 From: Dan Plischke Date: Thu, 12 Dec 2024 15:22:11 +0100 Subject: [PATCH] format and linting, update requirements.txt in fastapi integration tests to fix Starlette TestClient error, manually set anyio dependency lower for python 3.8 integration tests as current version is not available for 3.8 --- ariadne/asgi/handlers/http.py | 4 ++-- ariadne/contrib/sse.py | 13 ++++++++----- tests/asgi/test_sse.py | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/ariadne/asgi/handlers/http.py b/ariadne/asgi/handlers/http.py index 8d261f60..9432fecc 100644 --- a/ariadne/asgi/handlers/http.py +++ b/ariadne/asgi/handlers/http.py @@ -93,13 +93,13 @@ async def handle(self, scope: Scope, receive: Receive, send: Send) -> None: response = await self.handle_request(request) await response(scope, receive, send) - async def handle_request_override(self, request: Request) -> Optional[Response]: + async def handle_request_override(self, _: Request) -> Optional[Response]: """Override the default request handling logic in subclasses. Is called in the `handle_request` method before the default logic. If None is returned, the default logic is executed. # Required arguments: - `request`: the `Request` instance from Starlette or FastAPI. + `_`: the `Request` instance from Starlette or FastAPI. """ return None diff --git a/ariadne/contrib/sse.py b/ariadne/contrib/sse.py index e6b4be0c..cbc5e506 100644 --- a/ariadne/contrib/sse.py +++ b/ariadne/contrib/sse.py @@ -209,7 +209,8 @@ async def _ping(self, send: Send) -> None: await send( { "type": "http.response.body", - # always encode as utf-8 as per https://html.spec.whatwg.org/multipage/server-sent-events.html#sse-processing-model + # always encode as utf-8 as per + # https://html.spec.whatwg.org/multipage/server-sent-events.html#sse-processing-model "body": ":\r\n\r\n".encode("utf-8"), "more_body": True, } @@ -276,15 +277,17 @@ def encode_event(event: GraphQLServerSentEvent) -> bytes: # Required arguments `event`: the GraphQLServerSentEvent object """ - # always encode as utf-8 as per https://html.spec.whatwg.org/multipage/server-sent-events.html#sse-processing-model + # always encode as utf-8 as per + # https://html.spec.whatwg.org/multipage/server-sent-events.html#sse-processing-model return str(event).encode("utf-8") class GraphQLHTTPSSEHandler(GraphQLHTTPHandler): """Extension to the default GraphQLHTTPHandler to also handle Server-Sent Events as per - the GraphQL SSE Protocol specification. This handler only supports the defined `Distinct connections mode` - due to its statelessness. This implementation is based on the specification as of commit - 80cf75b5952d1a065c95bdbd6a74304c90dbe2c5. For more information see the specification + the GraphQL SSE Protocol specification. This handler only supports the defined + `Distinct connections mode` due to its statelessness. This implementation is based on + the specification as of commit 80cf75b5952d1a065c95bdbd6a74304c90dbe2c5. + For more information see the specification (https://github.com/enisdenjo/graphql-sse/blob/master/PROTOCOL.md) """ diff --git a/tests/asgi/test_sse.py b/tests/asgi/test_sse.py index ad7ed216..05a67257 100644 --- a/tests/asgi/test_sse.py +++ b/tests/asgi/test_sse.py @@ -179,7 +179,7 @@ def test_ping_is_send_sse(sse_client): def test_custom_ping_interval(schema): app = GraphQL( schema, - http_handler=GraphQLHTTPSSEHandler(ping_interval=10), + http_handler=GraphQLHTTPSSEHandler(ping_interval=8), introspection=False, ) sse_client = TestClient(app, headers=SSE_HEADER)