-
Notifications
You must be signed in to change notification settings - Fork 60
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
X-GraphQL-Event-Stream for being notified that the GraphQL schema has updated #48
Comments
sometimes this feature can come in handy |
@benjie do you have a simple GraphQL server repo that has this implemented for demo purposes? I've been finding it hard to see this implementation actually working |
No; but it is implemented in a separate small file: (Some of this file handles the differences between Koa and Express/Connect, so you may be able to trim a fair bit of it.) That file is called from a middleware with this code: // Setup an event stream so we can broadcast events to graphiql, etc.
if (pathname === '/graphql/stream') {
if (req.headers.accept !== 'text/event-stream') {
res.statusCode = 405;
res.end();
return;
}
setupServerSentEvents(req, res, options);
return;
} The other thing is we have an |
This is a fascinating idea. I really like it. I can also see that it'd be nice to see a standard around this mechanism. I'm thinking it'd be best for this to be post-1.0 release. What do you think? |
Definitely post 1.0 is fine. It’d be optional anyhow. |
@enisdenjo what do you think of adopting this for I would like to implement this for the editor tooling (LSP server and GraphiQL), finally! |
What exactly? Add the header? I don't think it's necessary to integrate this into the library as it can simply be added by the user itself. |
Server-sent events are a perfect mechanism for informing a GraphQL client that the schema has been updated. They don't require the complexity of websockets, and they are uni-directional.
I'm proposing that when introspecting a GraphQL API, if the header
X-GraphQL-Event-Stream
is detected then interested clients should subscribe to thetext/event-stream
at that (relative or absolute) URL and when it receives thechange
event it should automatically re-introspect the GraphQL schema.Not much code should be required to implement this, just something like:
(You may want to throttle the refreshSchema method.)
This has been baked into PostGraphile for a while; I opened an implementation PR to @skevy's GraphiQL.app a good while ago; and @imolorhe has implemented it independently in Altair. Samuel wrote more about it here: https://sirmuel.design/a-better-graphql-developer-experience-with-x-graphql-event-stream-1256aef96f24. We'll probably be implementing it in the new version of GraphiQL too, once we have the plugin system in place.
What are your thoughts?
The text was updated successfully, but these errors were encountered: