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

create.rb « labels « mutations « graphql « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 683d0b445863415334c89434df8b7af57d23a879 (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
50
# frozen_string_literal: true

module Mutations
  module Labels
    class Create < BaseMutation
      include Mutations::ResolvesResourceParent

      graphql_name 'LabelCreate'

      field :label,
            Types::LabelType,
            null: true,
            description: 'The label after mutation.'

      argument :title, GraphQL::STRING_TYPE,
               required: true,
               description: 'Title of the label.'

      argument :description, GraphQL::STRING_TYPE,
               required: false,
               description: 'Description of the label.'

      argument :color, GraphQL::STRING_TYPE,
               required: false,
               default_value: Label::DEFAULT_COLOR,
               see: {
                 'List of color keywords at mozilla.org' =>
                   'https://developer.mozilla.org/en-US/docs/Web/CSS/color_value#Color_keywords'
               },
               description: <<~DESC
                 The color of the label given in 6-digit hex notation with leading '#' sign
                 (for example, `#FFAABB`) or one of the CSS color names.
               DESC

      authorize :admin_label

      def resolve(args)
        parent = authorized_resource_parent_find!(args)
        parent_key = parent.is_a?(Project) ? :project : :group

        label = ::Labels::CreateService.new(args).execute(parent_key => parent)

        {
          label: label.persisted? ? label : nil,
          errors: errors_on_object(label)
        }
      end
    end
  end
end