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

68 lines
1.9 KiB
Ruby
Raw Normal View History

2019-09-04 21:01:54 +05:30
# frozen_string_literal: true
module Resolvers
class NamespaceProjectsResolver < BaseResolver
argument :include_subgroups, GraphQL::BOOLEAN_TYPE,
required: false,
default_value: false,
2021-03-08 18:12:59 +05:30
description: 'Include also subgroup projects.'
2019-09-04 21:01:54 +05:30
2020-11-24 15:15:51 +05:30
argument :search, GraphQL::STRING_TYPE,
required: false,
default_value: nil,
2021-03-08 18:12:59 +05:30
description: 'Search project with most similar names or paths.'
2020-11-24 15:15:51 +05:30
argument :sort, Types::Projects::NamespaceProjectSortEnum,
required: false,
default_value: nil,
2021-03-08 18:12:59 +05:30
description: 'Sort projects by this criteria.'
2020-11-24 15:15:51 +05:30
2021-04-17 20:07:23 +05:30
argument :ids, [GraphQL::ID_TYPE],
required: false,
default_value: nil,
description: 'Filter projects by IDs.'
2019-09-04 21:01:54 +05:30
type Types::ProjectType, null: true
2021-04-17 20:07:23 +05:30
def resolve(args)
2019-09-04 21:01:54 +05:30
# The namespace could have been loaded in batch by `BatchLoader`.
# At this point we need the `id` or the `full_path` of the namespace
# to query for projects, so make sure it's loaded and not `nil` before continuing.
2020-11-24 15:15:51 +05:30
2021-04-17 20:07:23 +05:30
::Namespaces::ProjectsFinder.new(
namespace: namespace,
current_user: current_user,
params: finder_params(args)
).execute
2019-09-04 21:01:54 +05:30
end
def self.resolver_complexity(args, child_complexity:)
complexity = super
complexity + 10
end
2021-01-29 00:20:46 +05:30
private
def namespace
strong_memoize(:namespace) do
object.respond_to?(:sync) ? object.sync : object
end
end
2021-04-17 20:07:23 +05:30
def finder_params(args)
{
include_subgroups: args.dig(:include_subgroups),
sort: args.dig(:sort),
search: args.dig(:search),
ids: parse_gids(args.dig(:ids))
}
end
def parse_gids(gids)
gids&.map { |gid| GitlabSchema.parse_gid(gid, expected_type: ::Project).model_id }
end
2019-09-04 21:01:54 +05:30
end
end
2020-05-24 23:13:21 +05:30
2021-06-08 01:23:25 +05:30
Resolvers::NamespaceProjectsResolver.prepend_mod_with('Resolvers::NamespaceProjectsResolver')