Commit 6540eb41 authored by Alex Kalderimis's avatar Alex Kalderimis

Merge branch '285467-package-registry-graphql-api' into 'master'

Add Conan GraphQL type to package

See merge request gitlab-org/gitlab!57719
parents 204238b3 8e70d093
......@@ -2,12 +2,20 @@
module Resolvers
class PackageDetailsResolver < BaseResolver
type ::Types::Packages::PackageType, null: true
type ::Types::Packages::PackageDetailsType, null: true
argument :id, ::Types::GlobalIDType[::Packages::Package],
required: true,
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:)
# TODO: remove this line when the compatibility layer is removed
# 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
graphql_name 'PackageMetadata'
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)
case object
when ::Packages::Composer::Metadatum
::Types::Packages::Composer::MetadatumType
when ::Packages::Conan::Metadatum
::Types::Packages::Conan::MetadatumType
else
# NOTE: This method must be kept in sync with `PackageWithoutVersionsType#metadata`,
# 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 @@
module Types
module Packages
class PackageType < PackageWithoutVersionsType
class PackageType < ::Types::BaseObject
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
field :versions, ::Types::Packages::PackageWithoutVersionsType.connection_type, null: true,
description: 'The other versions of the 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.'
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
# 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).
Find a package.
Returns [`Package`](#package).
Returns [`PackageDetailsType`](#packagedetailstype).
#### Arguments
......@@ -1548,6 +1548,34 @@ Composer metadata.
| `composerJson` | [`PackageComposerJsonType!`](#packagecomposerjsontype) | Data of the Composer JSON file. |
| `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`
Autogenerated return type of ConfigureSast.
......@@ -4501,7 +4529,7 @@ Autogenerated return type of OncallScheduleUpdate.
### `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 |
| ----- | ---- | ----------- |
......@@ -4515,7 +4543,7 @@ Represents a package in the Package Registry.
| `tags` | [`PackageTagConnection`](#packagetagconnection) | Package tags. |
| `updatedAt` | [`Time!`](#time) | Date of most recent update. |
| `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`
......@@ -4538,6 +4566,25 @@ The connection type for Package.
| `nodes` | [`[Package]`](#package) | A list of nodes. |
| `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`
An edge in a connection.
......@@ -4547,6 +4594,42 @@ An edge in a connection.
| `cursor` | [`String!`](#string) | A cursor for use in pagination. |
| `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`
Represents the Geo sync and verification state of a package file.
......@@ -4620,42 +4703,6 @@ An edge in a connection.
| `cursor` | [`String!`](#string) | A cursor for use in pagination. |
| `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`
Information about pagination in a connection.
......@@ -7536,6 +7583,15 @@ Mode of a commit action.
| `BASE64` | Base64 encoding. |
| `TEXT` | Text encoding. |
### `ConanMetadatumFileTypeEnum`
Conan file types.
| Value | Description |
| ----- | ----------- |
| `PACKAGE_FILE` | A package file type. |
| `RECIPE_FILE` | A recipe file type. |
### `ContainerExpirationPolicyCadenceEnum`
| Value | Description |
......@@ -8794,6 +8850,24 @@ A `NoteableID` is a global ID. It is encoded as a string.
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`
A `PackagesPackageID` is a global ID. It is encoded as a string.
......@@ -8902,6 +8976,7 @@ Represents metadata associated with a Package.
One of:
- [`ComposerMetadata`](#composermetadata)
- [`ConanMetadata`](#conanmetadata)
#### `VulnerabilityDetail`
......@@ -9054,6 +9129,19 @@ Implementations:
| `discussions` | [`DiscussionConnection!`](#discussionconnection) | All discussions 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`
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 @@
"type": "object",
"additionalProperties": false,
"required": [
"id", "name", "createdAt", "updatedAt", "version", "packageType",
"project", "tags", "pipelines", "versions", "metadata"
"id",
"name",
"createdAt",
"updatedAt",
"version",
"packageType",
"project",
"tags",
"pipelines",
"versions",
"metadata"
],
"properties": {
"id": {
......@@ -23,7 +32,18 @@
},
"packageType": {
"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": {
"type": "object",
......@@ -59,8 +79,18 @@
"metadata": {
"anyOf": [
{ "$ref": "./package_composer_metadata.json" },
{ "$ref": "./package_conan_metadata.json" },
{ "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 @@
require 'spec_helper'
RSpec.describe GitlabSchema.types['PackageWithoutVersions'] do
RSpec.describe GitlabSchema.types['PackageDetailsType'] do
it 'includes all the package fields' do
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)
......
# 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
id name version package_type
created_at updated_at
project
tags pipelines versions
tags pipelines metadata versions
]
expect(described_class).to include_graphql_fields(*expected_fields)
......
......@@ -98,6 +98,6 @@ RSpec.describe GitlabSchema.types['Query'] do
describe 'package field' do
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
......@@ -2,33 +2,47 @@
require 'spec_helper'
RSpec.describe 'package details' do
using RSpec::Parameterized::TableSyntax
include GraphqlHelpers
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_metadatum) do
# 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
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
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
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 {
#{query_graphql_fragment('ComposerMetadata')}
#{metadata}
}
packageFiles {
nodes {
#{package_files}
fileMetadata {
#{package_files_metadata}
}
}
}
FIELDS
end
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(: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) }
......@@ -40,23 +54,76 @@ RSpec.describe 'package details' do
it 'matches the JSON schema' do
expect(package_details).to match_schema('graphql/packages/package_details')
end
end
it 'includes the fields of the correct package' do
expect(package_details).to include(
'id' => package_global_id,
'metadata' => {
describe 'Packages Metadata' do
before do
subject
end
describe 'Composer' do
it 'has the correct metadata' do
expect(metadata_response).to include(
'targetSha' => 'foo_sha',
'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
context 'there are other versions of this package' do
let(:depth) { 3 }
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
subject
......@@ -73,8 +140,32 @@ RSpec.describe 'package details' do
subject
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
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
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