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