Add package list graphql endpoint

Add a new graphql package list GraphQL endpoint, to allow
Package data to be consumed with graphql, this is a first
Step to boost the ability of the backend to serve complete
And performant data

- resolver
- unit tests
- package type
- alter project type
Co-authored-by: default avatarTetiana Chupryna <tchupryna@gitlab.com>
Co-authored-by: default avatarDavid Fernandez <dfernandez@gitlab.com>
Co-authored-by: default avatarNick Kipling <nkipling@gitlab.com>
Co-authored-by: default avatarSteve Abrams <sabrams@gitlab.com>

Add new packages type to project type

- project type change
- unit test
Co-authored-by: default avatarTetiana Chupryna <tchupryna@gitlab.com>
Co-authored-by: default avatarDavid Fernandez <dfernandez@gitlab.com>
Co-authored-by: default avatarNick Kipling <nkipling@gitlab.com>
Co-authored-by: default avatarSteve Abrams <sabrams@gitlab.com>
parent 11790d5b
......@@ -42,6 +42,10 @@ module EE
Hash.new(0).merge(project.requirements.counts_by_state)
end
field :packages, ::Types::PackageType.connection_type, null: true,
description: 'Packages of the project',
resolver: ::Resolvers::PackagesResolver
def self.requirements_available?(project, user)
::Feature.enabled?(:requirements_management, project, default_enabled: true) && Ability.allowed?(user, :read_requirement, project)
end
......
# frozen_string_literal: true
module Resolvers
class PackagesResolver < BaseResolver
type Types::PackageType, null: true
def resolve(**args)
return unless packages_available?(object, current_user)
::Packages::PackagesFinder.new(object).execute
end
private
def packages_available?(object, user)
::Gitlab.config.packages.enabled && object.feature_available?(:packages) && Ability.allowed?(user, :read_package, object)
end
end
end
\ No newline at end of file
# frozen_string_literal: true
require 'spec_helper'
describe Resolvers::PackagesResolver do
include GraphqlHelpers
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project) }
let_it_be(:package) { create(:package, project: project) }
describe '#resolve' do
subject(:packages) { resolve(described_class, ctx: { current_user: user }, obj: project) }
context 'when the package feature is enabled' do
before do
stub_licensed_features(packages: true)
end
context 'when the project has the package feature enabled' do
before do
allow(project).to receive(:feature_available?).with(:packages).and_return(true)
end
context 'when the user is authorized to read the packages' do
before do
project.add_reporter(user)
end
it { is_expected.to contain_exactly(package) }
end
context 'when the user is not authorized to read the package' do
it { is_expected.to be_nil }
end
end
context 'when the project has the package feature disabled' do
before do
allow(project).to receive(:feature_available?).with(:packages).and_return(false)
end
it { is_expected.to be_nil }
end
end
context 'when the package feature is not enabled' do
it { is_expected.to be_nil }
end
end
end
......@@ -16,7 +16,7 @@ describe GitlabSchema.types['Project'] do
it 'includes the ee specific fields' do
expected_fields = %w[
service_desk_enabled service_desk_address vulnerabilities
requirement_states_count vulnerability_severities_count
requirement_states_count vulnerability_severities_count packages
]
expect(described_class).to include_graphql_fields(*expected_fields)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment