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

Đang mở
#401 1 bình luận 1 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
38/100
Loại issue
Tài liệu
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
graphql, javascript
Lĩnh vực
api, documentation

Hướng nghiên cứu

Bắt đầu bằng cách tìm tài liệu về subscription tùy chỉnh và các ví dụ hiện có về @pgSubscription và currentUserTopicFromContext. Tài liệu hóa initialEvent, bao gồm chữ ký hàm của nó và ví dụ thiết lập kết nối được cung cấp; hoàn thành khi người đọc có thể hiểu cách cung cấp nó và đối tượng được trả về kiểm soát điều gì.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
SCSS
Star
27
Fork
124
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

  • Không có Dockerfile hay tệp Docker Compose
  • Có mẫu pull request
  • Không có hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của graphile/graphile.github.io

Tất cả issue của graphile/graphile.github.io

Issue tương tự

Thêm issue về Backend & API Design

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.