Skip to content

Instantly share code, notes, and snippets.

@OlivierJM
Created April 9, 2020 09:46
Show Gist options
  • Save OlivierJM/afcdcdf74fcce088abda939943ab056e to your computer and use it in GitHub Desktop.
Save OlivierJM/afcdcdf74fcce088abda939943ab056e to your computer and use it in GitHub Desktop.
# 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