From 6b9d0fa0d45e0ff5a3e49ba47395b8d2fd21863e Mon Sep 17 00:00:00 2001 From: jordan-dr Date: Wed, 18 Jun 2025 09:30:42 -0500 Subject: [PATCH] On main: markasread-mutation --- .../mark_notification_as_read.rb | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 app/graphql/mutations/notifications/mark_notification_as_read.rb diff --git a/app/graphql/mutations/notifications/mark_notification_as_read.rb b/app/graphql/mutations/notifications/mark_notification_as_read.rb new file mode 100644 index 0000000..1774539 --- /dev/null +++ b/app/graphql/mutations/notifications/mark_notification_as_read.rb @@ -0,0 +1,26 @@ +module Mutations + module Notifications + class MarkNotificationAsRead < BaseMutation + graphql_name 'MarkNotificationAsRead' + + # Input argument to indicate which notification to update. + argument :id, ID, required: true + + # The response includes the updated notification and any errors. + field :notification, Types::NotificationType, null: true + field :errors, [String], null: false + + def resolve(id:) + notification = Notification.find_by(id: id) + return { notification: nil, errors: ["Notification not found"] } unless notification + + notification.read = true + if notification.save + { notification: notification, errors: [] } + else + { notification: nil, errors: notification.errors.full_messages } + end + end + end + end + end \ No newline at end of file