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,
|
|
|
|
description: 'Include also subgroup projects'
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
argument :search, GraphQL::STRING_TYPE,
|
|
|
|
required: false,
|
|
|
|
default_value: nil,
|
|
|
|
description: 'Search project with most similar names or paths'
|
|
|
|
|
|
|
|
argument :sort, Types::Projects::NamespaceProjectSortEnum,
|
|
|
|
required: false,
|
|
|
|
default_value: nil,
|
|
|
|
description: 'Sort projects by this criteria'
|
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
type Types::ProjectType, null: true
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
def resolve(include_subgroups:, sort:, search:)
|
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.
|
|
|
|
return Project.none if namespace.nil?
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
query = include_subgroups ? namespace.all_projects.with_route : namespace.projects.with_route
|
|
|
|
|
|
|
|
return query unless search.present?
|
|
|
|
|
|
|
|
if sort == :similarity
|
|
|
|
query.sorted_by_similarity_desc(search, include_in_select: true).merge(Project.search(search))
|
2019-09-04 21:01:54 +05:30
|
|
|
else
|
2020-11-24 15:15:51 +05:30
|
|
|
query.merge(Project.search(search))
|
2019-09-04 21:01:54 +05:30
|
|
|
end
|
|
|
|
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
|
2019-09-04 21:01:54 +05:30
|
|
|
end
|
|
|
|
end
|
2020-05-24 23:13:21 +05:30
|
|
|
|
|
|
|
Resolvers::NamespaceProjectsResolver.prepend_if_ee('::EE::Resolvers::NamespaceProjectsResolver')
|