1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# frozen_string_literal: true
module Resolvers
module Ci
module Catalog
class ResourcesResolver < BaseResolver
include LooksAhead
type ::Types::Ci::Catalog::ResourceType.connection_type, null: true
argument :scope, ::Types::Ci::Catalog::ResourceScopeEnum,
required: false,
default_value: :all,
description: 'Scope of the returned catalog resources.'
argument :search, GraphQL::Types::String,
required: false,
description: 'Search term to filter the catalog resources by name or description.'
argument :sort, ::Types::Ci::Catalog::ResourceSortEnum,
required: false,
description: 'Sort catalog resources by given criteria.'
# TODO: https://gitlab.com/gitlab-org/gitlab/-/issues/429636
argument :project_path, GraphQL::Types::ID,
required: false,
description: 'Project with the namespace catalog.'
def resolve_with_lookahead(scope:, project_path: nil, search: nil, sort: nil)
if project_path.present?
project = Project.find_by_full_path(project_path)
apply_lookahead(
::Ci::Catalog::Listing
.new(context[:current_user])
.resources(namespace: project.root_namespace, sort: sort, search: search)
)
elsif scope == :all
apply_lookahead(::Ci::Catalog::Listing.new(context[:current_user]).resources(sort: sort, search: search))
end
end
private
def preloads
{
web_path: { project: { namespace: :route } },
readme_html: { project: :route }
}
end
end
end
end
end
|