Heartbeat on SSE connections
Component(s)
router
Is your feature request related to a problem? Please describe.
When using WunderGraph SSE subscriptions, connections often pass through intermediate gateways, proxies, or load balancers. These components typically have idle timeout configurations that automatically close seemingly inactive connections after a certain period (e.g., 60-120 seconds).
Describe the solution you'd like
Implement a configurable feature within the WunderGraph Gateway/Router to periodically send lightweight SSE comment heartbeats (:\n\n) on active subscription connections. E.g. like this:
subscriptions:
sse:
enableHeartbeats: true
heartbeatInterval: 30s # send a heartbeat every 30 seconds
Describe alternatives you've considered
No response
Additional context
Here is a mozilla guide about SSE where this is mentioned: https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#event_stream_format
WunderGraph commits fully to Open Source and we want to make sure that we can help you as fast as possible. The roadmap is driven by our customers and we have to prioritize issues that are important to them. You can influence the priority by becoming a customer. Please contact us here.
Hello, you can enable heartbeats but looking at the code, only on accept content-type : "multipart/mixed" and not on "text/event-stream"
https://github.com/wundergraph/graphql-go-tools/blob/master/v2/pkg/engine/resolve/context.go#L37
https://github.com/wundergraph/cosmo/blob/main/router/core/flushwriter.go#L162
also your client needs to be able to handle heartbeats (empty data {} ) https://www.apollographql.com/docs/graphos/routing/operations/subscriptions/multipart-protocol#heartbeats
Hi @jerem1e, thanks for the issue, this is a great suggestion. We'll take a look at implementing this internally.