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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-07-20 15:26:25 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-07-20 15:26:25 +0300
commita09983ae35713f5a2bbb100981116d31ce99826e (patch)
tree2ee2af7bd104d57086db360a7e6d8c9d5d43667a /app/graphql/mutations
parent18c5ab32b738c0b6ecb4d0df3994000482f34bd8 (diff)
Add latest changes from gitlab-org/gitlab@13-2-stable-ee
Diffstat (limited to 'app/graphql/mutations')
-rw-r--r--app/graphql/mutations/alert_management/alerts/todo/create.rb30
-rw-r--r--app/graphql/mutations/alert_management/base.rb5
-rw-r--r--app/graphql/mutations/alert_management/update_alert_status.rb4
-rw-r--r--app/graphql/mutations/award_emojis/add.rb2
-rw-r--r--app/graphql/mutations/award_emojis/remove.rb2
-rw-r--r--app/graphql/mutations/award_emojis/toggle.rb2
-rw-r--r--app/graphql/mutations/base_mutation.rb2
-rw-r--r--app/graphql/mutations/concerns/mutations/resolves_issuable.rb29
-rw-r--r--app/graphql/mutations/container_expiration_policies/update.rb10
-rw-r--r--app/graphql/mutations/issues/set_locked.rb26
-rw-r--r--app/graphql/mutations/jira_import/start.rb9
-rw-r--r--app/graphql/mutations/merge_requests/update.rb39
-rw-r--r--app/graphql/mutations/notes/create/base.rb8
-rw-r--r--app/graphql/mutations/snippets/create.rb26
-rw-r--r--app/graphql/mutations/snippets/update.rb18
-rw-r--r--app/graphql/mutations/todos/mark_all_done.rb6
-rw-r--r--app/graphql/mutations/todos/restore_many.rb8
17 files changed, 193 insertions, 33 deletions
diff --git a/app/graphql/mutations/alert_management/alerts/todo/create.rb b/app/graphql/mutations/alert_management/alerts/todo/create.rb
new file mode 100644
index 00000000000..3dba96e43f1
--- /dev/null
+++ b/app/graphql/mutations/alert_management/alerts/todo/create.rb
@@ -0,0 +1,30 @@
+# frozen_string_literal: true
+
+module Mutations
+ module AlertManagement
+ module Alerts
+ module Todo
+ class Create < Base
+ graphql_name 'AlertTodoCreate'
+
+ def resolve(args)
+ alert = authorized_find!(project_path: args[:project_path], iid: args[:iid])
+ result = ::AlertManagement::Alerts::Todo::CreateService.new(alert, current_user).execute
+
+ prepare_response(result)
+ end
+
+ private
+
+ def prepare_response(result)
+ {
+ alert: result.payload[:alert],
+ todo: result.payload[:todo],
+ errors: result.error? ? [result.message] : []
+ }
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/app/graphql/mutations/alert_management/base.rb b/app/graphql/mutations/alert_management/base.rb
index 7fcca63db51..0de4b9409e4 100644
--- a/app/graphql/mutations/alert_management/base.rb
+++ b/app/graphql/mutations/alert_management/base.rb
@@ -18,6 +18,11 @@ module Mutations
null: true,
description: "The alert after mutation"
+ field :todo,
+ Types::TodoType,
+ null: true,
+ description: "The todo after mutation"
+
field :issue,
Types::IssueType,
null: true,
diff --git a/app/graphql/mutations/alert_management/update_alert_status.rb b/app/graphql/mutations/alert_management/update_alert_status.rb
index d820124d26f..ed61555fbd6 100644
--- a/app/graphql/mutations/alert_management/update_alert_status.rb
+++ b/app/graphql/mutations/alert_management/update_alert_status.rb
@@ -19,8 +19,8 @@ module Mutations
private
def update_status(alert, status)
- ::AlertManagement::UpdateAlertStatusService
- .new(alert, current_user, status)
+ ::AlertManagement::Alerts::UpdateService
+ .new(alert, current_user, status: status)
.execute
end
diff --git a/app/graphql/mutations/award_emojis/add.rb b/app/graphql/mutations/award_emojis/add.rb
index 85f3eb065bb..856fdd5fb14 100644
--- a/app/graphql/mutations/award_emojis/add.rb
+++ b/app/graphql/mutations/award_emojis/add.rb
@@ -3,7 +3,7 @@
module Mutations
module AwardEmojis
class Add < Base
- graphql_name 'AddAwardEmoji'
+ graphql_name 'AwardEmojiAdd'
def resolve(args)
awardable = authorized_find!(id: args[:awardable_id])
diff --git a/app/graphql/mutations/award_emojis/remove.rb b/app/graphql/mutations/award_emojis/remove.rb
index f8a3d0ce390..c654688c6dc 100644
--- a/app/graphql/mutations/award_emojis/remove.rb
+++ b/app/graphql/mutations/award_emojis/remove.rb
@@ -3,7 +3,7 @@
module Mutations
module AwardEmojis
class Remove < Base
- graphql_name 'RemoveAwardEmoji'
+ graphql_name 'AwardEmojiRemove'
def resolve(args)
awardable = authorized_find!(id: args[:awardable_id])
diff --git a/app/graphql/mutations/award_emojis/toggle.rb b/app/graphql/mutations/award_emojis/toggle.rb
index 22eab4812a1..a7714e695d2 100644
--- a/app/graphql/mutations/award_emojis/toggle.rb
+++ b/app/graphql/mutations/award_emojis/toggle.rb
@@ -3,7 +3,7 @@
module Mutations
module AwardEmojis
class Toggle < Base
- graphql_name 'ToggleAwardEmoji'
+ graphql_name 'AwardEmojiToggle'
field :toggledOn, GraphQL::BOOLEAN_TYPE, null: false,
description: 'Indicates the status of the emoji. ' \
diff --git a/app/graphql/mutations/base_mutation.rb b/app/graphql/mutations/base_mutation.rb
index 33f3f33a440..68e7853a9b1 100644
--- a/app/graphql/mutations/base_mutation.rb
+++ b/app/graphql/mutations/base_mutation.rb
@@ -7,6 +7,8 @@ module Mutations
ERROR_MESSAGE = 'You cannot perform write operations on a read-only instance'
+ field_class ::Types::BaseField
+
field :errors, [GraphQL::STRING_TYPE],
null: false,
description: 'Errors encountered during execution of the mutation.'
diff --git a/app/graphql/mutations/concerns/mutations/resolves_issuable.rb b/app/graphql/mutations/concerns/mutations/resolves_issuable.rb
index 13a56f2e709..0fe2d09de6d 100644
--- a/app/graphql/mutations/concerns/mutations/resolves_issuable.rb
+++ b/app/graphql/mutations/concerns/mutations/resolves_issuable.rb
@@ -9,30 +9,31 @@ module Mutations
end
def resolve_issuable(type:, parent_path:, iid:)
- parent = resolve_issuable_parent(type, parent_path)
- key = type == :merge_request ? :iids : :iid
- args = { key => iid.to_s }
+ parent = ::Gitlab::Graphql::Lazy.force(resolve_issuable_parent(type, parent_path))
+ return unless parent.present?
- resolver = issuable_resolver(type, parent, context)
- ready, early_return = resolver.ready?(**args)
-
- return early_return unless ready
-
- resolver.resolve(**args)
+ finder = issuable_finder(type, iids: [iid])
+ Gitlab::Graphql::Loaders::IssuableLoader.new(parent, finder).find_all.first
end
private
- def issuable_resolver(type, parent, context)
- resolver_class = "Resolvers::#{type.to_s.classify.pluralize}Resolver".constantize
-
- resolver_class.single.new(object: parent, context: context, field: nil)
+ def issuable_finder(type, args)
+ case type
+ when :merge_request
+ MergeRequestsFinder.new(current_user, args)
+ when :issue
+ IssuesFinder.new(current_user, args)
+ else
+ raise "Unsupported type: #{type}"
+ end
end
def resolve_issuable_parent(type, parent_path)
+ return unless parent_path.present?
return unless type == :issue || type == :merge_request
- resolve_project(full_path: parent_path) if parent_path.present?
+ resolve_project(full_path: parent_path)
end
end
end
diff --git a/app/graphql/mutations/container_expiration_policies/update.rb b/app/graphql/mutations/container_expiration_policies/update.rb
index c210571c6ca..4bff04bb705 100644
--- a/app/graphql/mutations/container_expiration_policies/update.rb
+++ b/app/graphql/mutations/container_expiration_policies/update.rb
@@ -34,6 +34,16 @@ module Mutations
required: false,
description: copy_field_description(Types::ContainerExpirationPolicyType, :keep_n)
+ argument :name_regex,
+ Types::UntrustedRegexp,
+ required: false,
+ description: copy_field_description(Types::ContainerExpirationPolicyType, :name_regex)
+
+ argument :name_regex_keep,
+ Types::UntrustedRegexp,
+ required: false,
+ description: copy_field_description(Types::ContainerExpirationPolicyType, :name_regex_keep)
+
field :container_expiration_policy,
Types::ContainerExpirationPolicyType,
null: true,
diff --git a/app/graphql/mutations/issues/set_locked.rb b/app/graphql/mutations/issues/set_locked.rb
new file mode 100644
index 00000000000..63a8483067a
--- /dev/null
+++ b/app/graphql/mutations/issues/set_locked.rb
@@ -0,0 +1,26 @@
+# frozen_string_literal: true
+
+module Mutations
+ module Issues
+ class SetLocked < Base
+ graphql_name 'IssueSetLocked'
+
+ argument :locked,
+ GraphQL::BOOLEAN_TYPE,
+ required: true,
+ description: 'Whether or not to lock discussion on the issue'
+
+ def resolve(project_path:, iid:, locked:)
+ issue = authorized_find!(project_path: project_path, iid: iid)
+
+ ::Issues::UpdateService.new(issue.project, current_user, discussion_locked: locked)
+ .execute(issue)
+
+ {
+ issue: issue,
+ errors: errors_on_object(issue)
+ }
+ end
+ end
+ end
+end
diff --git a/app/graphql/mutations/jira_import/start.rb b/app/graphql/mutations/jira_import/start.rb
index 3df26d33711..eda28059272 100644
--- a/app/graphql/mutations/jira_import/start.rb
+++ b/app/graphql/mutations/jira_import/start.rb
@@ -21,12 +21,17 @@ module Mutations
argument :jira_project_name, GraphQL::STRING_TYPE,
required: false,
description: 'Project name of the importer Jira project'
+ argument :users_mapping,
+ [Types::JiraUsersMappingInputType],
+ required: false,
+ description: 'The mapping of Jira to GitLab users'
- def resolve(project_path:, jira_project_key:)
+ def resolve(project_path:, jira_project_key:, users_mapping:)
project = authorized_find!(full_path: project_path)
+ mapping = users_mapping.to_ary.map { |map| map.to_hash }
service_response = ::JiraImport::StartImportService
- .new(context[:current_user], project, jira_project_key)
+ .new(context[:current_user], project, jira_project_key, mapping)
.execute
jira_import = service_response.success? ? service_response.payload[:import_data] : nil
diff --git a/app/graphql/mutations/merge_requests/update.rb b/app/graphql/mutations/merge_requests/update.rb
new file mode 100644
index 00000000000..b583fdfca9b
--- /dev/null
+++ b/app/graphql/mutations/merge_requests/update.rb
@@ -0,0 +1,39 @@
+# frozen_string_literal: true
+
+module Mutations
+ module MergeRequests
+ class Update < Base
+ graphql_name 'MergeRequestUpdate'
+
+ description 'Update attributes of a merge request'
+
+ argument :title, GraphQL::STRING_TYPE,
+ required: false,
+ description: copy_field_description(Types::MergeRequestType, :title)
+
+ argument :target_branch, GraphQL::STRING_TYPE,
+ required: false,
+ description: copy_field_description(Types::MergeRequestType, :target_branch)
+
+ argument :description, GraphQL::STRING_TYPE,
+ required: false,
+ description: copy_field_description(Types::MergeRequestType, :description)
+
+ def resolve(args)
+ merge_request = authorized_find!(args.slice(:project_path, :iid))
+ attributes = args.slice(:title, :description, :target_branch).compact
+
+ ::MergeRequests::UpdateService
+ .new(merge_request.project, current_user, attributes)
+ .execute(merge_request)
+
+ errors = errors_on_object(merge_request)
+
+ {
+ merge_request: merge_request.reset,
+ errors: errors
+ }
+ end
+ end
+ end
+end
diff --git a/app/graphql/mutations/notes/create/base.rb b/app/graphql/mutations/notes/create/base.rb
index cf9f74a63d8..f081eac368e 100644
--- a/app/graphql/mutations/notes/create/base.rb
+++ b/app/graphql/mutations/notes/create/base.rb
@@ -18,6 +18,11 @@ module Mutations
required: true,
description: copy_field_description(Types::Notes::NoteType, :body)
+ argument :confidential,
+ GraphQL::BOOLEAN_TYPE,
+ required: false,
+ description: 'The confidentiality flag of a note. Default is false.'
+
def resolve(args)
noteable = authorized_find!(id: args[:noteable_id])
@@ -40,7 +45,8 @@ module Mutations
def create_note_params(noteable, args)
{
noteable: noteable,
- note: args[:body]
+ note: args[:body],
+ confidential: args[:confidential]
}
end
end
diff --git a/app/graphql/mutations/snippets/create.rb b/app/graphql/mutations/snippets/create.rb
index e1022358c09..89c21486a74 100644
--- a/app/graphql/mutations/snippets/create.rb
+++ b/app/graphql/mutations/snippets/create.rb
@@ -21,7 +21,7 @@ module Mutations
description: 'File name of the snippet'
argument :content, GraphQL::STRING_TYPE,
- required: true,
+ required: false,
description: 'Content of the snippet'
argument :description, GraphQL::STRING_TYPE,
@@ -40,6 +40,10 @@ module Mutations
required: false,
description: 'The paths to files uploaded in the snippet description'
+ argument :files, [Types::Snippets::FileInputType],
+ description: "The snippet files to create",
+ required: false
+
def resolve(args)
project_path = args.delete(:project_path)
@@ -49,13 +53,9 @@ module Mutations
raise_resource_not_available_error!
end
- # We need to rename `uploaded_files` into `files` because
- # it's the expected key param
- args[:files] = args.delete(:uploaded_files)
-
service_response = ::Snippets::CreateService.new(project,
- context[:current_user],
- args).execute
+ context[:current_user],
+ create_params(args)).execute
snippet = service_response.payload[:snippet]
@@ -82,6 +82,18 @@ module Mutations
def can_create_personal_snippet?
Ability.allowed?(context[:current_user], :create_snippet)
end
+
+ def create_params(args)
+ args.tap do |create_args|
+ # We need to rename `files` into `snippet_actions` because
+ # it's the expected key param
+ create_args[:snippet_actions] = create_args.delete(:files)&.map(&:to_h)
+
+ # We need to rename `uploaded_files` into `files` because
+ # it's the expected key param
+ create_args[:files] = create_args.delete(:uploaded_files)
+ end
+ end
end
end
end
diff --git a/app/graphql/mutations/snippets/update.rb b/app/graphql/mutations/snippets/update.rb
index b6bdcb9b67b..8890158b0df 100644
--- a/app/graphql/mutations/snippets/update.rb
+++ b/app/graphql/mutations/snippets/update.rb
@@ -30,12 +30,16 @@ module Mutations
description: 'The visibility level of the snippet',
required: false
+ argument :files, [Types::Snippets::FileInputType],
+ description: 'The snippet files to update',
+ required: false
+
def resolve(args)
snippet = authorized_find!(id: args.delete(:id))
result = ::Snippets::UpdateService.new(snippet.project,
- context[:current_user],
- args).execute(snippet)
+ context[:current_user],
+ update_params(args)).execute(snippet)
snippet = result.payload[:snippet]
{
@@ -47,7 +51,15 @@ module Mutations
private
def ability_name
- "update"
+ 'update'
+ end
+
+ def update_params(args)
+ args.tap do |update_args|
+ # We need to rename `files` into `snippet_actions` because
+ # it's the expected key param
+ update_args[:snippet_actions] = update_args.delete(:files)&.map(&:to_h)
+ end
end
end
end
diff --git a/app/graphql/mutations/todos/mark_all_done.rb b/app/graphql/mutations/todos/mark_all_done.rb
index d30d1bcbcf0..8b53658ddd5 100644
--- a/app/graphql/mutations/todos/mark_all_done.rb
+++ b/app/graphql/mutations/todos/mark_all_done.rb
@@ -10,8 +10,13 @@ module Mutations
field :updated_ids,
[GraphQL::ID_TYPE],
null: false,
+ deprecated: { reason: 'Use todos', milestone: '13.2' },
description: 'Ids of the updated todos'
+ field :todos, [::Types::TodoType],
+ null: false,
+ description: 'Updated todos'
+
def resolve
authorize!(current_user)
@@ -19,6 +24,7 @@ module Mutations
{
updated_ids: map_to_global_ids(updated_ids),
+ todos: Todo.id_in(updated_ids),
errors: []
}
end
diff --git a/app/graphql/mutations/todos/restore_many.rb b/app/graphql/mutations/todos/restore_many.rb
index e95651b232f..c5e2750768c 100644
--- a/app/graphql/mutations/todos/restore_many.rb
+++ b/app/graphql/mutations/todos/restore_many.rb
@@ -14,7 +14,12 @@ module Mutations
field :updated_ids, [GraphQL::ID_TYPE],
null: false,
- description: 'The ids of the updated todo items'
+ description: 'The ids of the updated todo items',
+ deprecated: { reason: 'Use todos', milestone: '13.2' }
+
+ field :todos, [::Types::TodoType],
+ null: false,
+ description: 'Updated todos'
def resolve(ids:)
check_update_amount_limit!(ids)
@@ -24,6 +29,7 @@ module Mutations
{
updated_ids: gids_of(updated_ids),
+ todos: Todo.id_in(updated_ids),
errors: errors_on_objects(todos)
}
end