Welcome to mirror list, hosted at ThFree Co, Russian Federation.

base.rb « award_emojis « mutations « graphql « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: df6b883529e5c5b2ad5380bd25a33a614c2971d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# frozen_string_literal: true

module Mutations
  module AwardEmojis
    class Base < BaseMutation
      authorize :award_emoji

      argument :awardable_id,
               ::Types::GlobalIDType[::Awardable],
               required: true,
               description: 'The global id of the awardable resource'

      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

      def find_object(id:)
        # TODO: remove this line when the compatibility layer is removed
        # See: https://gitlab.com/gitlab-org/gitlab/-/issues/257883
        id = ::Types::GlobalIDType[::Awardable].coerce_isolated_input(id)
        GitlabSchema.find_by_gid(id)
      end

      # Called by mutations methods after performing an authorization check
      # of an awardable object.
      def check_object_is_awardable!(object)
        unless object.is_a?(Awardable) && object.emoji_awardable?
          raise Gitlab::Graphql::Errors::ResourceNotAvailable,
                'Cannot award emoji to this resource'
        end
      end
    end
  end
end