ariadne
ariadne copied to clipboard
Subscriptions: SSE distinct connection support
This PR introduces a first implementation of subscriptions over Server-Sent Events (SSE) based on the definition in graphql-sse. This provides an alternative to the existing WebSocket support, which is particularly useful in scenarios where WebSocket connections may be restricted (e.g., corporate proxies).
Key Features / Considerations
- SSE Support: Added to the GraphQLHTTPHandler ASGI class, specifically for subscriptions.
- Routing Requirement: The request must include Accept: text/event-stream to be routed to the SSE handler.
- Distinct Connection Support: Currently supports only one subscription per HTTP connection ('distinct connection mode' in the protocol definition). The single connection mode would require state management, which has not been implemented due to Ariadne's stateless design.
- Custom Starlette Response Class: A custom response class for SSE support has been added, based on the implementation in sse-starlette to avoid introducing an additional dependency.
It would be great to get some feedback from you on:
- Does adding SSE support align with Ariadne's goals, given that the protocol is not part of the official GraphQL Over HTTP specification?
- Should SSE be implemented as a separate handler, similar to WebSockets, or can it be integrated into the existing GraphQLHTTPHandler?
- Should there be a way of disabling SSE support?
- How can I best pass configuration options (i.e. send_timeout, ping_interval, headers, encoding) for the 'ServerSentEventResponse' from the 'GraphQLHTTPHandler'? Are parameters / member variables in the init of the 'GraphQLHTTPHandler' acceptable or do you see a cleaner alternative?
- Since the 'subscribe' function returns formatted GraphQL errors as dicts, do you see a more elegant solution of passing them in an 'ExecutionResult' to the 'GrapQLServerSentEvent'? Modifying the 'GrapQLServerSentEvent' to accept dicts, seemed a bit hacky.
Looking forward to your feedback! Thanks in advance!