debian-mirror-gitlab/app/graphql/resolvers/design_management/versions_resolver.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

67 lines
1.8 KiB
Ruby
Raw Normal View History

2020-05-24 23:13:21 +05:30
# frozen_string_literal: true
module Resolvers
module DesignManagement
class VersionsResolver < BaseResolver
type Types::DesignManagement::VersionType.connection_type, null: false
alias_method :design_or_collection, :object
2021-01-29 00:20:46 +05:30
VersionID = ::Types::GlobalIDType[::DesignManagement::Version]
2021-10-27 15:23:28 +05:30
argument :earlier_or_equal_to_sha, GraphQL::Types::String,
2020-05-24 23:13:21 +05:30
as: :sha,
required: false,
2021-10-27 15:23:28 +05:30
description: 'SHA256 of the most recent acceptable version.'
2020-05-24 23:13:21 +05:30
2021-01-29 00:20:46 +05:30
argument :earlier_or_equal_to_id, VersionID,
2020-05-24 23:13:21 +05:30
as: :id,
required: false,
2021-10-27 15:23:28 +05:30
description: 'Global ID of the most recent acceptable version.'
2020-05-24 23:13:21 +05:30
# This resolver has a custom singular resolver
def self.single
::Resolvers::DesignManagement::VersionInCollectionResolver
end
2022-07-16 23:28:13 +05:30
def resolve(id: nil, sha: nil)
version = cutoff(id, sha)
2020-05-24 23:13:21 +05:30
raise ::Gitlab::Graphql::Errors::ResourceNotAvailable, 'cutoff not found' unless version.present?
if version == :unconstrained
find
else
find(earlier_or_equal_to: version)
end
end
private
# Find the most recent version that the client will accept
2022-07-16 23:28:13 +05:30
def cutoff(id, sha)
2020-05-24 23:13:21 +05:30
if sha.present? || id.present?
specific_version(id, sha)
else
:unconstrained
end
end
2021-01-29 00:20:46 +05:30
def specific_version(gid, sha)
2020-05-24 23:13:21 +05:30
find(sha: sha, version_id: gid&.model_id).first
end
def find(**params)
::DesignManagement::VersionsFinder
.new(design_or_collection, current_user, params)
.execute
2021-06-08 01:23:25 +05:30
.with_author
2020-05-24 23:13:21 +05:30
end
2021-01-29 00:20:46 +05:30
def by_id(gid)
::Gitlab::Graphql::Lazy.force(GitlabSchema.find_by_gid(gid))
2020-05-24 23:13:21 +05:30
end
end
end
end