Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test Subscription in AWS AppSync Console?

I have written the following subscription and mutation code in the App Sync Console:

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
        
       }
}

In the schema, I have defined both the mutation and subscription:

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

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

}

When I test the CreateDoctor mutation in the App Sync console, I get the following response:

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

However, I don't see any logs getting printed for the subscription in AWS App Sync console. The same if I test in the React Native Client app, the subscription event is triggered.

As per AWS docs it possible to test subscription in App Sync console: 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.

Did anyone successfully tested subscriptions in AWS Sync Console?

like image 520
Deep Arora Avatar asked Sep 29 '18 10:09

Deep Arora


1 Answers

It won't work because you try to test mutation and subscription in the same console.
Just open two different consoles. One for mutation and another one for subscription.
First, start subscription in the first console.
Whenever mutation in the second console start, subscription will get invoked in the first console.

like image 93
KoingDev Avatar answered Oct 21 '22 22:10

KoingDev