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

55 lines
1.6 KiB
Ruby
Raw Normal View History

2020-05-24 23:13:21 +05:30
# frozen_string_literal: true
module Resolvers
class ProjectsResolver < BaseResolver
type Types::ProjectType, null: true
2021-10-27 15:23:28 +05:30
argument :membership, GraphQL::Types::Boolean,
2020-05-24 23:13:21 +05:30
required: false,
2021-03-08 18:12:59 +05:30
description: 'Limit projects that the current user is a member of.'
2020-05-24 23:13:21 +05:30
2021-10-27 15:23:28 +05:30
argument :search, GraphQL::Types::String,
2020-05-24 23:13:21 +05:30
required: false,
2021-03-08 18:12:59 +05:30
description: 'Search query for project name, path, or description.'
2020-05-24 23:13:21 +05:30
2021-10-27 15:23:28 +05:30
argument :ids, [GraphQL::Types::ID],
2021-01-03 14:25:43 +05:30
required: false,
2021-03-08 18:12:59 +05:30
description: 'Filter projects by IDs.'
2021-01-03 14:25:43 +05:30
2021-10-27 15:23:28 +05:30
argument :search_namespaces, GraphQL::Types::Boolean,
2021-01-03 14:25:43 +05:30
required: false,
2021-03-08 18:12:59 +05:30
description: 'Include namespace in project search.'
2021-01-03 14:25:43 +05:30
2021-10-27 15:23:28 +05:30
argument :sort, GraphQL::Types::String,
2021-01-03 14:25:43 +05:30
required: false,
2021-03-08 18:12:59 +05:30
description: 'Sort order of results.'
2020-11-24 15:15:51 +05:30
2021-10-27 15:23:28 +05:30
argument :topics, type: [GraphQL::Types::String],
2021-09-04 01:27:46 +05:30
required: false,
description: 'Filters projects by topics.'
2020-05-24 23:13:21 +05:30
def resolve(**args)
ProjectsFinder
2020-11-24 15:15:51 +05:30
.new(current_user: current_user, params: project_finder_params(args), project_ids_relation: parse_gids(args[:ids]))
2020-05-24 23:13:21 +05:30
.execute
end
private
def project_finder_params(params)
{
without_deleted: true,
non_public: params[:membership],
2021-01-03 14:25:43 +05:30
search: params[:search],
search_namespaces: params[:search_namespaces],
2021-09-04 01:27:46 +05:30
sort: params[:sort],
topic: params[:topics]
2020-05-24 23:13:21 +05:30
}.compact
end
2020-11-24 15:15:51 +05:30
def parse_gids(gids)
gids&.map { |gid| GitlabSchema.parse_gid(gid, expected_type: ::Project).model_id }
end
2020-05-24 23:13:21 +05:30
end
end