Skip to main content

PostGraphile RealtimePostGraphile 实时功能

Every application is different, and no more so than when it comes to their realtime requirements. Some applications are read-heavy, others write-heavy, and others are collaborative and need to put in effort to avoid conflicts between multiple people editing the same things at the same time (e.g. Google Docs).

每个应用各不相同,在实时性需求方面尤其如此。有些应用偏重读操作,有些偏重写操作,还有一些是协同编辑类应用,需要专门投入精力避免多人同时编辑同一内容时发生冲突(例如 Google Docs)。

PostGraphile focusses on customisability and extensibility; rather than giving a one-size-fits-all solution, we provide the baseline subscription functionality in core, and the rest is achieved by adding and combining plugins — the official ones, ones made by the community, or ones you've developed in-house. This enables you to use whatever technology best suits your requirements to provide the realtime features to PostGraphile.

PostGraphile 专注于可定制性与可扩展性。我们没有提供“一刀切”的方案,而是在核心中提供基础的 subscription 能力,其余能力则通过添加和组合插件来实现——无论是官方插件、社区插件,还是你内部自研的插件。这让你能够自由选用最契合自身需求的技术方案,为 PostGraphile 提供实时功能。

SubscriptionsSubscription(订阅)​

"Subscriptions" are a way of having a new message proactively sent to the client automatically whenever a particular event occurs on the server side, such as:

“Subscription”是指每当服务端发生特定事件时,自动向客户端推送新消息的机制,例如:

subscription {
chatMessageAdded(channel: 27) {
id
message
author { id name avatarUrl }
timestamp
}
}

This example subscription would result in a new response whenever a new message is added to channel 27. Note that a normal subscription such as this one only triggers when the event occurs (i.e. chat message added) — it does not trigger when the message is edited, or if the author changes their avatar.

上述 subscription 示例会在频道 27 新增一条消息时返回新的响应。请注意,像这样的常规 subscription 仅在事件发生时(即新增聊天消息时)触发——当消息被编辑或作者更换头像时,它并不会触发。

Subscriptions are part of the latest GraphQL specification, and are well supported by many clients.

Subscription 是最新 GraphQL 规范的一部分,目前已得到众多客户端的良好支持。

Use subscriptions when:

适合使用 subscription 的场景:

  • You need to update your UI based on events happening in the system

    需要根据系统中发生的事件来更新界面

  • You know which events should trigger an update

    明确知道哪些事件应当触发更新

  • Performance and scalability is important to you

    对性能和可扩展性有较高要求

Live queries are not yet available in V5V5 暂未支持实时查询(Live Queries)

Live queries are planned for a future PostGraphile V5 release, but are not yet implemented. If this feature matters to you, please sponsor it or reach out to collaborate.

实时查询(Live Queries)已列入 PostGraphile V5 后续版本的规划,但目前尚未实现。如果这项特性对你至关重要,欢迎赞助该项目或联系我们展开合作。