How to monitor the database operation in real-time using a Subscription

Hypi supports real-time monitoring of the update/insertion of the data in the database.

The subscription works on any field of any type for which data was inserted or updated.
The server pushes the update to all the connected clients.
It works only on the upsert mutation.
It works on the subscribed field only and not on other fields.

Suppose you are building a Messaging App with the following data type.

type Message {
  text: String
}

Create a Listener socket by configuring the Subscription on the text field.

subscription {
  subscribe {
    Message {
      text
    }
  }
}
 

Open another tab of the browser and select the same release and instance. It works as a Sender socket.

Execute the upsert on the text field.

mutation {
  upsert(
    values: {
      Message: [
        {
          text: "Check" 
        }
      ]
    }
  ) {
    id
  }
}

The Listener socket receives the notification.

#update1
{
  "data": {
    "subscribe": {
      "Message": {
        "text": "Check"
      }
    }
  },
  "errors": null
}

#update2
{
  "data": {
    "subscribe": {
      "Message": {
        "text": "Check1"
      }
    }
  },
  "errors": null
}

Thus the receiver receives the inserted text or message of the sender.