2020-05-24 23:13:21 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Resolvers
|
|
|
|
module DesignManagement
|
|
|
|
class VersionInCollectionResolver < BaseResolver
|
|
|
|
include Gitlab::Graphql::Authorize::AuthorizeResource
|
|
|
|
|
|
|
|
type Types::DesignManagement::VersionType, null: true
|
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
requires_argument!
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
authorize :read_design
|
|
|
|
|
|
|
|
alias_method :collection, :object
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
VersionID = ::Types::GlobalIDType[::DesignManagement::Version]
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
argument :sha, GraphQL::STRING_TYPE,
|
|
|
|
required: false,
|
2021-03-08 18:12:59 +05:30
|
|
|
description: "The SHA256 of a specific version."
|
2021-01-29 00:20:46 +05:30
|
|
|
argument :id, VersionID,
|
|
|
|
as: :version_id,
|
2020-05-24 23:13:21 +05:30
|
|
|
required: false,
|
2021-03-08 18:12:59 +05:30
|
|
|
description: 'The Global ID of the version.'
|
2020-05-24 23:13:21 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
def resolve(version_id: nil, sha: nil)
|
|
|
|
# TODO: remove this line when the compatibility layer is removed
|
|
|
|
# See: https://gitlab.com/gitlab-org/gitlab/-/issues/257883
|
|
|
|
version_id &&= VersionID.coerce_isolated_input(version_id)
|
2020-05-24 23:13:21 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
check_args(version_id, sha)
|
2020-05-24 23:13:21 +05:30
|
|
|
|
|
|
|
::DesignManagement::VersionsFinder
|
2021-01-29 00:20:46 +05:30
|
|
|
.new(collection, current_user, sha: sha, version_id: version_id&.model_id)
|
2020-05-24 23:13:21 +05:30
|
|
|
.execute
|
|
|
|
.first
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.single
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def check_args(id, sha)
|
|
|
|
return if id.present? || sha.present?
|
|
|
|
|
|
|
|
raise ::Gitlab::Graphql::Errors::ArgumentError, 'one of id or sha is required'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|