summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorBob Van Landuyt <bob@vanlanduyt.co>2018-07-10 16:19:45 +0200
committerBob Van Landuyt <bob@vanlanduyt.co>2018-07-25 18:37:12 +0200
commit3bcb04f100f5e982379fbeae37a30a191581d1ef (patch)
treee01065b8a6728bcc75af16166baafcbddd1a6cf5 /app
parent9fe58f5a23f2960f666c4d641b463c744138d29c (diff)
downloadgitlab-ce-3bcb04f100f5e982379fbeae37a30a191581d1ef.tar.gz
Add mutation toggling WIP state of merge requests
This is mainly the setup of mutations for GraphQL. Including authorization and basic return type-structure.
Diffstat (limited to 'app')
-rw-r--r--app/graphql/gitlab_schema.rb2
-rw-r--r--app/graphql/mutations/base_mutation.rb13
-rw-r--r--app/graphql/mutations/concerns/mutations/resolves_project.rb13
-rw-r--r--app/graphql/mutations/merge_requests/base.rb32
-rw-r--r--app/graphql/mutations/merge_requests/set_wip.rb35
-rw-r--r--app/graphql/types/mutation_type.rb6
6 files changed, 99 insertions, 2 deletions
diff --git a/app/graphql/gitlab_schema.rb b/app/graphql/gitlab_schema.rb
index d9f9129d08a..8755a1a62e7 100644
--- a/app/graphql/gitlab_schema.rb
+++ b/app/graphql/gitlab_schema.rb
@@ -7,5 +7,5 @@ class GitlabSchema < GraphQL::Schema
query(Types::QueryType)
default_max_page_size 100
- # mutation(Types::MutationType)
+ mutation(Types::MutationType)
end
diff --git a/app/graphql/mutations/base_mutation.rb b/app/graphql/mutations/base_mutation.rb
new file mode 100644
index 00000000000..eb03dfe1624
--- /dev/null
+++ b/app/graphql/mutations/base_mutation.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+module Mutations
+ class BaseMutation < GraphQL::Schema::RelayClassicMutation
+ field :errors, [GraphQL::STRING_TYPE],
+ null: false,
+ description: "Reasons why the mutation failed."
+
+ def current_user
+ context[:current_user]
+ end
+ end
+end
diff --git a/app/graphql/mutations/concerns/mutations/resolves_project.rb b/app/graphql/mutations/concerns/mutations/resolves_project.rb
new file mode 100644
index 00000000000..0dd1f264a52
--- /dev/null
+++ b/app/graphql/mutations/concerns/mutations/resolves_project.rb
@@ -0,0 +1,13 @@
+module Mutations
+ module ResolvesProject
+ extend ActiveSupport::Concern
+
+ def resolve_project(full_path:)
+ resolver.resolve(full_path: full_path)
+ end
+
+ def resolver
+ Resolvers::ProjectResolver.new(object: nil, context: context)
+ end
+ end
+end
diff --git a/app/graphql/mutations/merge_requests/base.rb b/app/graphql/mutations/merge_requests/base.rb
new file mode 100644
index 00000000000..2149e72e2df
--- /dev/null
+++ b/app/graphql/mutations/merge_requests/base.rb
@@ -0,0 +1,32 @@
+module Mutations
+ module MergeRequests
+ class Base < BaseMutation
+ include Gitlab::Graphql::Authorize::AuthorizeResource
+ include Mutations::ResolvesProject
+
+ argument :project_path, GraphQL::ID_TYPE,
+ required: true,
+ description: "The project the merge request to mutate is in"
+
+ argument :iid, GraphQL::ID_TYPE,
+ required: true,
+ description: "The iid of the merge request to mutate"
+
+ field :merge_request,
+ Types::MergeRequestType,
+ null: true,
+ description: "The merge request after mutation"
+
+ authorize :update_merge_request
+
+ private
+
+ def find_object(project_path:, iid:)
+ project = resolve_project(full_path: project_path)
+ resolver = Resolvers::MergeRequestResolver.new(object: project, context: context)
+
+ resolver.resolve(iid: iid)
+ end
+ end
+ end
+end
diff --git a/app/graphql/mutations/merge_requests/set_wip.rb b/app/graphql/mutations/merge_requests/set_wip.rb
new file mode 100644
index 00000000000..a2aa0c84ee4
--- /dev/null
+++ b/app/graphql/mutations/merge_requests/set_wip.rb
@@ -0,0 +1,35 @@
+# frozen_string_literal: true
+
+module Mutations
+ module MergeRequests
+ class SetWip < Base
+ graphql_name 'MergeRequestSetWip'
+
+ argument :wip,
+ GraphQL::BOOLEAN_TYPE,
+ required: true,
+ description: <<~DESC
+ Whether or not to set the merge request as a WIP.
+ DESC
+
+ def resolve(project_path:, iid:, wip: nil)
+ merge_request = authorized_find!(project_path: project_path, iid: iid)
+ project = merge_request.project
+
+ ::MergeRequests::UpdateService.new(project, current_user, wip_event: wip_event(merge_request, wip))
+ .execute(merge_request)
+
+ {
+ merge_request: merge_request,
+ errors: merge_request.errors.full_messages
+ }
+ end
+
+ private
+
+ def wip_event(merge_request, wip)
+ wip ? 'wip' : 'unwip'
+ end
+ end
+ end
+end
diff --git a/app/graphql/types/mutation_type.rb b/app/graphql/types/mutation_type.rb
index 06ed91c1658..2b4ef299296 100644
--- a/app/graphql/types/mutation_type.rb
+++ b/app/graphql/types/mutation_type.rb
@@ -1,7 +1,11 @@
+# frozen_string_literal: true
+
module Types
class MutationType < BaseObject
+ include Gitlab::Graphql::MountMutation
+
graphql_name "Mutation"
- # TODO: Add Mutations as fields
+ mount_mutation Mutations::MergeRequests::SetWip
end
end