2019-05-12 21:10:46 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Resolvers
|
|
|
|
class NamespaceProjectsResolver < BaseResolver
|
2021-07-22 12:10:04 +00:00
|
|
|
argument :include_subgroups, GraphQL::Types::Boolean,
|
2019-05-12 21:10:46 +00:00
|
|
|
required: false,
|
|
|
|
default_value: false,
|
2021-01-12 00:10:42 +00:00
|
|
|
description: 'Include also subgroup projects.'
|
2019-05-12 21:10:46 +00:00
|
|
|
|
2021-07-22 12:10:04 +00:00
|
|
|
argument :search, GraphQL::Types::String,
|
2020-09-05 03:08:31 +00:00
|
|
|
required: false,
|
|
|
|
default_value: nil,
|
2021-01-12 00:10:42 +00:00
|
|
|
description: 'Search project with most similar names or paths.'
|
2020-09-05 03:08:31 +00:00
|
|
|
|
|
|
|
argument :sort, Types::Projects::NamespaceProjectSortEnum,
|
|
|
|
required: false,
|
|
|
|
default_value: nil,
|
2021-01-12 00:10:42 +00:00
|
|
|
description: 'Sort projects by this criteria.'
|
2020-09-05 03:08:31 +00:00
|
|
|
|
2021-07-22 12:10:04 +00:00
|
|
|
argument :ids, [GraphQL::Types::ID],
|
2021-03-04 00:11:19 +00:00
|
|
|
required: false,
|
|
|
|
default_value: nil,
|
|
|
|
description: 'Filter projects by IDs.'
|
|
|
|
|
2019-05-12 21:10:46 +00:00
|
|
|
type Types::ProjectType, null: true
|
|
|
|
|
2021-03-08 15:08:54 +00:00
|
|
|
def resolve(args)
|
2019-05-12 21:10:46 +00:00
|
|
|
# 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.
|
|
|
|
|
2021-03-08 15:08:54 +00:00
|
|
|
::Namespaces::ProjectsFinder.new(
|
|
|
|
namespace: namespace,
|
|
|
|
current_user: current_user,
|
|
|
|
params: finder_params(args)
|
|
|
|
).execute
|
2019-05-12 21:10:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.resolver_complexity(args, child_complexity:)
|
|
|
|
complexity = super
|
|
|
|
complexity + 10
|
|
|
|
end
|
2020-10-30 18:08:56 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def namespace
|
|
|
|
strong_memoize(:namespace) do
|
|
|
|
object.respond_to?(:sync) ? object.sync : object
|
|
|
|
end
|
|
|
|
end
|
2021-03-04 00:11:19 +00:00
|
|
|
|
2021-03-08 15:08:54 +00:00
|
|
|
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
|
|
|
|
|
2021-03-04 00:11:19 +00:00
|
|
|
def parse_gids(gids)
|
|
|
|
gids&.map { |gid| GitlabSchema.parse_gid(gid, expected_type: ::Project).model_id }
|
|
|
|
end
|
2019-05-12 21:10:46 +00:00
|
|
|
end
|
|
|
|
end
|
2020-05-07 09:09:51 +00:00
|
|
|
|
2021-05-11 21:10:21 +00:00
|
|
|
Resolvers::NamespaceProjectsResolver.prepend_mod_with('Resolvers::NamespaceProjectsResolver')
|