2021-01-29 00:20:46 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Mutations
|
|
|
|
module Labels
|
|
|
|
class Create < BaseMutation
|
|
|
|
include Mutations::ResolvesResourceParent
|
|
|
|
|
|
|
|
graphql_name 'LabelCreate'
|
|
|
|
|
|
|
|
field :label,
|
|
|
|
Types::LabelType,
|
|
|
|
null: true,
|
2021-10-27 15:23:28 +05:30
|
|
|
description: 'Label after mutation.'
|
2021-01-29 00:20:46 +05:30
|
|
|
|
2021-10-27 15:23:28 +05:30
|
|
|
argument :title, GraphQL::Types::String,
|
2021-01-29 00:20:46 +05:30
|
|
|
required: true,
|
2021-03-08 18:12:59 +05:30
|
|
|
description: 'Title of the label.'
|
2021-01-29 00:20:46 +05:30
|
|
|
|
2021-10-27 15:23:28 +05:30
|
|
|
argument :description, GraphQL::Types::String,
|
2021-01-29 00:20:46 +05:30
|
|
|
required: false,
|
2021-03-08 18:12:59 +05:30
|
|
|
description: 'Description of the label.'
|
2021-01-29 00:20:46 +05:30
|
|
|
|
2021-10-27 15:23:28 +05:30
|
|
|
argument :color, GraphQL::Types::String,
|
2021-01-29 00:20:46 +05:30
|
|
|
required: false,
|
|
|
|
default_value: Label::DEFAULT_COLOR,
|
2021-06-08 01:23:25 +05:30
|
|
|
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
|
2021-01-29 00:20:46 +05:30
|
|
|
|
|
|
|
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
|