diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-18 10:34:06 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-18 10:34:06 +0000 |
commit | 859a6fb938bb9ee2a317c46dfa4fcc1af49608f0 (patch) | |
tree | d7f2700abe6b4ffcb2dcfc80631b2d87d0609239 /app/graphql/mutations/boards/lists/base_create.rb | |
parent | 446d496a6d000c73a304be52587cd9bbc7493136 (diff) | |
download | gitlab-ce-859a6fb938bb9ee2a317c46dfa4fcc1af49608f0.tar.gz |
Add latest changes from gitlab-org/gitlab@13-9-stable-eev13.9.0-rc42
Diffstat (limited to 'app/graphql/mutations/boards/lists/base_create.rb')
-rw-r--r-- | app/graphql/mutations/boards/lists/base_create.rb | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/app/graphql/mutations/boards/lists/base_create.rb b/app/graphql/mutations/boards/lists/base_create.rb new file mode 100644 index 00000000000..a21c7feece3 --- /dev/null +++ b/app/graphql/mutations/boards/lists/base_create.rb @@ -0,0 +1,55 @@ +# frozen_string_literal: true + +module Mutations + module Boards + module Lists + class BaseCreate < BaseMutation + argument :backlog, GraphQL::BOOLEAN_TYPE, + required: false, + description: 'Create the backlog list.' + + argument :label_id, ::Types::GlobalIDType[::Label], + required: false, + description: 'Global ID of an existing label.' + + def ready?(**args) + if args.slice(*mutually_exclusive_args).size != 1 + arg_str = mutually_exclusive_args.map { |x| x.to_s.camelize(:lower) }.join(' or ') + raise Gitlab::Graphql::Errors::ArgumentError, "one and only one of #{arg_str} is required" + end + + super + end + + def resolve(**args) + board = authorized_find!(id: args[:board_id]) + params = create_list_params(args) + + response = create_list(board, params) + + { + list: response.success? ? response.payload[:list] : nil, + errors: response.errors + } + end + + private + + def create_list(board, params) + raise NotImplementedError + end + + def create_list_params(args) + params = args.slice(*mutually_exclusive_args).with_indifferent_access + params[:label_id] &&= ::GitlabSchema.parse_gid(params[:label_id], expected_type: ::Label).model_id + + params + end + + def mutually_exclusive_args + [:backlog, :label_id] + end + end + end + end +end |