diff options
Diffstat (limited to 'app/graphql/types/packages')
-rw-r--r-- | app/graphql/types/packages/composer/details_type.rb | 16 | ||||
-rw-r--r-- | app/graphql/types/packages/composer/metadatum_type.rb | 4 | ||||
-rw-r--r-- | app/graphql/types/packages/metadata_type.rb | 23 | ||||
-rw-r--r-- | app/graphql/types/packages/package_type.rb | 19 | ||||
-rw-r--r-- | app/graphql/types/packages/package_type_enum.rb | 2 | ||||
-rw-r--r-- | app/graphql/types/packages/package_without_versions_type.rb | 44 |
6 files changed, 73 insertions, 35 deletions
diff --git a/app/graphql/types/packages/composer/details_type.rb b/app/graphql/types/packages/composer/details_type.rb deleted file mode 100644 index 8c6845a6fb3..00000000000 --- a/app/graphql/types/packages/composer/details_type.rb +++ /dev/null @@ -1,16 +0,0 @@ -# frozen_string_literal: true - -module Types - module Packages - module Composer - class DetailsType < Types::Packages::PackageType - graphql_name 'PackageComposerDetails' - description 'Details of a Composer package' - - authorize :read_package - - field :composer_metadatum, Types::Packages::Composer::MetadatumType, null: false, description: 'The Composer metadatum.' - end - end - end -end diff --git a/app/graphql/types/packages/composer/metadatum_type.rb b/app/graphql/types/packages/composer/metadatum_type.rb index a97818b1fb8..9d4ce3cebd4 100644 --- a/app/graphql/types/packages/composer/metadatum_type.rb +++ b/app/graphql/types/packages/composer/metadatum_type.rb @@ -4,8 +4,8 @@ module Types module Packages module Composer class MetadatumType < BaseObject - graphql_name 'PackageComposerMetadatumType' - description 'Composer metadatum' + graphql_name 'ComposerMetadata' + description 'Composer metadata' authorize :read_package diff --git a/app/graphql/types/packages/metadata_type.rb b/app/graphql/types/packages/metadata_type.rb new file mode 100644 index 00000000000..26c43b51a69 --- /dev/null +++ b/app/graphql/types/packages/metadata_type.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +module Types + module Packages + class MetadataType < BaseUnion + graphql_name 'PackageMetadata' + description 'Represents metadata associated with a Package' + + possible_types ::Types::Packages::Composer::MetadatumType + + def self.resolve_type(object, context) + case object + when ::Packages::Composer::Metadatum + ::Types::Packages::Composer::MetadatumType + else + # NOTE: This method must be kept in sync with `PackageWithoutVersionsType#metadata`, + # which must never produce data that this discriminator cannot handle. + raise 'Unsupported metadata type' + end + end + end + end +end diff --git a/app/graphql/types/packages/package_type.rb b/app/graphql/types/packages/package_type.rb index b13d16e91c6..331898a1e84 100644 --- a/app/graphql/types/packages/package_type.rb +++ b/app/graphql/types/packages/package_type.rb @@ -2,26 +2,13 @@ module Types module Packages - class PackageType < BaseObject + class PackageType < PackageWithoutVersionsType graphql_name 'Package' description 'Represents a package in the Package Registry' - authorize :read_package - field :id, GraphQL::ID_TYPE, null: false, description: 'The ID of the package.' - field :name, GraphQL::STRING_TYPE, null: false, description: 'The name of the package.' - field :created_at, Types::TimeType, null: false, description: 'The created date.' - field :updated_at, Types::TimeType, null: false, description: 'The updated date.' - field :version, GraphQL::STRING_TYPE, null: true, description: 'The version of the package.' - field :package_type, Types::Packages::PackageTypeEnum, null: false, description: 'The type of the package.' - field :tags, Types::Packages::PackageTagType.connection_type, null: true, description: 'The package tags.' - field :project, Types::ProjectType, null: false, description: 'Project where the package is stored.' - field :pipelines, Types::Ci::PipelineType.connection_type, null: true, description: 'Pipelines that built the package.' - field :versions, Types::Packages::PackageType.connection_type, null: true, description: 'The other versions of the package.' - - def project - Gitlab::Graphql::Loaders::BatchModelLoader.new(Project, object.project_id).find - end + field :versions, ::Types::Packages::PackageWithoutVersionsType.connection_type, null: true, + description: 'The other versions of the package.' end end end diff --git a/app/graphql/types/packages/package_type_enum.rb b/app/graphql/types/packages/package_type_enum.rb index 9713c9d49b1..e2b5cf3163e 100644 --- a/app/graphql/types/packages/package_type_enum.rb +++ b/app/graphql/types/packages/package_type_enum.rb @@ -5,7 +5,7 @@ module Types class PackageTypeEnum < BaseEnum PACKAGE_TYPE_NAMES = { pypi: 'PyPI', - npm: 'NPM' + npm: 'npm' }.freeze ::Packages::Package.package_types.keys.each do |package_type| diff --git a/app/graphql/types/packages/package_without_versions_type.rb b/app/graphql/types/packages/package_without_versions_type.rb new file mode 100644 index 00000000000..9c6bb37e6cc --- /dev/null +++ b/app/graphql/types/packages/package_without_versions_type.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +module Types + module Packages + class PackageWithoutVersionsType < ::Types::BaseObject + graphql_name 'PackageWithoutVersions' + description 'Represents a version of a package in the Package Registry' + + authorize :read_package + + field :id, ::Types::GlobalIDType[::Packages::Package], null: false, + description: 'ID of the package.' + + field :name, GraphQL::STRING_TYPE, null: false, description: 'Name of the package.' + field :created_at, Types::TimeType, null: false, description: 'Date of creation.' + field :updated_at, Types::TimeType, null: false, description: 'Date of most recent update.' + field :version, GraphQL::STRING_TYPE, null: true, description: 'Version string.' + field :package_type, Types::Packages::PackageTypeEnum, null: false, description: 'Package type.' + field :tags, Types::Packages::PackageTagType.connection_type, null: true, description: 'Package tags.' + field :project, Types::ProjectType, null: false, description: 'Project where the package is stored.' + field :pipelines, Types::Ci::PipelineType.connection_type, null: true, + description: 'Pipelines that built the package.' + field :metadata, Types::Packages::MetadataType, null: true, + description: 'Package metadata.' + + def project + Gitlab::Graphql::Loaders::BatchModelLoader.new(Project, object.project_id).find + end + + # NOTE: This method must be kept in sync with the union + # type: `Types::Packages::MetadataType`. + # + # `Types::Packages::MetadataType.resolve_type(metadata, ctx)` must never raise. + def metadata + case object.package_type + when 'composer' + object.composer_metadatum + else + nil + end + end + end + end +end |