Skip to content

Commit

Permalink
format and linting, update requirements.txt in fastapi integration te…
Browse files Browse the repository at this point in the history
…sts 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
  • Loading branch information
danplischke committed Dec 18, 2024
1 parent f2ada34 commit 5a18fc3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions ariadne/asgi/handlers/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 8 additions & 5 deletions ariadne/contrib/sse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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)
"""

Expand Down
2 changes: 1 addition & 1 deletion tests/asgi/test_sse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5a18fc3

Please sign in to comment.