2020-11-06 03:09:19 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Mutations
|
|
|
|
module Labels
|
|
|
|
class Create < BaseMutation
|
|
|
|
include Mutations::ResolvesResourceParent
|
|
|
|
|
|
|
|
graphql_name 'LabelCreate'
|
|
|
|
|
|
|
|
field :label,
|
|
|
|
Types::LabelType,
|
|
|
|
null: true,
|
2021-08-12 03:10:11 +00:00
|
|
|
description: 'Label after mutation.'
|
2020-11-06 03:09:19 +00:00
|
|
|
|
2021-07-22 21:09:40 +00:00
|
|
|
argument :title, GraphQL::Types::String,
|
2020-11-06 03:09:19 +00:00
|
|
|
required: true,
|
2021-01-07 12:10:24 +00:00
|
|
|
description: 'Title of the label.'
|
2020-11-06 03:09:19 +00:00
|
|
|
|
2021-07-22 21:09:40 +00:00
|
|
|
argument :description, GraphQL::Types::String,
|
2020-11-06 03:09:19 +00:00
|
|
|
required: false,
|
2021-01-07 12:10:24 +00:00
|
|
|
description: 'Description of the label.'
|
2020-11-06 03:09:19 +00:00
|
|
|
|
2021-07-22 21:09:40 +00:00
|
|
|
argument :color, GraphQL::Types::String,
|
2020-11-06 03:09:19 +00:00
|
|
|
required: false,
|
|
|
|
default_value: Label::DEFAULT_COLOR,
|
2021-04-29 21:10:03 +00:00
|
|
|
see: {
|
|
|
|
'List of color keywords at mozilla.org' =>
|
|
|
|
'https://developer.mozilla.org/en-US/docs/Web/CSS/color_value#Color_keywords'
|
|
|
|
},
|
2021-04-22 12:09:49 +00:00
|
|
|
description: <<~DESC
|
|
|
|
The color of the label given in 6-digit hex notation with leading '#' sign
|
2021-04-29 21:10:03 +00:00
|
|
|
(for example, `#FFAABB`) or one of the CSS color names.
|
2021-04-22 12:09:49 +00:00
|
|
|
DESC
|
2020-11-06 03:09:19 +00:00
|
|
|
|
|
|
|
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
|