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