如何在 AWS AppSync 控制台中测试订阅?

How to test Subscription in AWS AppSync Console?

我在 App Sync 控制台中编写了以下订阅和变异代码:

subscription SubscribeToCreateDoctor {
  
  subscribeToCreateDoctor {
       id
       name
  }
     
}

mutation CreateDoctor {

      createDoctor(
        input: {
          name: "sanju", 
          registrationNo: "some value",
          speciality: "some value",
          profilePic: "some value",
          placeOfResidence: "some value", 
          medicalCenter: "some value",
          direction: "some value",
          municipality: "some value",
          isAvailable: "No",
        }) {
         id
         name
        
       }
}

在架构中,我定义了变更和订阅:

type Subscription {
    
    subscribeToCreateDoctor: Doctor
        @aws_subscribe(mutations: ["createDoctor"])
}

type Mutation {
    
    createDoctor(input: CreateDoctorInput!): Doctor

}

当我在 App Sync 控制台中测试 CreateDoctor 突变时,我得到以下响应:

{
  "data": {
    "createDoctor": {
      "id": "5845c994-2389-4df9-8a3e-e13dc24b0153",
      "name": "Sanju"
    }
  }
}

但是,我没有看到在 AWS App Sync 控制台中为订阅打印任何日志。如果我在 React Native Client 应用程序中测试,订阅事件也会被触发。

根据 AWS 文档,可以在 App Sync 控制台中测试订阅: https://docs.aws.amazon.com/appsync/latest/devguide/test-debug-resolvers.html

AWS AppSync lets you log errors and full request details using Amazon CloudWatch. Additionally, you can use the AWS AppSync console to test GraphQL queries, mutations, and subscriptions and live stream log data for each request back into the query editor to debug in real time. For subscriptions, the logs display connection-time information.

有人在 AWS 同步控制台中成功测试过订阅吗?

它不会工作,因为您尝试在同一个控制台中测试变更和订阅。
只需打开两个不同的控制台。一个用于 mutation,另一个用于 subscription
首先,在第一个控制台中开始订阅。
每当第二个控制台中的突变开始时,订阅将在第一个控制台。