diff options
Diffstat (limited to 'app/graphql/resolvers/ci/catalog/resources_resolver.rb')
-rw-r--r-- | app/graphql/resolvers/ci/catalog/resources_resolver.rb | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/app/graphql/resolvers/ci/catalog/resources_resolver.rb b/app/graphql/resolvers/ci/catalog/resources_resolver.rb new file mode 100644 index 00000000000..c6904dcd7f6 --- /dev/null +++ b/app/graphql/resolvers/ci/catalog/resources_resolver.rb @@ -0,0 +1,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 |