dehaze

Sample use cases for Subscription

The following are a few use cases for using subscription:

Realtime chat applink

If you want to build a realtime chat app, then you can use Space Cloud for various realtime features in your app like:

  • Realtime stream of chat messages
  • Online/offline status of a user
  • Is typing indicator for a user

Example: Subscribe to chat messages:

subscription {
  messages (
    where: {to: {_eq: "user1"}}
  ) @mongo {
    type
    payload {
      _id
      from
      to
      text 
      timestamp
    }
    docId
  }
}

Example: Subscribe to is_typing indicator and status of a user:

subscription {
  users (
    where: {_id: {_eq: "user2"}}
  ) @mongo {
    type
    payload {
      _id
      status
      is_typing
    }
    docId
  }
}

Live score updateslink

Let’s say you want to display the score of a particular game in realtime without polling the database again and again. In this case, you can subscribe to the game score and get notified whenever it’s updated.

subscription {
  games (
    where: {_id: {_eq: "1"}}
  ) @mongo {
    type
    payload {
      score
    }
  }
}

Have a technical question?

Improve the docs!