debian-mirror-gitlab/app/graphql/mutations/award_emojis/base.rb

42 lines
1.2 KiB
Ruby
Raw Normal View History

2019-09-30 21:07:59 +05:30
# frozen_string_literal: true
module Mutations
module AwardEmojis
class Base < BaseMutation
2021-02-22 17:27:13 +05:30
include ::Mutations::FindsByGid
NOT_EMOJI_AWARDABLE = 'You cannot award emoji to this resource.'
2019-09-30 21:07:59 +05:30
authorize :award_emoji
argument :awardable_id,
2021-01-03 14:25:43 +05:30
::Types::GlobalIDType[::Awardable],
2019-09-30 21:07:59 +05:30
required: true,
2021-02-22 17:27:13 +05:30
description: 'The global ID of the awardable resource'
2019-09-30 21:07:59 +05:30
argument :name,
GraphQL::STRING_TYPE,
required: true,
description: copy_field_description(Types::AwardEmojis::AwardEmojiType, :name)
field :award_emoji,
Types::AwardEmojis::AwardEmojiType,
null: true,
description: 'The award emoji after mutation'
private
2021-02-22 17:27:13 +05:30
# TODO: remove this method when the compatibility layer is removed
# See: https://gitlab.com/gitlab-org/gitlab/-/issues/257883
2019-09-30 21:07:59 +05:30
def find_object(id:)
2021-02-22 17:27:13 +05:30
super(id: ::Types::GlobalIDType[::Awardable].coerce_isolated_input(id))
2019-09-30 21:07:59 +05:30
end
2021-02-22 17:27:13 +05:30
def authorize!(object)
super
raise_resource_not_available_error!(NOT_EMOJI_AWARDABLE) unless object.emoji_awardable?
2019-09-30 21:07:59 +05:30
end
end
end
end