Commit 5bc51756 authored by Jan Provaznik's avatar Jan Provaznik

Merge branch 'ajk-globalid-mrs' into 'master'

[GraphQL] Merge Requests: use Global-ID scalar

See merge request gitlab-org/gitlab!36118
parents c57cc457 ed6df5bd
......@@ -6,7 +6,7 @@ module Mutations
graphql_name 'MergeRequestSetLabels'
argument :label_ids,
[GraphQL::ID_TYPE],
[::Types::GlobalIDType[Label]],
required: true,
description: <<~DESC
The Label IDs to set. Replaces existing labels by default.
......@@ -23,10 +23,11 @@ module Mutations
merge_request = authorized_find!(project_path: project_path, iid: iid)
project = merge_request.project
label_ids = label_ids
.map { |gid| GlobalID.parse(gid) }
.select(&method(:label_descendant?))
.map(&:model_id) # MergeRequests::UpdateService expects integers
# TODO: remove this line when the compatibility layer is removed:
# See: https://gitlab.com/gitlab-org/gitlab/-/issues/257883
label_ids = label_ids.map { |id| ::Types::GlobalIDType[::Label].coerce_isolated_input(id) }
# MergeRequests::UpdateService expects integers
label_ids = label_ids.compact.map(&:model_id)
attribute_name = case operation_mode
when Types::MutationOperationModeEnum.enum[:append]
......@@ -45,10 +46,6 @@ module Mutations
errors: errors_on_object(merge_request)
}
end
def label_descendant?(gid)
gid&.model_class&.ancestors&.include?(Label)
end
end
end
end
# frozen_string_literal: true
module ResolvesProject
# Accepts EITHER one of
# - full_path: String (see Project#full_path)
# - project_id: GlobalID. Arguments should be typed as: `::Types::GlobalIDType[Project]`
def resolve_project(full_path: nil, project_id: nil)
unless full_path.present? ^ project_id.present?
raise ::Gitlab::Graphql::Errors::ArgumentError, 'Incompatible arguments: projectId, projectPath.'
......
......@@ -8,7 +8,7 @@ module Resolvers
required: false,
description: 'The full-path of the project the authored merge requests should be in. Incompatible with projectId.'
argument :project_id, GraphQL::ID_TYPE,
argument :project_id, ::Types::GlobalIDType[::Project],
required: false,
description: 'The global ID of the project the authored merge requests should be in. Incompatible with projectPath.'
......@@ -50,8 +50,10 @@ module Resolvers
end
def load_project(project_path, project_id)
@project = resolve_project(full_path: project_path, project_id: project_id)
@project = @project.sync if @project.respond_to?(:sync)
# TODO: remove this line when the compatibility layer is removed
# See: https://gitlab.com/gitlab-org/gitlab/-/issues/257883
project_id &&= ::Types::GlobalIDType[::Project].coerce_isolated_input(project_id)
@project = ::Gitlab::Graphql::Lazy.force(resolve_project(full_path: project_path, project_id: project_id))
end
def no_results_possible?(args)
......
......@@ -12258,7 +12258,7 @@ input MergeRequestSetLabelsInput {
"""
The Label IDs to set. Replaces existing labels by default.
"""
labelIds: [ID!]!
labelIds: [LabelID!]!
"""
Changes the operation mode. Defaults to REPLACE.
......@@ -21464,7 +21464,7 @@ type User {
"""
The global ID of the project the authored merge requests should be in. Incompatible with projectPath.
"""
projectId: ID
projectId: ProjectID
"""
The full-path of the project the authored merge requests should be in. Incompatible with projectId.
......@@ -21549,7 +21549,7 @@ type User {
"""
The global ID of the project the authored merge requests should be in. Incompatible with projectPath.
"""
projectId: ID
projectId: ProjectID
"""
The full-path of the project the authored merge requests should be in. Incompatible with projectId.
......
......@@ -33685,7 +33685,7 @@
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "ID",
"name": "LabelID",
"ofType": null
}
}
......@@ -62248,7 +62248,7 @@
"description": "The global ID of the project the authored merge requests should be in. Incompatible with projectPath.",
"type": {
"kind": "SCALAR",
"name": "ID",
"name": "ProjectID",
"ofType": null
},
"defaultValue": null
......@@ -62453,7 +62453,7 @@
"description": "The global ID of the project the authored merge requests should be in. Incompatible with projectPath.",
"type": {
"kind": "SCALAR",
"name": "ID",
"name": "ProjectID",
"ofType": null
},
"defaultValue": null
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment