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

Add Server-Sent Events transport #2498

Merged
merged 4 commits into from
Jan 7, 2023
Merged

Conversation

jmic
Copy link
Contributor

@jmic jmic commented Jan 6, 2023

Inspired by the feature request #329 and several articles about GraphQL subscriptions via Server-Sent Events, I started to implement an SSE transport that follows this protocol specification and is compatible with the graphql-sse library at the distinct connections mode.
The result is this PR. Besides tests and documentation, I added an SSE option to the chat example as well. Please try it.

Remarks: I didn't want to change the Supports(r *http.Request) functions of the present transports to add a filter that rejects all text/event-stream requests, instead the order in which the transport Supports(r *http.Request) are called is essential. This can of course be solved the other way around if desired.

Many thanks to the developers of gqlgen for this great library!

@jmic jmic marked this pull request as ready for review January 6, 2023 18:41
@coveralls
Copy link

coveralls commented Jan 7, 2023

Coverage Status

Coverage: 75.587% (+0.04%) from 75.547% when pulling ea4c416 on jmic:master into e8d6115 on 99designs:master.

@StevenACoffman StevenACoffman merged commit f0a090d into 99designs:master Jan 7, 2023
@StevenACoffman
Copy link
Collaborator

Thanks so much! This is a great alternative to websockets for subscriptions!

@StevenACoffman StevenACoffman added the SSE Server-Sent Events label Sep 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
SSE Server-Sent Events websocket
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants