【问题标题】:How to run Graphql subsciptions with type-graphql and aws-lambda-graphql如何使用 type-graphql 和 aws-lambda-graphql 运行 Graphql 订阅
【发布时间】:2021-03-30 20:29:24
【问题描述】:

您好,我设法发布了数据,但我正在为订阅而苦苦挣扎,这是我的代码

  Subscription,
  Root,
  ResolverFilterData
} from 'type-graphql';

import { DynamoDBEventStore, PubSub } from 'aws-lambda-graphql';
import { awsClient } from '../../config/database';
import { Notification, NotificationPayload } from './notification.type';
const eventStore = new DynamoDBEventStore({
  dynamoDbClient: awsClient
});
const pubSub = new PubSub({ eventStore });

以及订阅:

  @Subscription({
    subscribe: (rootValue, args, context, info) => {
      return context.pubSub.subscribe('NEW_MESSAGE')(rootValue.message);
    }
  })
  normalSubs(@Root() { id, message }: NotificationPayload): Notification {
    return { id, message, date: new Date() };
  }

【问题讨论】:

    标签: aws-lambda amazon-dynamodb typegraphql


    【解决方案1】:

    您需要通过网络套接字连接sample listener to the Subscription为您的订阅设置一个监听器

    监听器设置成功后,您可以将消息发布到主题,订阅者将收到发送到相应主题listener receives the message subscribed to a specific topic的消息

    【讨论】:

      猜你喜欢
      • 2019-09-27
      • 2022-09-29
      • 2017-09-01
      • 2020-11-17
      • 2021-01-14
      • 2019-07-14
      • 2017-09-19
      • 2019-12-02
      • 2021-10-09
      相关资源
      最近更新 更多