X-GraphQL-Event-Stream for being notified that the GraphQL schema has updated
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 28/100
- Issue 类型
- 功能
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- graphql, javascript
调研方向
首先查看链接的 GraphiQL.app pull request、Altair 实现和 PostGraphile 参考资料,以比较 X-GraphQL-Event-Stream 提案的处理方式。就行为达成一致并将该决定纳入 GraphQL over HTTP 规范后,即视为完成。
由索引模型根据 Issue 内容生成。
描述
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 the text/event-stream at that (relative or absolute) URL and when it receives the change event it should automatically re-introspect the GraphQL schema.
Not much code should be required to implement this, just something like:
// refreshSchema is a function you provide which triggers re-introspection
const streamUrl = response.headers["x-graphql-event-stream"];
if (streamUrl) {
const endpointUrl = new URL(endpoint);
const streamUrl = new URL(streamUrl, endpointUrl);
if (endpointUrl.host !== streamUrl.host) {
throw new Error(
`Stream and endpoint hosts don't match - '${streamUrl.host}' !== '${endpointUrl.host}'`
);
}
const eventSource = new EventSource(streamUrl);
eventSource.addEventListener("change", refreshSchema, false);
eventSource.addEventListener("open", () => { /* ... */ }, false);
eventSource.addEventListener("error", () => { /* ... */ }, false);
}
(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?
- 主要语言
- JavaScript
- 星标
- 428
- 派生
- 70
- 平均合并
- 11 分钟
- 30 天内合并 PR
- 4
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
graphql/graphql-over-http 的其他 Issue
-
难度 3/5 半天 新手友好度 25/100
graphql/graphql-over-http#446 · 3 条评论 ·
-
难度 5/5 一周以上 新手友好度 25/100
graphql/graphql-over-http#415 ·
-
难度 5/5 一周以上 新手友好度 25/100
graphql/graphql-over-http#392 · 4 个 reaction ·
-
难度 4/5 3-5 天 新手友好度 35/100
graphql/graphql-over-http#242 · 8 条评论 ·
-
难度 5/5 一周以上 新手友好度 35/100
graphql/graphql-over-http#216 · 15 条评论 · 1 个 reaction ·
查看 graphql/graphql-over-http 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
enhancement
难度 1/5 1 小时以内 新手友好度 84/100
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 88/100
-
难度 2/5 1-3 小时 新手友好度 66/100
remotion-dev/remotion#13341 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 70/100
svix/svix-webhooks#2808 ·
维护者通常 1 天内回复