Commit 8e70d093 authored by Nicolò Maria Mezzopera's avatar Nicolò Maria Mezzopera Committed by Alex Kalderimis

Add Conan GraphQL type to package

parent d9800c2b
...@@ -2,12 +2,20 @@ ...@@ -2,12 +2,20 @@
module Resolvers module Resolvers
class PackageDetailsResolver < BaseResolver class PackageDetailsResolver < BaseResolver
type ::Types::Packages::PackageType, null: true type ::Types::Packages::PackageDetailsType, null: true
argument :id, ::Types::GlobalIDType[::Packages::Package], argument :id, ::Types::GlobalIDType[::Packages::Package],
required: true, required: true,
description: 'The global ID of the package.' description: 'The global ID of the package.'
def ready?(**args)
context[self.class] ||= { executions: 0 }
context[self.class][:executions] += 1
raise GraphQL::ExecutionError, "Package details can be requested only for one package at a time" if context[self.class][:executions] > 1
super
end
def resolve(id:) def resolve(id:)
# TODO: remove this line when the compatibility layer is removed # TODO: remove this line when the compatibility layer is removed
# See: https://gitlab.com/gitlab-org/gitlab/-/issues/257883 # See: https://gitlab.com/gitlab-org/gitlab/-/issues/257883
......
# frozen_string_literal: true
module Types
module Packages
module Conan
class FileMetadatumType < BaseObject
graphql_name 'ConanFileMetadata'
description 'Conan file metadata'
implements Types::Packages::FileMetadataType
authorize :read_package
field :id, ::Types::GlobalIDType[::Packages::Conan::FileMetadatum], null: false, description: 'ID of the metadatum.'
field :recipe_revision, GraphQL::STRING_TYPE, null: false, description: 'Revision of the Conan recipe.'
field :package_revision, GraphQL::STRING_TYPE, null: true, description: 'Revision of the package.'
field :conan_package_reference, GraphQL::STRING_TYPE, null: true, description: 'Reference of the Conan package.'
field :conan_file_type, ::Types::Packages::Conan::MetadatumFileTypeEnum, null: false, description: 'Type of the Conan file.'
end
end
end
end
# frozen_string_literal: true
module Types
module Packages
module Conan
class MetadatumFileTypeEnum < BaseEnum
graphql_name 'ConanMetadatumFileTypeEnum'
description 'Conan file types'
::Packages::Conan::FileMetadatum.conan_file_types.keys.each do |file|
value file.upcase, value: file, description: "A #{file.humanize(capitalize: false)} type."
end
end
end
end
end
# frozen_string_literal: true
module Types
module Packages
module Conan
class MetadatumType < BaseObject
graphql_name 'ConanMetadata'
description 'Conan metadata'
authorize :read_package
field :id, ::Types::GlobalIDType[::Packages::Conan::Metadatum], null: false, description: 'ID of the metadatum.'
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 :package_username, GraphQL::STRING_TYPE, null: false, description: 'Username of the Conan package.'
field :package_channel, GraphQL::STRING_TYPE, null: false, description: 'Channel of the Conan package.'
field :recipe, GraphQL::STRING_TYPE, null: false, description: 'Recipe of the Conan package.'
field :recipe_path, GraphQL::STRING_TYPE, null: false, description: 'Recipe path of the Conan package.'
end
end
end
end
# frozen_string_literal: true
module Types
module Packages
module FileMetadataType
include ::Types::BaseInterface
graphql_name 'PackageFileMetadata'
description 'Represents metadata associated with a Package file'
field :created_at, ::Types::TimeType, null: false, description: 'Date of creation.'
field :updated_at, ::Types::TimeType, null: false, description: 'Date of most recent update.'
def self.resolve_type(object, context)
case object
when ::Packages::Conan::FileMetadatum
::Types::Packages::Conan::FileMetadatumType
else
# NOTE: This method must be kept in sync with `PackageFileType#file_metadata`,
# which must never produce data that this discriminator cannot handle.
raise 'Unsupported file metadata type'
end
end
orphan_types Types::Packages::Conan::FileMetadatumType
end
end
end
...@@ -6,12 +6,14 @@ module Types ...@@ -6,12 +6,14 @@ module Types
graphql_name 'PackageMetadata' graphql_name 'PackageMetadata'
description 'Represents metadata associated with a Package' description 'Represents metadata associated with a Package'
possible_types ::Types::Packages::Composer::MetadatumType possible_types ::Types::Packages::Composer::MetadatumType, ::Types::Packages::Conan::MetadatumType
def self.resolve_type(object, context) def self.resolve_type(object, context)
case object case object
when ::Packages::Composer::Metadatum when ::Packages::Composer::Metadatum
::Types::Packages::Composer::MetadatumType ::Types::Packages::Composer::MetadatumType
when ::Packages::Conan::Metadatum
::Types::Packages::Conan::MetadatumType
else else
# NOTE: This method must be kept in sync with `PackageWithoutVersionsType#metadata`, # NOTE: This method must be kept in sync with `PackageWithoutVersionsType#metadata`,
# which must never produce data that this discriminator cannot handle. # which must never produce data that this discriminator cannot handle.
......
# frozen_string_literal: true
module Types
module Packages
class PackageDetailsType < PackageType
graphql_name 'PackageDetailsType'
description 'Represents a package details in the Package Registry. Note that this type is in beta and susceptible to changes'
authorize :read_package
field :versions, ::Types::Packages::PackageType.connection_type, null: true,
description: 'The other versions of the package.'
field :package_files, Types::Packages::PackageFileType.connection_type, null: true, description: 'Package files.'
def versions
object.versions
end
end
end
end
# frozen_string_literal: true
module Types
module Packages
class PackageFileType < BaseObject
graphql_name 'PackageFile'
description 'Represents a package file'
authorize :read_package
field :id, ::Types::GlobalIDType[::Packages::PackageFile], null: false, description: 'ID of the file.'
field :created_at, Types::TimeType, null: false, description: 'The created date.'
field :updated_at, Types::TimeType, null: false, description: 'The updated date.'
field :size, GraphQL::STRING_TYPE, null: false, description: 'Size of the package file.'
field :file_name, GraphQL::STRING_TYPE, null: false, description: 'Name of the package file.'
field :download_path, GraphQL::STRING_TYPE, null: false, description: 'Download path of the package file.'
field :file_md5, GraphQL::STRING_TYPE, null: true, description: 'Md5 of the package file.'
field :file_sha1, GraphQL::STRING_TYPE, null: true, description: 'Sha1 of the package file.'
field :file_sha256, GraphQL::STRING_TYPE, null: true, description: 'Sha256 of the package file.'
field :file_metadata, Types::Packages::FileMetadataType, null: true,
description: 'File metadata.'
# NOTE: This method must be kept in sync with the union
# type: `Types::Packages::FileMetadataType`.
#
# `Types::Packages::FileMetadataType.resolve_type(metadata, ctx)` must never raise.
def file_metadata
case object.package.package_type
when 'conan'
object.conan_file_metadatum
else
nil
end
end
end
end
end
...@@ -2,13 +2,52 @@ ...@@ -2,13 +2,52 @@
module Types module Types
module Packages module Packages
class PackageType < PackageWithoutVersionsType class PackageType < ::Types::BaseObject
graphql_name 'Package' graphql_name 'Package'
description 'Represents a package in the Package Registry' description 'Represents a package in the Package Registry. Note that this type is in beta and susceptible to changes'
authorize :read_package authorize :read_package
field :versions, ::Types::Packages::PackageWithoutVersionsType.connection_type, null: true, field :id, ::Types::GlobalIDType[::Packages::Package], null: false,
description: 'The other versions of the package.' 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.'
field :versions, ::Types::Packages::PackageType.connection_type, null: true,
description: 'The other versions of the package.',
deprecated: { reason: 'This field is now only returned in the PackageDetailsType', milestone: '13.11' }
def project
Gitlab::Graphql::Loaders::BatchModelLoader.new(Project, object.project_id).find
end
def versions
[]
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
when 'conan'
object.conan_metadatum
else
nil
end
end
end end
end end
end end
# 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
# frozen_string_literal: true
module Packages
module Conan
class FileMetadatumPolicy < BasePolicy
delegate { @subject.package_file.package }
end
end
end
# frozen_string_literal: true
module Packages
module Conan
class MetadatumPolicy < BasePolicy
delegate { @subject.package }
end
end
end
# frozen_string_literal: true
module Packages
class PackageFilePolicy < BasePolicy
delegate { @subject.package }
end
end
---
title: Add Conan GraphQL type to package
merge_request: 57719
author:
type: added
...@@ -215,7 +215,7 @@ Returns [`Namespace`](#namespace). ...@@ -215,7 +215,7 @@ Returns [`Namespace`](#namespace).
Find a package. Find a package.
Returns [`Package`](#package). Returns [`PackageDetailsType`](#packagedetailstype).
#### Arguments #### Arguments
...@@ -1545,6 +1545,34 @@ Composer metadata. ...@@ -1545,6 +1545,34 @@ Composer metadata.
| `composerJson` | [`PackageComposerJsonType!`](#packagecomposerjsontype) | Data of the Composer JSON file. | | `composerJson` | [`PackageComposerJsonType!`](#packagecomposerjsontype) | Data of the Composer JSON file. |
| `targetSha` | [`String!`](#string) | Target SHA of the package. | | `targetSha` | [`String!`](#string) | Target SHA of the package. |
### `ConanFileMetadata`
Conan file metadata.
| Field | Type | Description |
| ----- | ---- | ----------- |
| `conanFileType` | [`ConanMetadatumFileTypeEnum!`](#conanmetadatumfiletypeenum) | Type of the Conan file. |
| `conanPackageReference` | [`String`](#string) | Reference of the Conan package. |
| `createdAt` | [`Time!`](#time) | Date of creation. |
| `id` | [`PackagesConanFileMetadatumID!`](#packagesconanfilemetadatumid) | ID of the metadatum. |
| `packageRevision` | [`String`](#string) | Revision of the package. |
| `recipeRevision` | [`String!`](#string) | Revision of the Conan recipe. |
| `updatedAt` | [`Time!`](#time) | Date of most recent update. |
### `ConanMetadata`
Conan metadata.
| Field | Type | Description |
| ----- | ---- | ----------- |
| `createdAt` | [`Time!`](#time) | Date of creation. |
| `id` | [`PackagesConanMetadatumID!`](#packagesconanmetadatumid) | ID of the metadatum. |
| `packageChannel` | [`String!`](#string) | Channel of the Conan package. |
| `packageUsername` | [`String!`](#string) | Username of the Conan package. |
| `recipe` | [`String!`](#string) | Recipe of the Conan package. |
| `recipePath` | [`String!`](#string) | Recipe path of the Conan package. |
| `updatedAt` | [`Time!`](#time) | Date of most recent update. |
### `ConfigureSastPayload` ### `ConfigureSastPayload`
Autogenerated return type of ConfigureSast. Autogenerated return type of ConfigureSast.
...@@ -4495,7 +4523,7 @@ Autogenerated return type of OncallScheduleUpdate. ...@@ -4495,7 +4523,7 @@ Autogenerated return type of OncallScheduleUpdate.
### `Package` ### `Package`
Represents a package in the Package Registry. Represents a package in the Package Registry. Note that this type is in beta and susceptible to changes.
| Field | Type | Description | | Field | Type | Description |
| ----- | ---- | ----------- | | ----- | ---- | ----------- |
...@@ -4509,7 +4537,7 @@ Represents a package in the Package Registry. ...@@ -4509,7 +4537,7 @@ Represents a package in the Package Registry.
| `tags` | [`PackageTagConnection`](#packagetagconnection) | Package tags. | | `tags` | [`PackageTagConnection`](#packagetagconnection) | Package tags. |
| `updatedAt` | [`Time!`](#time) | Date of most recent update. | | `updatedAt` | [`Time!`](#time) | Date of most recent update. |
| `version` | [`String`](#string) | Version string. | | `version` | [`String`](#string) | Version string. |
| `versions` | [`PackageWithoutVersionsConnection`](#packagewithoutversionsconnection) | The other versions of the package. | | `versions` **{warning-solid}** | [`PackageConnection`](#packageconnection) | **Deprecated** in 13.11. This field is now only returned in the PackageDetailsType. |
### `PackageComposerJsonType` ### `PackageComposerJsonType`
...@@ -4532,6 +4560,25 @@ The connection type for Package. ...@@ -4532,6 +4560,25 @@ The connection type for Package.
| `nodes` | [`[Package]`](#package) | A list of nodes. | | `nodes` | [`[Package]`](#package) | A list of nodes. |
| `pageInfo` | [`PageInfo!`](#pageinfo) | Information to aid in pagination. | | `pageInfo` | [`PageInfo!`](#pageinfo) | Information to aid in pagination. |
### `PackageDetailsType`
Represents a package details in the Package Registry. Note that this type is in beta and susceptible to changes.
| Field | Type | Description |
| ----- | ---- | ----------- |
| `createdAt` | [`Time!`](#time) | Date of creation. |
| `id` | [`PackagesPackageID!`](#packagespackageid) | ID of the package. |
| `metadata` | [`PackageMetadata`](#packagemetadata) | Package metadata. |
| `name` | [`String!`](#string) | Name of the package. |
| `packageFiles` | [`PackageFileConnection`](#packagefileconnection) | Package files. |
| `packageType` | [`PackageTypeEnum!`](#packagetypeenum) | Package type. |
| `pipelines` | [`PipelineConnection`](#pipelineconnection) | Pipelines that built the package. |
| `project` | [`Project!`](#project) | Project where the package is stored. |
| `tags` | [`PackageTagConnection`](#packagetagconnection) | Package tags. |
| `updatedAt` | [`Time!`](#time) | Date of most recent update. |
| `version` | [`String`](#string) | Version string. |
| `versions` | [`PackageConnection`](#packageconnection) | The other versions of the package. |
### `PackageEdge` ### `PackageEdge`
An edge in a connection. An edge in a connection.
...@@ -4541,6 +4588,42 @@ An edge in a connection. ...@@ -4541,6 +4588,42 @@ An edge in a connection.
| `cursor` | [`String!`](#string) | A cursor for use in pagination. | | `cursor` | [`String!`](#string) | A cursor for use in pagination. |
| `node` | [`Package`](#package) | The item at the end of the edge. | | `node` | [`Package`](#package) | The item at the end of the edge. |
### `PackageFile`
Represents a package file.
| Field | Type | Description |
| ----- | ---- | ----------- |
| `createdAt` | [`Time!`](#time) | The created date. |
| `downloadPath` | [`String!`](#string) | Download path of the package file. |
| `fileMd5` | [`String`](#string) | Md5 of the package file. |
| `fileMetadata` | [`PackageFileMetadata`](#packagefilemetadata) | File metadata. |
| `fileName` | [`String!`](#string) | Name of the package file. |
| `fileSha1` | [`String`](#string) | Sha1 of the package file. |
| `fileSha256` | [`String`](#string) | Sha256 of the package file. |
| `id` | [`PackagesPackageFileID!`](#packagespackagefileid) | ID of the file. |
| `size` | [`String!`](#string) | Size of the package file. |
| `updatedAt` | [`Time!`](#time) | The updated date. |
### `PackageFileConnection`
The connection type for PackageFile.
| Field | Type | Description |
| ----- | ---- | ----------- |
| `edges` | [`[PackageFileEdge]`](#packagefileedge) | A list of edges. |
| `nodes` | [`[PackageFile]`](#packagefile) | A list of nodes. |
| `pageInfo` | [`PageInfo!`](#pageinfo) | Information to aid in pagination. |
### `PackageFileEdge`
An edge in a connection.
| Field | Type | Description |
| ----- | ---- | ----------- |
| `cursor` | [`String!`](#string) | A cursor for use in pagination. |
| `node` | [`PackageFile`](#packagefile) | The item at the end of the edge. |
### `PackageFileRegistry` ### `PackageFileRegistry`
Represents the Geo sync and verification state of a package file. Represents the Geo sync and verification state of a package file.
...@@ -4614,42 +4697,6 @@ An edge in a connection. ...@@ -4614,42 +4697,6 @@ An edge in a connection.
| `cursor` | [`String!`](#string) | A cursor for use in pagination. | | `cursor` | [`String!`](#string) | A cursor for use in pagination. |
| `node` | [`PackageTag`](#packagetag) | The item at the end of the edge. | | `node` | [`PackageTag`](#packagetag) | The item at the end of the edge. |
### `PackageWithoutVersions`
Represents a version of a package in the Package Registry.
| Field | Type | Description |
| ----- | ---- | ----------- |
| `createdAt` | [`Time!`](#time) | Date of creation. |
| `id` | [`PackagesPackageID!`](#packagespackageid) | ID of the package. |
| `metadata` | [`PackageMetadata`](#packagemetadata) | Package metadata. |
| `name` | [`String!`](#string) | Name of the package. |
| `packageType` | [`PackageTypeEnum!`](#packagetypeenum) | Package type. |
| `pipelines` | [`PipelineConnection`](#pipelineconnection) | Pipelines that built the package. |
| `project` | [`Project!`](#project) | Project where the package is stored. |
| `tags` | [`PackageTagConnection`](#packagetagconnection) | Package tags. |
| `updatedAt` | [`Time!`](#time) | Date of most recent update. |
| `version` | [`String`](#string) | Version string. |
### `PackageWithoutVersionsConnection`
The connection type for PackageWithoutVersions.
| Field | Type | Description |
| ----- | ---- | ----------- |
| `edges` | [`[PackageWithoutVersionsEdge]`](#packagewithoutversionsedge) | A list of edges. |
| `nodes` | [`[PackageWithoutVersions]`](#packagewithoutversions) | A list of nodes. |
| `pageInfo` | [`PageInfo!`](#pageinfo) | Information to aid in pagination. |
### `PackageWithoutVersionsEdge`
An edge in a connection.
| Field | Type | Description |
| ----- | ---- | ----------- |
| `cursor` | [`String!`](#string) | A cursor for use in pagination. |
| `node` | [`PackageWithoutVersions`](#packagewithoutversions) | The item at the end of the edge. |
### `PageInfo` ### `PageInfo`
Information about pagination in a connection. Information about pagination in a connection.
...@@ -7530,6 +7577,15 @@ Mode of a commit action. ...@@ -7530,6 +7577,15 @@ Mode of a commit action.
| `BASE64` | Base64 encoding. | | `BASE64` | Base64 encoding. |
| `TEXT` | Text encoding. | | `TEXT` | Text encoding. |
### `ConanMetadatumFileTypeEnum`
Conan file types.
| Value | Description |
| ----- | ----------- |
| `PACKAGE_FILE` | A package file type. |
| `RECIPE_FILE` | A recipe file type. |
### `ContainerExpirationPolicyCadenceEnum` ### `ContainerExpirationPolicyCadenceEnum`
| Value | Description | | Value | Description |
...@@ -8788,6 +8844,24 @@ A `NoteableID` is a global ID. It is encoded as a string. ...@@ -8788,6 +8844,24 @@ A `NoteableID` is a global ID. It is encoded as a string.
An example `NoteableID` is: `"gid://gitlab/Noteable/1"`. An example `NoteableID` is: `"gid://gitlab/Noteable/1"`.
### `PackagesConanFileMetadatumID`
A `PackagesConanFileMetadatumID` is a global ID. It is encoded as a string.
An example `PackagesConanFileMetadatumID` is: `"gid://gitlab/Packages::Conan::FileMetadatum/1"`.
### `PackagesConanMetadatumID`
A `PackagesConanMetadatumID` is a global ID. It is encoded as a string.
An example `PackagesConanMetadatumID` is: `"gid://gitlab/Packages::Conan::Metadatum/1"`.
### `PackagesPackageFileID`
A `PackagesPackageFileID` is a global ID. It is encoded as a string.
An example `PackagesPackageFileID` is: `"gid://gitlab/Packages::PackageFile/1"`.
### `PackagesPackageID` ### `PackagesPackageID`
A `PackagesPackageID` is a global ID. It is encoded as a string. A `PackagesPackageID` is a global ID. It is encoded as a string.
...@@ -8896,6 +8970,7 @@ Represents metadata associated with a Package. ...@@ -8896,6 +8970,7 @@ Represents metadata associated with a Package.
One of: One of:
- [`ComposerMetadata`](#composermetadata) - [`ComposerMetadata`](#composermetadata)
- [`ConanMetadata`](#conanmetadata)
#### `VulnerabilityDetail` #### `VulnerabilityDetail`
...@@ -9048,6 +9123,19 @@ Implementations: ...@@ -9048,6 +9123,19 @@ Implementations:
| `discussions` | [`DiscussionConnection!`](#discussionconnection) | All discussions on this noteable. | | `discussions` | [`DiscussionConnection!`](#discussionconnection) | All discussions on this noteable. |
| `notes` | [`NoteConnection!`](#noteconnection) | All notes on this noteable. | | `notes` | [`NoteConnection!`](#noteconnection) | All notes on this noteable. |
#### `PackageFileMetadata`
Represents metadata associated with a Package file.
Implementations:
- [`ConanFileMetadata`](#conanfilemetadata)
| Field | Type | Description |
| ----- | ---- | ----------- |
| `createdAt` | [`Time!`](#time) | Date of creation. |
| `updatedAt` | [`Time!`](#time) | Date of most recent update. |
#### `ResolvableInterface` #### `ResolvableInterface`
Implementations: Implementations:
......
{
"type": "object",
"additionalProperties": false,
"required": [
"id",
"createdAt",
"updatedAt",
"packageUsername",
"packageChannel",
"recipe",
"recipePath",
"packageName"
],
"properties": {
"id": {
"type": "string"
},
"created_at": {
"type": "string"
},
"updated_at": {
"type": "string"
},
"package_username": {
"type": "string"
},
"package_channel": {
"type": "string"
},
"recipe": {
"type": "string"
},
"recipe_path": {
"type": "string"
}
}
}
...@@ -2,8 +2,17 @@ ...@@ -2,8 +2,17 @@
"type": "object", "type": "object",
"additionalProperties": false, "additionalProperties": false,
"required": [ "required": [
"id", "name", "createdAt", "updatedAt", "version", "packageType", "id",
"project", "tags", "pipelines", "versions", "metadata" "name",
"createdAt",
"updatedAt",
"version",
"packageType",
"project",
"tags",
"pipelines",
"versions",
"metadata"
], ],
"properties": { "properties": {
"id": { "id": {
...@@ -23,7 +32,18 @@ ...@@ -23,7 +32,18 @@
}, },
"packageType": { "packageType": {
"type": ["string"], "type": ["string"],
"enum": ["MAVEN", "NPM", "CONAN", "NUGET", "PYPI", "COMPOSER", "GENERIC", "GOLANG", "RUBYGEMS", "DEBIAN"] "enum": [
"MAVEN",
"NPM",
"CONAN",
"NUGET",
"PYPI",
"COMPOSER",
"GENERIC",
"GOLANG",
"RUBYGEMS",
"DEBIAN"
]
}, },
"tags": { "tags": {
"type": "object", "type": "object",
...@@ -59,8 +79,18 @@ ...@@ -59,8 +79,18 @@
"metadata": { "metadata": {
"anyOf": [ "anyOf": [
{ "$ref": "./package_composer_metadata.json" }, { "$ref": "./package_composer_metadata.json" },
{ "$ref": "./package_conan_metadata.json" },
{ "type": "null" } { "type": "null" }
] ]
},
"packageFiles": {
"type": "object",
"additionalProperties": false,
"properties": {
"pageInfo": { "type": "object" },
"edges": { "type": "array" },
"nodes": { "type": "array" }
}
} }
} }
} }
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe GitlabSchema.types['ConanFileMetadata'] do
it 'includes conan file metadatum fields' do
expected_fields = %w[
id created_at updated_at recipe_revision package_revision conan_package_reference conan_file_type
]
expect(described_class).to include_graphql_fields(*expected_fields)
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe GitlabSchema.types['ConanMetadatumFileTypeEnum'] do
it 'uses all possible options from model' do
expected_keys = ::Packages::Conan::FileMetadatum.conan_file_types
.keys
.map(&:upcase)
expect(described_class.values.keys).to contain_exactly(*expected_keys)
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe GitlabSchema.types['ConanMetadata'] do
it 'includes conan metadatum fields' do
expected_fields = %w[
id created_at updated_at package_username package_channel recipe recipe_path
]
expect(described_class).to include_graphql_fields(*expected_fields)
end
end
...@@ -2,10 +2,10 @@ ...@@ -2,10 +2,10 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe GitlabSchema.types['PackageWithoutVersions'] do RSpec.describe GitlabSchema.types['PackageDetailsType'] do
it 'includes all the package fields' do it 'includes all the package fields' do
expected_fields = %w[ expected_fields = %w[
id name version created_at updated_at package_type tags project pipelines id name version created_at updated_at package_type tags project pipelines versions package_files
] ]
expect(described_class).to include_graphql_fields(*expected_fields) expect(described_class).to include_graphql_fields(*expected_fields)
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe GitlabSchema.types['PackageFile'] do
it 'includes package file fields' do
expected_fields = %w[
id file_name created_at updated_at size file_name download_path file_md5 file_sha1 file_sha256 file_metadata
]
expect(described_class).to include_graphql_fields(*expected_fields)
end
end
...@@ -8,7 +8,7 @@ RSpec.describe GitlabSchema.types['Package'] do ...@@ -8,7 +8,7 @@ RSpec.describe GitlabSchema.types['Package'] do
id name version package_type id name version package_type
created_at updated_at created_at updated_at
project project
tags pipelines versions tags pipelines metadata versions
] ]
expect(described_class).to include_graphql_fields(*expected_fields) expect(described_class).to include_graphql_fields(*expected_fields)
......
...@@ -98,6 +98,6 @@ RSpec.describe GitlabSchema.types['Query'] do ...@@ -98,6 +98,6 @@ RSpec.describe GitlabSchema.types['Query'] do
describe 'package field' do describe 'package field' do
subject { described_class.fields['package'] } subject { described_class.fields['package'] }
it { is_expected.to have_graphql_type(Types::Packages::PackageType) } it { is_expected.to have_graphql_type(Types::Packages::PackageDetailsType) }
end end
end end
...@@ -2,33 +2,47 @@ ...@@ -2,33 +2,47 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe 'package details' do RSpec.describe 'package details' do
using RSpec::Parameterized::TableSyntax
include GraphqlHelpers include GraphqlHelpers
let_it_be(:project) { create(:project) } let_it_be(:project) { create(:project) }
let_it_be(:package) { create(:composer_package, project: project) } let_it_be(:composer_package) { create(:composer_package, project: project) }
let_it_be(:composer_json) { { name: 'name', type: 'type', license: 'license', version: 1 } } let_it_be(:composer_json) { { name: 'name', type: 'type', license: 'license', version: 1 } }
let_it_be(:composer_metadatum) do let_it_be(:composer_metadatum) do
# we are forced to manually create the metadatum, without using the factory to force the sha to be a string # we are forced to manually create the metadatum, without using the factory to force the sha to be a string
# and avoid an error where gitaly can't find the repository # and avoid an error where gitaly can't find the repository
create(:composer_metadatum, package: package, target_sha: 'foo_sha', composer_json: composer_json) create(:composer_metadatum, package: composer_package, target_sha: 'foo_sha', composer_json: composer_json)
end end
let(:depth) { 3 } let(:depth) { 3 }
let(:excluded) { %w[metadata apiFuzzingCiConfiguration pipeline] } let(:excluded) { %w[metadata apiFuzzingCiConfiguration pipeline packageFiles] }
let(:metadata) { query_graphql_fragment('ComposerMetadata') }
let(:package_files) {all_graphql_fields_for('PackageFile')}
let(:package_files_metadata) {query_graphql_fragment('ConanFileMetadata')}
let(:query) do let(:query) do
graphql_query_for(:package, { id: package_global_id }, <<~FIELDS) graphql_query_for(:package, { id: package_global_id }, <<~FIELDS)
#{all_graphql_fields_for('Package', max_depth: depth, excluded: excluded)} #{all_graphql_fields_for('PackageDetailsType', max_depth: depth, excluded: excluded)}
metadata { metadata {
#{query_graphql_fragment('ComposerMetadata')} #{metadata}
}
packageFiles {
nodes {
#{package_files}
fileMetadata {
#{package_files_metadata}
}
}
} }
FIELDS FIELDS
end end
let(:user) { project.owner } let(:user) { project.owner }
let(:package_global_id) { global_id_of(package) } let(:package_global_id) { global_id_of(composer_package) }
let(:package_details) { graphql_data_at(:package) } let(:package_details) { graphql_data_at(:package) }
let(:metadata_response) { graphql_data_at(:package, :metadata) }
let(:package_files_response) { graphql_data_at(:package, :package_files, :nodes) }
let(:first_file_response) { graphql_data_at(:package, :package_files, :nodes, 0)}
let(:first_file_response_metadata) { graphql_data_at(:package, :package_files, :nodes, 0, :file_metadata)}
subject { post_graphql(query, current_user: user) } subject { post_graphql(query, current_user: user) }
...@@ -40,15 +54,68 @@ RSpec.describe 'package details' do ...@@ -40,15 +54,68 @@ RSpec.describe 'package details' do
it 'matches the JSON schema' do it 'matches the JSON schema' do
expect(package_details).to match_schema('graphql/packages/package_details') expect(package_details).to match_schema('graphql/packages/package_details')
end end
end
describe 'Packages Metadata' do
before do
subject
end
it 'includes the fields of the correct package' do describe 'Composer' do
expect(package_details).to include( it 'has the correct metadata' do
'id' => package_global_id, expect(metadata_response).to include(
'metadata' => {
'targetSha' => 'foo_sha', 'targetSha' => 'foo_sha',
'composerJson' => composer_json.transform_keys(&:to_s).transform_values(&:to_s) 'composerJson' => composer_json.transform_keys(&:to_s).transform_values(&:to_s)
} )
) end
it 'does not have files' do
expect(package_files_response).to be_empty
end
end
describe 'Conan' do
let_it_be(:conan_package) { create(:conan_package, project: project) }
let(:package_global_id) { global_id_of(conan_package) }
let(:metadata) { query_graphql_fragment('ConanMetadata') }
let(:first_file) { conan_package.package_files.find { |f| global_id_of(f) == first_file_response['id'] } }
it 'has the correct metadata' do
expect(metadata_response).to include(
'id' => global_id_of(conan_package.conan_metadatum),
'recipe' => conan_package.conan_metadatum.recipe,
'packageChannel' => conan_package.conan_metadatum.package_channel,
'packageUsername' => conan_package.conan_metadatum.package_username,
'recipePath' => conan_package.conan_metadatum.recipe_path
)
end
it 'has the right amount of files' do
expect(package_files_response.length).to be(conan_package.package_files.length)
end
it 'has the basic package files data' do
expect(first_file_response).to include(
'id' => global_id_of(first_file),
'fileName' => first_file.file_name,
'size' => first_file.size.to_s,
'downloadPath' => first_file.download_path,
'fileSha1' => first_file.file_sha1,
'fileMd5' => first_file.file_md5,
'fileSha256' => first_file.file_sha256
)
end
it 'has the correct file metadata' do
expect(first_file_response_metadata).to include(
'id' => global_id_of(first_file.conan_file_metadatum),
'packageRevision' => first_file.conan_file_metadatum.package_revision,
'conanPackageReference' => first_file.conan_file_metadatum.conan_package_reference,
'recipeRevision' => first_file.conan_file_metadatum.recipe_revision,
'conanFileType' => first_file.conan_file_metadatum.conan_file_type.upcase
)
end
end end
end end
...@@ -56,7 +123,7 @@ RSpec.describe 'package details' do ...@@ -56,7 +123,7 @@ RSpec.describe 'package details' do
let(:depth) { 3 } let(:depth) { 3 }
let(:excluded) { %w[metadata project tags pipelines] } # to limit the query complexity let(:excluded) { %w[metadata project tags pipelines] } # to limit the query complexity
let_it_be(:siblings) { create_list(:composer_package, 2, project: project, name: package.name) } let_it_be(:siblings) { create_list(:composer_package, 2, project: project, name: composer_package.name) }
it 'includes the sibling versions' do it 'includes the sibling versions' do
subject subject
...@@ -73,8 +140,32 @@ RSpec.describe 'package details' do ...@@ -73,8 +140,32 @@ RSpec.describe 'package details' do
subject subject
expect(graphql_data_at(:package, :versions, :nodes, :version)).to be_present expect(graphql_data_at(:package, :versions, :nodes, :version)).to be_present
expect(graphql_data_at(:package, :versions, :nodes, :versions)).not_to be_present expect(graphql_data_at(:package, :versions, :nodes, :versions, :nodes)).to be_empty
end end
end end
end end
context 'with a batched query' do
let_it_be(:conan_package) { create(:conan_package, project: project) }
let(:batch_query) do
<<~QUERY
{
a: package(id: "#{global_id_of(composer_package)}") { name }
b: package(id: "#{global_id_of(conan_package)}") { name }
}
QUERY
end
let(:a_packages_names) { graphql_data_at(:a, :packages, :nodes, :name) }
it 'returns an error for the second package and data for the first' do
post_graphql(batch_query, current_user: user)
expect(graphql_data_at(:a, :name)).to eq(composer_package.name)
expect_graphql_errors_to_include [/Package details can be requested only for one package at a time/]
expect(graphql_data_at(:b)).to be(nil)
end
end
end end
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