跳转到内容

GraphQL 订阅

GraphQL 订阅是一种 Web 套接字连接,每当上游发生观察到的事件时,客户端都会收到带有数据的事件。

所有项目表都可以使用 wss 协议通过项目端点接收订阅。

wss://archie-core.archie-platform.com/subscriptions?project_id=projectID

为了举例说明,让我们考虑一个场景,其中存在一个名为 students 的表,该表具有预期的字段和关系,如 firstNameemail

要创建新的订阅配置,您可以使用 system { createSubscription } 变更。此操作定义订阅规则,包括要监视哪些表以及哪些操作(创建、更新、删除)应触发事件。

mutation createNewSubscription($input: SubscriptionInput!) {
system {
createSubscription(input: $input) {
id
active
name
}
}
}
{
"input": {
"name": "students_all",
"description": "Subscription all operations",
"active": true,
"tables": [
{
"table": "students",
"operations": ["UPDATE", "CREATE", "DELETE"],
"fields": ["first_name", "email"]
}
]
}
}