Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support subscriptions using SSE (Server-Sent Events) as alternative to websockets #476

Open
cmeeren opened this issue Apr 10, 2024 · 1 comment

Comments

@cmeeren
Copy link

cmeeren commented Apr 10, 2024

I propose that support is added for the GraphQL over Server-Sent Events Protocol, like HotChocolate has.

This simplifies authentication, since you can use the same authentication as normal HTTP requests.

I haven't looked at the GraphQL-specific parts of it, but SSE it itself technically very simple. Here is a demo:

Get(
    "/sse-test",
    RequestDelegate(fun (ctx: HttpContext) ->
        task {
            ctx.Response.Headers.Add("Content-Type", "text/event-stream")

            while not ctx.RequestAborted.IsCancellationRequested do
                do!
                    ctx.Response.WriteAsync(
                        $"data: {DateTime.Now}"
                    )

                do! ctx.Response.WriteAsync("\n\n")
                do! ctx.Response.Body.FlushAsync()
                do! Async.Sleep(1000)
        }
    )
)

You can test it by simply opening that endpoint in a browser (at least Edge works fine).

Related: #460

@cmeeren cmeeren changed the title Support subscriptions using SSE (Server-Sent Events) instead of websockets Support subscriptions using SSE (Server-Sent Events) as alternative to websockets Apr 10, 2024
@xperiandri
Copy link
Collaborator

Good idea, why not!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants