Skip to main content

Notification Type

The Notification type represents notifications sent to users about tracker events and status changes.

Type Definition​

"""
Notification type for user notifications
"""
type Notification {
"""
Unique identifier for the notification.
"""
id: ID!

"""
Notification message content.
"""
message: String!

"""
Status of the notification.
"""
status: String!

"""
Whether the notification has been read.
"""
read: Boolean!

"""
When the notification was created.
"""
createdAt: DateTime!

"""
The tracker this notification is about.
"""
tracker: Tracker
}

Fields​

FieldTypeDescription
idID!Required. Unique identifier
messageString!Required. Notification message content
statusString!Required. Status of the notification
readBoolean!Required. Whether it has been read
createdAtDateTime!Required. Creation timestamp
trackerTrackerOptional. Associated tracker

Notification Preferences​

Users can configure how they receive notifications:

"""
Notification preferences type
"""
type NotificationPreferences {
"""
Whether to receive email notifications.
"""
email: Boolean!

"""
Whether to receive UI notifications.
"""
ui: Boolean!
}

"""
Input type for updating notification preferences
"""
input NotificationPreferencesInput {
"""
Whether to receive email notifications.
"""
email: Boolean!

"""
Whether to receive UI notifications.
"""
ui: Boolean!
}

User Extensions​

The User type is extended with notification-related fields:

extend type User {
"""
User's notification preferences.
"""
notificationPreferences: NotificationPreferences!

"""
List of notifications for the user.
"""
notifications(read: Boolean): [Notification!]!

"""
Count of unread notifications.
"""
unreadNotificationCount: Int!

"""
List of trackers the user is subscribed to.
"""
trackerSubscriptions: [Tracker!]!
}

Example Queries​

Get User Notifications​

query GetNotifications {
notifications(read: false) {
id
message
status
createdAt
tracker {
id
name
currentStatus
}
}

unreadNotificationCount
}

Get User Notification Preferences​

query GetNotificationPreferences {
me {
notificationPreferences {
email
ui
}
trackerSubscriptions {
id
name
}
}
}

Example Mutations​

Mark Notification as Read​

mutation MarkAsRead {
markNotificationAsRead(id: "123")
}

Update Notification Preferences​

mutation UpdatePreferences {
updateNotificationPreferences(input: { email: true, ui: true })
}

Subscribe to Tracker Notifications​

mutation SubscribeToTracker {
subscribeToTrackerNotifications(trackerId: "456")
}

Notification System​

The notification system works as follows:

  1. Generation

    • Notifications are generated by system events
    • Common triggers include status changes, geofence events, and system alerts
    • Each notification is associated with a specific tracker and user
  2. Delivery

    • Notifications are delivered based on user preferences
    • UI notifications appear in the application interface
    • Email notifications are sent to the user's email address (if enabled)
  3. Management

    • Users can mark notifications as read
    • Users can subscribe/unsubscribe from specific trackers
    • Notification preferences control delivery methods

Real-time Updates​

Notifications are integrated with the Socket.IO system:

  1. When a notification is created, it's sent to subscribed clients in real-time
  2. The client can update its UI immediately without polling
  3. This provides instant feedback for important events like status changes

Best Practices​

  1. Subscription Management

    • Subscribe only to relevant trackers
    • Consider batch operations for managing multiple subscriptions
  2. Notification Handling

    • Regularly mark notifications as read
    • Use the unread count for UI indicators
    • Filter notifications by read status when appropriate
  3. Preference Configuration

    • Set email notifications only for critical events
    • Use UI notifications for regular updates
  • User
  • Tracker
  • DateTime (Built-in scalar type for ISO 8601 dates)
  • notifications
  • unreadNotificationCount
  • markNotificationAsRead
  • markAllNotificationsAsRead
  • subscribeToTrackerNotifications
  • unsubscribeFromTrackerNotifications
  • updateNotificationPreferences