summaryrefslogtreecommitdiff
path: root/app/graphql/mutations/notes/base.rb
blob: a7198f5fba6aed16b141ad6c4b2198ff0fda72e5 (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
# frozen_string_literal: true

module Mutations
  module Notes
    class Base < BaseMutation
      include Gitlab::Graphql::Authorize::AuthorizeResource

      field :note,
            Types::Notes::NoteType,
            null: true,
            description: 'The note after mutation'

      private

      def find_object(id:)
        GitlabSchema.object_from_id(id)
      end

      def check_object_is_noteable!(object)
        unless object.is_a?(Noteable)
          raise Gitlab::Graphql::Errors::ResourceNotAvailable,
                'Cannot add notes to this resource'
        end
      end

      def check_object_is_note!(object)
        unless object.is_a?(Note)
          raise Gitlab::Graphql::Errors::ResourceNotAvailable,
                'Resource is not a note'
        end
      end
    end
  end
end