Documentation Improvement by adding an example and description for initialEvent for custom subscriptions

未關閉
#401 1 則留言 1 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
38/100
Issue 類型
文件
描述清晰度
基本清楚
活躍度
停滯
技術堆疊
graphql, javascript
領域
api, documentation

研究方向

首先找到自訂 subscription 文件,以及現有的 @pgSubscription 和 currentUserTopicFromContext 範例。為 initialEvent 撰寫文件,包括其函式簽章和所示的連線建立範例;當讀者能夠理解如何提供它,以及傳回的物件控制什麼時,即可視為完成。

由索引模型根據 Issue 內容生成。

描述

help wanted quick

Over the last few days I've been trying to create a custom subscription that sends the data directly after connecting. However, there is no example in the documentation of an initial event or any evidence that there is an interface for it. The default behavior of an custom subscription is that it only fetches the previous data and the new data (on insert) after an event was been triggered on the database side.

I only got the information about the initialEvent from the discord server:

  • By providing the initialEvent argument to @pgSubscription(...) in typeDefs you can pass to it the function which you want to be executed on connection establishment the same way as currentUserTopicFromContext from the docs to topic:
currentUserUpdated: UserSubscriptionPayload @pgSubscription(topic: ${embed(
   currentUserTopicFromContext,
)})

with initialEvent:

currentUserUpdated: UserSubscriptionPayload @pgSubscription(topic: ${embed(
   currentUserTopicFromContext,
)}, initialEvent: ${embed(
   onInitialEvent, //the function that you want to be executed
)})

The function that you want to be executed in initialEvent has the same structure as currentUserTopicFromContext:

const onInitialEvent = async (_args, context, _resolveInfo) => {
   // do something
  return {}; // return an object 
}

Now because returning an empty object was the solution for my problem (get already existing data on connection establishment), I didn't dig any deeper on what arguments I can give to the object to control the behavior and what operations can be done in the initialEvent function. This can be added additionally to the documentation.

Adding description for initialEvent and examples for it to the documentation to make it clear that something like that exists would help allot.

主要語言
SCSS
星號
27
分支
124
PR 合併指標
30 天內沒有已合併 PR

環境準備

  • 沒有 Dockerfile 或 Docker Compose 檔案
  • 有 Pull Request 範本
  • 沒有貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

graphile/graphile.github.io 的其他 Issue

查看 graphile/graphile.github.io 的全部 Issue

相似的 Issue

更多 Backend & API Design Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。