2019-09-04 21:01:54 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Resolvers
|
|
|
|
class NamespaceProjectsResolver < BaseResolver
|
2021-10-27 15:23:28 +05:30
|
|
|
argument :include_subgroups, GraphQL::Types::Boolean,
|
2019-09-04 21:01:54 +05:30
|
|
|
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
|
|
|
|
2021-10-27 15:23:28 +05:30
|
|
|
argument :search, GraphQL::Types::String,
|
2023-04-23 21:23:45 +05:30
|
|
|
required: false,
|
|
|
|
default_value: nil,
|
|
|
|
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-10-27 15:23:28 +05:30
|
|
|
argument :ids, [GraphQL::Types::ID],
|
2021-04-17 20:07:23 +05:30
|
|
|
required: false,
|
|
|
|
default_value: nil,
|
|
|
|
description: 'Filter projects by IDs.'
|
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
argument :with_issues_enabled, GraphQL::Types::Boolean,
|
|
|
|
required: false,
|
|
|
|
description: "Return only projects with issues enabled."
|
|
|
|
|
|
|
|
argument :with_merge_requests_enabled, GraphQL::Types::Boolean,
|
|
|
|
required: false,
|
|
|
|
description: "Return only projects with merge requests enabled."
|
|
|
|
|
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),
|
2023-04-23 21:23:45 +05:30
|
|
|
ids: parse_gids(args.dig(:ids)),
|
|
|
|
with_issues_enabled: args[:with_issues_enabled],
|
|
|
|
with_merge_requests_enabled: args[:with_merge_requests_enabled]
|
2021-04-17 20:07:23 +05:30
|
|
|
}
|
|
|
|
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')
|