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