debian-mirror-gitlab/app/graphql/resolvers/group_packages_resolver.rb

37 lines
1.1 KiB
Ruby
Raw Normal View History

2021-04-17 20:07:23 +05:30
# frozen_string_literal: true
2021-06-08 01:23:25 +05:30
# rubocop: disable Graphql/ResolverType
2021-04-17 20:07:23 +05:30
module Resolvers
2021-06-08 01:23:25 +05:30
class GroupPackagesResolver < PackagesBaseResolver
# The GraphQL type is defined in the extended class
argument :sort, Types::Packages::PackageGroupSortEnum,
description: 'Sort packages by this criteria.',
required: false,
default_value: :created_desc
GROUP_SORT_TO_PARAMS_MAP = SORT_TO_PARAMS_MAP.merge({
project_path_desc: { order_by: 'project_path', sort: 'desc' },
project_path_asc: { order_by: 'project_path', sort: 'asc' }
}).freeze
2021-04-17 20:07:23 +05:30
def ready?(**args)
context[self.class] ||= { executions: 0 }
context[self.class][:executions] += 1
raise GraphQL::ExecutionError, "Packages can be requested only for one group at a time" if context[self.class][:executions] > 1
super
end
2021-06-08 01:23:25 +05:30
def resolve(sort:, **filters)
2021-04-17 20:07:23 +05:30
return unless packages_available?
2022-07-16 23:28:13 +05:30
params = filters.merge(GROUP_SORT_TO_PARAMS_MAP.fetch(sort))
params[:preload_pipelines] = false
::Packages::GroupPackagesFinder.new(current_user, object, params).execute
2021-04-17 20:07:23 +05:30
end
end
end
2021-06-08 01:23:25 +05:30
# rubocop: enable Graphql/ResolverType