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 12, 2024
1 parent eeea4f1 commit 0243e1e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 18 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
23 changes: 13 additions & 10 deletions tests_integrations/fastapi/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
#
# This file is autogenerated by pip-compile with Python 3.11
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# pip-compile --output-file=requirements.txt requirements.in
#
annotated-types==0.6.0
annotated-types==0.7.0
# via pydantic
anyio==3.7.1
anyio==4.5.2
# via starlette
fastapi==0.109.1
exceptiongroup==1.2.2
# via anyio
fastapi==0.115.6
# via -r requirements.in
idna==3.7
idna==3.10
# via anyio
pydantic==2.4.2
pydantic==2.10.3
# via fastapi
pydantic-core==2.10.1
pydantic-core==2.27.1
# via pydantic
sniffio==1.3.0
sniffio==1.3.1
# via anyio
starlette==0.35.1
starlette==0.41.3
# via fastapi
typing-extensions==4.8.0
typing-extensions==4.12.2
# via
# anyio
# fastapi
# pydantic
# pydantic-core

0 comments on commit 0243e1e

Please sign in to comment.