Files
api/web/components/Notifications/graphql/notification.query.ts
Pujit Mehrotra 7588e0e3cf feat(web): improve notification count syncing (#1148)
## Summary by CodeRabbit

- **New Features**
- Added a refresh button in the notifications sidebar, allowing users to
update notification counts on demand.
- Introduced real-time updates for notification counts through a new
subscription.
- Enhanced GraphQL functionality to support recalculating notification
counts for archived and unread notifications.
  - Added a new mutation for recalculating the notifications overview.
- Implemented a new subscription to receive updates on notification
counts.
- Minor formatting update to the notifications title for improved
readability.
2025-02-19 14:25:04 -05:00

116 lines
2.1 KiB
TypeScript

import { graphql } from '~/composables/gql/gql';
export const NOTIFICATION_FRAGMENT = graphql(/* GraphQL */ `
fragment NotificationFragment on Notification {
id
title
subject
description
importance
link
type
timestamp
formattedTimestamp
}
`);
export const NOTIFICATION_COUNT_FRAGMENT = graphql(/* GraphQL */ `
fragment NotificationCountFragment on NotificationCounts {
total
info
warning
alert
}
`);
export const getNotifications = graphql(/* GraphQL */ `
query Notifications($filter: NotificationFilter!) {
notifications {
id
list(filter: $filter) {
...NotificationFragment
}
}
}
`);
export const archiveNotification = graphql(/* GraphQL */ `
mutation ArchiveNotification($id: String!) {
archiveNotification(id: $id) {
...NotificationFragment
}
}
`);
export const archiveAllNotifications = graphql(/* GraphQL */ `
mutation ArchiveAllNotifications {
archiveAll {
unread {
total
}
archive {
info
warning
alert
total
}
}
}
`);
export const deleteNotification = graphql(/* GraphQL */ `
mutation DeleteNotification($id: String!, $type: NotificationType!) {
deleteNotification(id: $id, type: $type) {
archive {
total
}
}
}
`);
export const deleteArchivedNotifications = graphql(/* GraphQL */ `
mutation DeleteAllNotifications {
deleteArchivedNotifications {
archive {
total
}
unread {
total
}
}
}
`);
export const notificationsOverview = graphql(/* GraphQL */ `
query Overview {
notifications {
id
overview {
unread {
info
warning
alert
total
}
archive {
total
}
}
}
}
`);
/** Re-calculates the notifications overview (i.e. notification counts) */
export const resetOverview = graphql(/* GraphQL */ `
mutation RecomputeOverview {
recalculateOverview {
archive {
...NotificationCountFragment
}
unread {
...NotificationCountFragment
}
}
}
`);