Created
April 9, 2020 09:46
-
-
Save OlivierJM/afcdcdf74fcce088abda939943ab056e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
module Mutations | |
module Message | |
# Updating message for the user | |
class MessageUpdate < BaseMutation | |
argument :id, ID, required: true | |
field :message, Types::MessageType, null: true | |
def resolve(id:) | |
message = ::Message.find(id) | |
return { message: message } if message.update(is_read: true) | |
raise GraphQL::ExecutionError, message.errors.full_messages | |
end | |
# TODO: Better auth here | |
def authorized?(_id) | |
current_user = context[:current_user] | |
raise GraphQL::ExecutionError, 'Unauthorized' unless current_user&.admin? | |
true | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment