Skip to main content

Notifications

Notifications consist of activities from other accounts which is related to your account. For example, if someone likes your post, or comments on your post, or shares your post, you will get a notification for that activity. You can use notifications query to get the notifications which can also be filtered by the account it belongs to. Or you can also use accountById query and get the notifications attribute.

Example queries

Get Notifications for an account

Both queries below will result in same data:

query GetNotifications($accountId: String!) {
notifications(
where: { account: { id_eq: $accountId } }
orderBy: activity_date_DESC
limit: 10
) {
activity {
# You can also get other activity data from here
event
date
account {
id
}
}
}
}
query GetNotifications($accountId: String!) {
accountById(id: $accountId) {
notifications(orderBy: activity_date_DESC, limit: 10) {
activity {
# You can also get other activity data from here
event
date
account {
id
}
}
}
}
}
info

If you want to aggregate similar notifications, you can filter the notifications by the aggregated value.

query GetNotifications($accountId: String!) {
notifications(
where: { account: { id_eq: $accountId }, aggregated_eq: true }
orderBy: activity_date_DESC
limit: 10
) {
activity {
# You can also get other activity data from here
aggregated
aggCount

event
date
account {
id
}
}
}
}

This way, you can use the data like below:

Account {activity.account.id} and {activity.aggCount} others liked your post.

Get Feeds Count

You can get the count of the notifications using notificationsConnection query.

query GetNotificationsCount($accountId: String!) {
notificationsConnection(
where: { account: { id_eq: $accountId } }
orderBy: activity_date_DESC
) {
totalCount
}
}
info

One trick you can use to get the unread notifications count is to use notificationsConnection query and filter the notifications to only include activity with date more than the last read date.

query GetNotificationsCount($accountId: String!, $lastReadDate: DateTime!) {
notificationsConnection(
where: {
account: { id_eq: $accountId }
activity: { date_gt: $lastReadDate }
}
orderBy: activity_date_DESC
) {
totalCount
}
}

Example variables:

{
"accountId": "3osmnRNnrcScHsgkTJH1xyBF5kGjpbWHsGrqM31BJpy4vwn8",
"lastReadDate": "2023-01-20T15:56:36.304Z"
}