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

base.rb « create « notes « mutations « graphql « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: cf9f74a63d8d17093065c4de3b57faca67e8dc18 (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
43
44
45
46
47
48
49
# frozen_string_literal: true

module Mutations
  module Notes
    module Create
      # This is a Base class for the Note creation Mutations and is not
      # mounted as a GraphQL mutation itself.
      class Base < Mutations::Notes::Base
        authorize :create_note

        argument :noteable_id,
                  GraphQL::ID_TYPE,
                  required: true,
                  description: 'The global id of the resource to add a note to'

        argument :body,
                  GraphQL::STRING_TYPE,
                  required: true,
                  description: copy_field_description(Types::Notes::NoteType, :body)

        def resolve(args)
          noteable = authorized_find!(id: args[:noteable_id])

          check_object_is_noteable!(noteable)

          note = ::Notes::CreateService.new(
            noteable.project,
            current_user,
            create_note_params(noteable, args)
          ).execute

          {
            note: (note if note.persisted?),
            errors: errors_on_object(note)
          }
        end

        private

        def create_note_params(noteable, args)
          {
            noteable: noteable,
            note: args[:body]
          }
        end
      end
    end
  end
end