基于事件的GraphQL订阅

时间:2019-12-16 10:22:23

标签: graphql apollo subscription apollo-server

我正在尝试基于多个突变来触发通知。 我有两种类型的事件:

新活动 新评论

如果执行了其中一种突变,我想触发通知。

我的模式:

input commentInput {

            CommentBody: String!
            EventID: String
            CreatedBy: String
            UpdatedBy: String
            Replies: commentInput
}


input eventInput {

            Title: String!
            EventBody: String
            EventComments: commentInput
            CommentsCount: Int
            Status: String
            Type: String
            EventUID: String
            Location: locationInput
            CreatedBy: String
            createdAt: String 

}

input notificationInput {

        Sender: String 
        Receiver: [String]
        Flight: String
        NotificationType: String
        Message: String
}

extend type Subscription{
    newNotification: notification
}

我的解析器:

Mutation: {

      async AddComment(root, {commentInput}, context, info) {
        await commentModel.create(commentInput)
        .then (doc => {
          NewlyCreatedComment = doc;

       });

         return NewlyCreatedComment;


      async CreateEvent(root, {eventInput}, context, info) {
                   await eventModel.create(eventInput)
                   .then (doc => {
                    NewlyCreatedEvent = doc;

                  });

                    return NewlyCreatedEvent;

                  },

    },

Subscription: {
        newNotification: {
        subscribe: () => pubsub.asyncIterator([NOTIFICATION_ADDED]),
      }
    },

我花了整整一周的时间来寻找解决方案,但是没有运气。

有人可以协助吗?

谢谢

0 个答案:

没有答案