Commit b51b57dc authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch 'ajk-graphql-packages' into 'master'

Packages to use composition, not inheritance [RUN AS-IF-FOSS]

See merge request gitlab-org/gitlab!52131
parents b6dce9d0 8e5772f8
# frozen_string_literal: true
module Resolvers
# No return types defined because they can be different.
# rubocop: disable Graphql/ResolverType
class PackageDetailsResolver < BaseResolver
type ::Types::Packages::PackageType, null: true
argument :id, ::Types::GlobalIDType[::Packages::Package],
required: true,
description: 'The global ID of the package.'
......
......@@ -2,7 +2,7 @@
module Resolvers
class PackagesResolver < BaseResolver
type Types::Packages::PackageType, null: true
type Types::Packages::PackageType.connection_type, null: true
def resolve(**args)
return unless packages_available?
......
# 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
......@@ -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
......
# 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
......@@ -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
# 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
......@@ -179,7 +179,7 @@ module Types
description: 'A single issue of the project',
resolver: Resolvers::IssuesResolver.single
field :packages, Types::Packages::PackageType.connection_type, null: true,
field :packages,
description: 'Packages of the project',
resolver: Resolvers::PackagesResolver
......
......@@ -58,9 +58,8 @@ module Types
argument :id, ::Types::GlobalIDType[::ContainerRepository], required: true, description: 'The global ID of the container repository'
end
field :package_composer_details, Types::Packages::Composer::DetailsType,
null: true,
description: 'Find a composer package',
field :package,
description: 'Find a package',
resolver: Resolvers::PackageDetailsResolver
field :user, Types::UserType,
......
......@@ -94,7 +94,6 @@ module Security
def gitlab_ci_yml_attributes
@gitlab_ci_yml_attributes ||= begin
config_content = @project.repository.blob_data_at(@project.repository.root_ref_sha, ci_config_file)
return {} unless config_content
build_sast_attributes(config_content)
......
---
title: 'Breaking change: Prevent mutual recursion in GraphQL Package'
merge_request: 52131
author:
type: fixed
......@@ -3879,6 +3879,21 @@ Identifier of ComplianceManagement::Framework.
"""
scalar ComplianceManagementFrameworkID
"""
Composer metadata
"""
type ComposerMetadata {
"""
Data of the Composer JSON file.
"""
composerJson: PackageComposerJsonType!
"""
Target SHA of the package.
"""
targetSha: String!
}
"""
Autogenerated input type of ConfigureSast
"""
......@@ -16880,142 +16895,27 @@ Represents a package in the Package Registry
"""
type Package {
"""
The created date.
Date of creation.
"""
createdAt: Time!
"""
The ID of the package.
"""
id: ID!
"""
The name of the package.
"""
name: String!
"""
The type of the package.
"""
packageType: PackageTypeEnum!
"""
Pipelines that built the package.
ID of the package.
"""
pipelines(
"""
Returns the elements in the list that come after the specified cursor.
"""
after: String
"""
Returns the elements in the list that come before the specified cursor.
"""
before: String
"""
Returns the first _n_ elements from the list.
"""
first: Int
"""
Returns the last _n_ elements from the list.
"""
last: Int
): PipelineConnection
id: PackagesPackageID!
"""
Project where the package is stored.
Package metadata.
"""
project: Project!
metadata: PackageMetadata
"""
The package tags.
"""
tags(
"""
Returns the elements in the list that come after the specified cursor.
"""
after: String
"""
Returns the elements in the list that come before the specified cursor.
"""
before: String
"""
Returns the first _n_ elements from the list.
"""
first: Int
"""
Returns the last _n_ elements from the list.
"""
last: Int
): PackageTagConnection
"""
The updated date.
"""
updatedAt: Time!
"""
The version of the package.
"""
version: String
"""
The other versions of the package.
"""
versions(
"""
Returns the elements in the list that come after the specified cursor.
"""
after: String
"""
Returns the elements in the list that come before the specified cursor.
"""
before: String
"""
Returns the first _n_ elements from the list.
"""
first: Int
"""
Returns the last _n_ elements from the list.
"""
last: Int
): PackageConnection
}
"""
Details of a Composer package
"""
type PackageComposerDetails {
"""
The Composer metadatum.
"""
composerMetadatum: PackageComposerMetadatumType!
"""
The created date.
"""
createdAt: Time!
"""
The ID of the package.
"""
id: ID!
"""
The name of the package.
Name of the package.
"""
name: String!
"""
The type of the package.
Package type.
"""
packageType: PackageTypeEnum!
......@@ -17050,7 +16950,7 @@ type PackageComposerDetails {
project: Project!
"""
The package tags.
Package tags.
"""
tags(
"""
......@@ -17075,12 +16975,12 @@ type PackageComposerDetails {
): PackageTagConnection
"""
The updated date.
Date of most recent update.
"""
updatedAt: Time!
"""
The version of the package.
Version string.
"""
version: String
......@@ -17107,7 +17007,7 @@ type PackageComposerDetails {
Returns the last _n_ elements from the list.
"""
last: Int
): PackageConnection
): PackageWithoutVersionsConnection
}
"""
......@@ -17135,21 +17035,6 @@ type PackageComposerJsonType {
version: String
}
"""
Composer metadatum
"""
type PackageComposerMetadatumType {
"""
Data of the Composer JSON file.
"""
composerJson: PackageComposerJsonType!
"""
Target SHA of the package.
"""
targetSha: String!
}
"""
The connection type for Package.
"""
......@@ -17265,6 +17150,11 @@ type PackageFileRegistryEdge {
node: PackageFileRegistry
}
"""
Represents metadata associated with a Package
"""
union PackageMetadata = ComposerMetadata
"""
Namespace-level Package Registry settings
"""
......@@ -17388,6 +17278,136 @@ enum PackageTypeEnum {
PYPI
}
"""
Represents a version of a package in the Package Registry
"""
type PackageWithoutVersions {
"""
Date of creation.
"""
createdAt: Time!
"""
ID of the package.
"""
id: PackagesPackageID!
"""
Package metadata.
"""
metadata: PackageMetadata
"""
Name of the package.
"""
name: String!
"""
Package type.
"""
packageType: PackageTypeEnum!
"""
Pipelines that built the package.
"""
pipelines(
"""
Returns the elements in the list that come after the specified cursor.
"""
after: String
"""
Returns the elements in the list that come before the specified cursor.
"""
before: String
"""
Returns the first _n_ elements from the list.
"""
first: Int
"""
Returns the last _n_ elements from the list.
"""
last: Int
): PipelineConnection
"""
Project where the package is stored.
"""
project: Project!
"""
Package tags.
"""
tags(
"""
Returns the elements in the list that come after the specified cursor.
"""
after: String
"""
Returns the elements in the list that come before the specified cursor.
"""
before: String
"""
Returns the first _n_ elements from the list.
"""
first: Int
"""
Returns the last _n_ elements from the list.
"""
last: Int
): PackageTagConnection
"""
Date of most recent update.
"""
updatedAt: Time!
"""
Version string.
"""
version: String
}
"""
The connection type for PackageWithoutVersions.
"""
type PackageWithoutVersionsConnection {
"""
A list of edges.
"""
edges: [PackageWithoutVersionsEdge]
"""
A list of nodes.
"""
nodes: [PackageWithoutVersions]
"""
Information to aid in pagination.
"""
pageInfo: PageInfo!
}
"""
An edge in a connection.
"""
type PackageWithoutVersionsEdge {
"""
A cursor for use in pagination.
"""
cursor: String!
"""
The item at the end of the edge.
"""
node: PackageWithoutVersions
}
"""
Identifier of Packages::Package.
"""
......@@ -20538,14 +20558,14 @@ type Query {
): Namespace
"""
Find a composer package
Find a package
"""
packageComposerDetails(
package(
"""
The global ID of the package.
"""
id: PackagesPackageID!
): PackageComposerDetails
): Package
"""
Find a project
......
......@@ -10566,6 +10566,55 @@
"enumValues": null,
"possibleTypes": null
},
{
"kind": "OBJECT",
"name": "ComposerMetadata",
"description": "Composer metadata",
"fields": [
{
"name": "composerJson",
"description": "Data of the Composer JSON file.",
"args": [
],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "OBJECT",
"name": "PackageComposerJsonType",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "targetSha",
"description": "Target SHA of the package.",
"args": [
],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
}
],
"inputFields": null,
"interfaces": [
],
"enumValues": null,
"possibleTypes": null
},
{
"kind": "INPUT_OBJECT",
"name": "ConfigureSastInput",
......@@ -49849,7 +49898,7 @@
"fields": [
{
"name": "createdAt",
"description": "The created date.",
"description": "Date of creation.",
"args": [
],
......@@ -49867,7 +49916,7 @@
},
{
"name": "id",
"description": "The ID of the package.",
"description": "ID of the package.",
"args": [
],
......@@ -49876,16 +49925,30 @@
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "ID",
"name": "PackagesPackageID",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "metadata",
"description": "Package metadata.",
"args": [
],
"type": {
"kind": "UNION",
"name": "PackageMetadata",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "name",
"description": "The name of the package.",
"description": "Name of the package.",
"args": [
],
......@@ -49903,7 +49966,7 @@
},
{
"name": "packageType",
"description": "The type of the package.",
"description": "Package type.",
"args": [
],
......@@ -49992,7 +50055,7 @@
},
{
"name": "tags",
"description": "The package tags.",
"description": "Package tags.",
"args": [
{
"name": "after",
......@@ -50045,7 +50108,7 @@
},
{
"name": "updatedAt",
"description": "The updated date.",
"description": "Date of most recent update.",
"args": [
],
......@@ -50063,7 +50126,7 @@
},
{
"name": "version",
"description": "The version of the package.",
"description": "Version string.",
"args": [
],
......@@ -50122,7 +50185,7 @@
],
"type": {
"kind": "OBJECT",
"name": "PackageConnection",
"name": "PackageWithoutVersionsConnection",
"ofType": null
},
"isDeprecated": false,
......@@ -50138,93 +50201,90 @@
},
{
"kind": "OBJECT",
"name": "PackageComposerDetails",
"description": "Details of a Composer package",
"name": "PackageComposerJsonType",
"description": "Represents a composer JSON file",
"fields": [
{
"name": "composerMetadatum",
"description": "The Composer metadatum.",
"name": "license",
"description": "The license set in the Composer JSON file.",
"args": [
],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "OBJECT",
"name": "PackageComposerMetadatumType",
"ofType": null
}
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "createdAt",
"description": "The created date.",
"name": "name",
"description": "The name set in the Composer JSON file.",
"args": [
],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "Time",
"ofType": null
}
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "id",
"description": "The ID of the package.",
"name": "type",
"description": "The type set in the Composer JSON file.",
"args": [
],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "ID",
"ofType": null
}
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "name",
"description": "The name of the package.",
"name": "version",
"description": "The version set in the Composer JSON file.",
"args": [
],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
}
],
"inputFields": null,
"interfaces": [
],
"enumValues": null,
"possibleTypes": null
},
{
"kind": "OBJECT",
"name": "PackageConnection",
"description": "The connection type for Package.",
"fields": [
{
"name": "packageType",
"description": "The type of the package.",
"name": "edges",
"description": "A list of edges.",
"args": [
],
"type": {
"kind": "NON_NULL",
"kind": "LIST",
"name": null,
"ofType": {
"kind": "ENUM",
"name": "PackageTypeEnum",
"kind": "OBJECT",
"name": "PackageEdge",
"ofType": null
}
},
......@@ -50232,61 +50292,26 @@
"deprecationReason": null
},
{
"name": "pipelines",
"description": "Pipelines that built the package.",
"name": "nodes",
"description": "A list of nodes.",
"args": [
{
"name": "after",
"description": "Returns the elements in the list that come after the specified cursor.",
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"defaultValue": null
},
{
"name": "before",
"description": "Returns the elements in the list that come before the specified cursor.",
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"defaultValue": null
},
{
"name": "first",
"description": "Returns the first _n_ elements from the list.",
"type": {
"kind": "SCALAR",
"name": "Int",
"ofType": null
},
"defaultValue": null
},
{
"name": "last",
"description": "Returns the last _n_ elements from the list.",
"type": {
"kind": "SCALAR",
"name": "Int",
"ofType": null
},
"defaultValue": null
}
],
"type": {
"kind": "OBJECT",
"name": "PipelineConnection",
"ofType": null
"kind": "LIST",
"name": null,
"ofType": {
"kind": "OBJECT",
"name": "Package",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "project",
"description": "Project where the package is stored.",
"name": "pageInfo",
"description": "Information to aid in pagination.",
"args": [
],
......@@ -50295,69 +50320,29 @@
"name": null,
"ofType": {
"kind": "OBJECT",
"name": "Project",
"name": "PageInfo",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "tags",
"description": "The package tags.",
"args": [
{
"name": "after",
"description": "Returns the elements in the list that come after the specified cursor.",
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"defaultValue": null
},
{
"name": "before",
"description": "Returns the elements in the list that come before the specified cursor.",
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"defaultValue": null
},
{
"name": "first",
"description": "Returns the first _n_ elements from the list.",
"type": {
"kind": "SCALAR",
"name": "Int",
"ofType": null
},
"defaultValue": null
},
{
"name": "last",
"description": "Returns the last _n_ elements from the list.",
"type": {
"kind": "SCALAR",
"name": "Int",
"ofType": null
},
"defaultValue": null
}
],
"type": {
"kind": "OBJECT",
"name": "PackageTagConnection",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
}
],
"inputFields": null,
"interfaces": [
],
"enumValues": null,
"possibleTypes": null
},
{
"kind": "OBJECT",
"name": "PackageEdge",
"description": "An edge in a connection.",
"fields": [
{
"name": "updatedAt",
"description": "The updated date.",
"name": "cursor",
"description": "A cursor for use in pagination.",
"args": [
],
......@@ -50366,7 +50351,7 @@
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "Time",
"name": "String",
"ofType": null
}
},
......@@ -50374,67 +50359,14 @@
"deprecationReason": null
},
{
"name": "version",
"description": "The version of the package.",
"name": "node",
"description": "The item at the end of the edge.",
"args": [
],
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "versions",
"description": "The other versions of the package.",
"args": [
{
"name": "after",
"description": "Returns the elements in the list that come after the specified cursor.",
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"defaultValue": null
},
{
"name": "before",
"description": "Returns the elements in the list that come before the specified cursor.",
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"defaultValue": null
},
{
"name": "first",
"description": "Returns the first _n_ elements from the list.",
"type": {
"kind": "SCALAR",
"name": "Int",
"ofType": null
},
"defaultValue": null
},
{
"name": "last",
"description": "Returns the last _n_ elements from the list.",
"type": {
"kind": "SCALAR",
"name": "Int",
"ofType": null
},
"defaultValue": null
}
],
"type": {
"kind": "OBJECT",
"name": "PackageConnection",
"name": "Package",
"ofType": null
},
"isDeprecated": false,
......@@ -50450,40 +50382,44 @@
},
{
"kind": "OBJECT",
"name": "PackageComposerJsonType",
"description": "Represents a composer JSON file",
"name": "PackageFileRegistry",
"description": "Represents the Geo sync and verification state of a package file",
"fields": [
{
"name": "license",
"description": "The license set in the Composer JSON file.",
"name": "createdAt",
"description": "Timestamp when the PackageFileRegistry was created",
"args": [
],
"type": {
"kind": "SCALAR",
"name": "String",
"name": "Time",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "name",
"description": "The name set in the Composer JSON file.",
"name": "id",
"description": "ID of the PackageFileRegistry",
"args": [
],
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "ID",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "type",
"description": "The type set in the Composer JSON file.",
"name": "lastSyncFailure",
"description": "Error message during sync of the PackageFileRegistry",
"args": [
],
......@@ -50496,35 +50432,22 @@
"deprecationReason": null
},
{
"name": "version",
"description": "The version set in the Composer JSON file.",
"name": "lastSyncedAt",
"description": "Timestamp of the most recent successful sync of the PackageFileRegistry",
"args": [
],
"type": {
"kind": "SCALAR",
"name": "String",
"name": "Time",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
}
],
"inputFields": null,
"interfaces": [
],
"enumValues": null,
"possibleTypes": null
},
{
"kind": "OBJECT",
"name": "PackageComposerMetadatumType",
"description": "Composer metadatum",
"fields": [
},
{
"name": "composerJson",
"description": "Data of the Composer JSON file.",
"name": "packageFileId",
"description": "ID of the PackageFile",
"args": [
],
......@@ -50532,8 +50455,8 @@
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "OBJECT",
"name": "PackageComposerJsonType",
"kind": "SCALAR",
"name": "ID",
"ofType": null
}
},
......@@ -50541,19 +50464,43 @@
"deprecationReason": null
},
{
"name": "targetSha",
"description": "Target SHA of the package.",
"name": "retryAt",
"description": "Timestamp after which the PackageFileRegistry should be resynced",
"args": [
],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
"kind": "SCALAR",
"name": "Time",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "retryCount",
"description": "Number of consecutive failed sync attempts of the PackageFileRegistry",
"args": [
],
"type": {
"kind": "SCALAR",
"name": "Int",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "state",
"description": "Sync state of the PackageFileRegistry",
"args": [
],
"type": {
"kind": "ENUM",
"name": "RegistryState",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
......@@ -50568,8 +50515,8 @@
},
{
"kind": "OBJECT",
"name": "PackageConnection",
"description": "The connection type for Package.",
"name": "PackageFileRegistryConnection",
"description": "The connection type for PackageFileRegistry.",
"fields": [
{
"name": "edges",
......@@ -50582,7 +50529,7 @@
"name": null,
"ofType": {
"kind": "OBJECT",
"name": "PackageEdge",
"name": "PackageFileRegistryEdge",
"ofType": null
}
},
......@@ -50600,7 +50547,7 @@
"name": null,
"ofType": {
"kind": "OBJECT",
"name": "Package",
"name": "PackageFileRegistry",
"ofType": null
}
},
......@@ -50635,7 +50582,7 @@
},
{
"kind": "OBJECT",
"name": "PackageEdge",
"name": "PackageFileRegistryEdge",
"description": "An edge in a connection.",
"fields": [
{
......@@ -50664,7 +50611,7 @@
],
"type": {
"kind": "OBJECT",
"name": "Package",
"name": "PackageFileRegistry",
"ofType": null
},
"isDeprecated": false,
......@@ -50678,28 +50625,44 @@
"enumValues": null,
"possibleTypes": null
},
{
"kind": "UNION",
"name": "PackageMetadata",
"description": "Represents metadata associated with a Package",
"fields": null,
"inputFields": null,
"interfaces": null,
"enumValues": null,
"possibleTypes": [
{
"kind": "OBJECT",
"name": "ComposerMetadata",
"ofType": null
}
]
},
{
"kind": "OBJECT",
"name": "PackageFileRegistry",
"description": "Represents the Geo sync and verification state of a package file",
"name": "PackageSettings",
"description": "Namespace-level Package Registry settings",
"fields": [
{
"name": "createdAt",
"description": "Timestamp when the PackageFileRegistry was created",
"name": "mavenDuplicateExceptionRegex",
"description": "When maven_duplicates_allowed is false, you can publish duplicate packages with names that match this regex. Otherwise, this setting has no effect.",
"args": [
],
"type": {
"kind": "SCALAR",
"name": "Time",
"name": "UntrustedRegexp",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "id",
"description": "ID of the PackageFileRegistry",
"name": "mavenDuplicatesAllowed",
"description": "Indicates whether duplicate Maven packages are allowed for this namespace.",
"args": [
],
......@@ -50708,44 +50671,47 @@
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "ID",
"name": "Boolean",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "lastSyncFailure",
"description": "Error message during sync of the PackageFileRegistry",
"args": [
}
],
"inputFields": null,
"interfaces": [
],
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
],
"enumValues": null,
"possibleTypes": null
},
{
"kind": "OBJECT",
"name": "PackageTag",
"description": "Represents a package tag",
"fields": [
{
"name": "lastSyncedAt",
"description": "Timestamp of the most recent successful sync of the PackageFileRegistry",
"name": "createdAt",
"description": "The created date.",
"args": [
],
"type": {
"kind": "SCALAR",
"name": "Time",
"ofType": null
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "Time",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "packageFileId",
"description": "ID of the PackageFile",
"name": "id",
"description": "The ID of the tag.",
"args": [
],
......@@ -50762,43 +50728,37 @@
"deprecationReason": null
},
{
"name": "retryAt",
"description": "Timestamp after which the PackageFileRegistry should be resynced",
"args": [
],
"type": {
"kind": "SCALAR",
"name": "Time",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "retryCount",
"description": "Number of consecutive failed sync attempts of the PackageFileRegistry",
"name": "name",
"description": "The name of the tag.",
"args": [
],
"type": {
"kind": "SCALAR",
"name": "Int",
"ofType": null
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "state",
"description": "Sync state of the PackageFileRegistry",
"name": "updatedAt",
"description": "The updated date.",
"args": [
],
"type": {
"kind": "ENUM",
"name": "RegistryState",
"ofType": null
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "Time",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
......@@ -50813,8 +50773,8 @@
},
{
"kind": "OBJECT",
"name": "PackageFileRegistryConnection",
"description": "The connection type for PackageFileRegistry.",
"name": "PackageTagConnection",
"description": "The connection type for PackageTag.",
"fields": [
{
"name": "edges",
......@@ -50827,7 +50787,7 @@
"name": null,
"ofType": {
"kind": "OBJECT",
"name": "PackageFileRegistryEdge",
"name": "PackageTagEdge",
"ofType": null
}
},
......@@ -50845,7 +50805,7 @@
"name": null,
"ofType": {
"kind": "OBJECT",
"name": "PackageFileRegistry",
"name": "PackageTag",
"ofType": null
}
},
......@@ -50880,7 +50840,7 @@
},
{
"kind": "OBJECT",
"name": "PackageFileRegistryEdge",
"name": "PackageTagEdge",
"description": "An edge in a connection.",
"fields": [
{
......@@ -50909,7 +50869,7 @@
],
"type": {
"kind": "OBJECT",
"name": "PackageFileRegistry",
"name": "PackageTag",
"ofType": null
},
"isDeprecated": false,
......@@ -50923,28 +50883,97 @@
"enumValues": null,
"possibleTypes": null
},
{
"kind": "ENUM",
"name": "PackageTypeEnum",
"description": null,
"fields": null,
"inputFields": null,
"interfaces": null,
"enumValues": [
{
"name": "MAVEN",
"description": "Packages from the Maven package manager",
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "NPM",
"description": "Packages from the NPM package manager",
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "CONAN",
"description": "Packages from the Conan package manager",
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "NUGET",
"description": "Packages from the Nuget package manager",
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "PYPI",
"description": "Packages from the PyPI package manager",
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "COMPOSER",
"description": "Packages from the Composer package manager",
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "GENERIC",
"description": "Packages from the Generic package manager",
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "GOLANG",
"description": "Packages from the Golang package manager",
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "DEBIAN",
"description": "Packages from the Debian package manager",
"isDeprecated": false,
"deprecationReason": null
}
],
"possibleTypes": null
},
{
"kind": "OBJECT",
"name": "PackageSettings",
"description": "Namespace-level Package Registry settings",
"name": "PackageWithoutVersions",
"description": "Represents a version of a package in the Package Registry",
"fields": [
{
"name": "mavenDuplicateExceptionRegex",
"description": "When maven_duplicates_allowed is false, you can publish duplicate packages with names that match this regex. Otherwise, this setting has no effect.",
"name": "createdAt",
"description": "Date of creation.",
"args": [
],
"type": {
"kind": "SCALAR",
"name": "UntrustedRegexp",
"ofType": null
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "Time",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "mavenDuplicatesAllowed",
"description": "Indicates whether duplicate Maven packages are allowed for this namespace.",
"name": "id",
"description": "ID of the package.",
"args": [
],
......@@ -50953,29 +50982,30 @@
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "Boolean",
"name": "PackagesPackageID",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
}
],
"inputFields": null,
"interfaces": [
},
{
"name": "metadata",
"description": "Package metadata.",
"args": [
],
"enumValues": null,
"possibleTypes": null
},
{
"kind": "OBJECT",
"name": "PackageTag",
"description": "Represents a package tag",
"fields": [
],
"type": {
"kind": "UNION",
"name": "PackageMetadata",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "createdAt",
"description": "The created date.",
"name": "name",
"description": "Name of the package.",
"args": [
],
......@@ -50984,7 +51014,7 @@
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "Time",
"name": "String",
"ofType": null
}
},
......@@ -50992,8 +51022,8 @@
"deprecationReason": null
},
{
"name": "id",
"description": "The ID of the tag.",
"name": "packageType",
"description": "Package type.",
"args": [
],
......@@ -51001,8 +51031,8 @@
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "ID",
"kind": "ENUM",
"name": "PackageTypeEnum",
"ofType": null
}
},
......@@ -51010,8 +51040,61 @@
"deprecationReason": null
},
{
"name": "name",
"description": "The name of the tag.",
"name": "pipelines",
"description": "Pipelines that built the package.",
"args": [
{
"name": "after",
"description": "Returns the elements in the list that come after the specified cursor.",
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"defaultValue": null
},
{
"name": "before",
"description": "Returns the elements in the list that come before the specified cursor.",
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"defaultValue": null
},
{
"name": "first",
"description": "Returns the first _n_ elements from the list.",
"type": {
"kind": "SCALAR",
"name": "Int",
"ofType": null
},
"defaultValue": null
},
{
"name": "last",
"description": "Returns the last _n_ elements from the list.",
"type": {
"kind": "SCALAR",
"name": "Int",
"ofType": null
},
"defaultValue": null
}
],
"type": {
"kind": "OBJECT",
"name": "PipelineConnection",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "project",
"description": "Project where the package is stored.",
"args": [
],
......@@ -51019,17 +51102,70 @@
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"kind": "OBJECT",
"name": "Project",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "tags",
"description": "Package tags.",
"args": [
{
"name": "after",
"description": "Returns the elements in the list that come after the specified cursor.",
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"defaultValue": null
},
{
"name": "before",
"description": "Returns the elements in the list that come before the specified cursor.",
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"defaultValue": null
},
{
"name": "first",
"description": "Returns the first _n_ elements from the list.",
"type": {
"kind": "SCALAR",
"name": "Int",
"ofType": null
},
"defaultValue": null
},
{
"name": "last",
"description": "Returns the last _n_ elements from the list.",
"type": {
"kind": "SCALAR",
"name": "Int",
"ofType": null
},
"defaultValue": null
}
],
"type": {
"kind": "OBJECT",
"name": "PackageTagConnection",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "updatedAt",
"description": "The updated date.",
"description": "Date of most recent update.",
"args": [
],
......@@ -51044,6 +51180,20 @@
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "version",
"description": "Version string.",
"args": [
],
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
}
],
"inputFields": null,
......@@ -51055,8 +51205,8 @@
},
{
"kind": "OBJECT",
"name": "PackageTagConnection",
"description": "The connection type for PackageTag.",
"name": "PackageWithoutVersionsConnection",
"description": "The connection type for PackageWithoutVersions.",
"fields": [
{
"name": "edges",
......@@ -51069,7 +51219,7 @@
"name": null,
"ofType": {
"kind": "OBJECT",
"name": "PackageTagEdge",
"name": "PackageWithoutVersionsEdge",
"ofType": null
}
},
......@@ -51087,7 +51237,7 @@
"name": null,
"ofType": {
"kind": "OBJECT",
"name": "PackageTag",
"name": "PackageWithoutVersions",
"ofType": null
}
},
......@@ -51122,7 +51272,7 @@
},
{
"kind": "OBJECT",
"name": "PackageTagEdge",
"name": "PackageWithoutVersionsEdge",
"description": "An edge in a connection.",
"fields": [
{
......@@ -51151,7 +51301,7 @@
],
"type": {
"kind": "OBJECT",
"name": "PackageTag",
"name": "PackageWithoutVersions",
"ofType": null
},
"isDeprecated": false,
......@@ -51165,71 +51315,6 @@
"enumValues": null,
"possibleTypes": null
},
{
"kind": "ENUM",
"name": "PackageTypeEnum",
"description": null,
"fields": null,
"inputFields": null,
"interfaces": null,
"enumValues": [
{
"name": "MAVEN",
"description": "Packages from the Maven package manager",
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "NPM",
"description": "Packages from the NPM package manager",
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "CONAN",
"description": "Packages from the Conan package manager",
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "NUGET",
"description": "Packages from the Nuget package manager",
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "PYPI",
"description": "Packages from the PyPI package manager",
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "COMPOSER",
"description": "Packages from the Composer package manager",
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "GENERIC",
"description": "Packages from the Generic package manager",
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "GOLANG",
"description": "Packages from the Golang package manager",
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "DEBIAN",
"description": "Packages from the Debian package manager",
"isDeprecated": false,
"deprecationReason": null
}
],
"possibleTypes": null
},
{
"kind": "SCALAR",
"name": "PackagesPackageID",
......@@ -59703,8 +59788,8 @@
"deprecationReason": null
},
{
"name": "packageComposerDetails",
"description": "Find a composer package",
"name": "package",
"description": "Find a package",
"args": [
{
"name": "id",
......@@ -59723,7 +59808,7 @@
],
"type": {
"kind": "OBJECT",
"name": "PackageComposerDetails",
"name": "Package",
"ofType": null
},
"isDeprecated": false,
......@@ -593,6 +593,15 @@ Represents a ComplianceFramework associated with a Project.
| `name` | String! | Name of the compliance framework |
| `pipelineConfigurationFullPath` | String | Full path of the compliance pipeline configuration stored in a project repository, such as `.gitlab/compliance/soc2/.gitlab-ci.yml`. |
### ComposerMetadata
Composer metadata.
| Field | Type | Description |
| ----- | ---- | ----------- |
| `composerJson` | PackageComposerJsonType! | Data of the Composer JSON file. |
| `targetSha` | String! | Target SHA of the package. |
### ConfigureSastPayload
Autogenerated return type of ConfigureSast.
......@@ -2541,34 +2550,17 @@ Represents a package in the Package Registry.
| Field | Type | Description |
| ----- | ---- | ----------- |
| `createdAt` | Time! | The created date. |
| `id` | ID! | The ID of the package. |
| `name` | String! | The name of the package. |
| `packageType` | PackageTypeEnum! | The type of the package. |
| `pipelines` | PipelineConnection | Pipelines that built the package. |
| `project` | Project! | Project where the package is stored. |
| `tags` | PackageTagConnection | The package tags. |
| `updatedAt` | Time! | The updated date. |
| `version` | String | The version of the package. |
| `versions` | PackageConnection | The other versions of the package. |
### PackageComposerDetails
Details of a Composer package.
| Field | Type | Description |
| ----- | ---- | ----------- |
| `composerMetadatum` | PackageComposerMetadatumType! | The Composer metadatum. |
| `createdAt` | Time! | The created date. |
| `id` | ID! | The ID of the package. |
| `name` | String! | The name of the package. |
| `packageType` | PackageTypeEnum! | The type of the package. |
| `createdAt` | Time! | Date of creation. |
| `id` | PackagesPackageID! | ID of the package. |
| `metadata` | PackageMetadata | Package metadata. |
| `name` | String! | Name of the package. |
| `packageType` | PackageTypeEnum! | Package type. |
| `pipelines` | PipelineConnection | Pipelines that built the package. |
| `project` | Project! | Project where the package is stored. |
| `tags` | PackageTagConnection | The package tags. |
| `updatedAt` | Time! | The updated date. |
| `version` | String | The version of the package. |
| `versions` | PackageConnection | The other versions of the package. |
| `tags` | PackageTagConnection | Package tags. |
| `updatedAt` | Time! | Date of most recent update. |
| `version` | String | Version string. |
| `versions` | PackageWithoutVersionsConnection | The other versions of the package. |
### PackageComposerJsonType
......@@ -2581,15 +2573,6 @@ Represents a composer JSON file.
| `type` | String | The type set in the Composer JSON file. |
| `version` | String | The version set in the Composer JSON file. |
### PackageComposerMetadatumType
Composer metadatum.
| Field | Type | Description |
| ----- | ---- | ----------- |
| `composerJson` | PackageComposerJsonType! | Data of the Composer JSON file. |
| `targetSha` | String! | Target SHA of the package. |
### PackageFileRegistry
Represents the Geo sync and verification state of a package file.
......@@ -2625,6 +2608,23 @@ Represents a package tag.
| `name` | String! | The name of the tag. |
| `updatedAt` | Time! | The updated date. |
### PackageWithoutVersions
Represents a version of a package in the Package Registry.
| Field | Type | Description |
| ----- | ---- | ----------- |
| `createdAt` | Time! | Date of creation. |
| `id` | PackagesPackageID! | ID of the package. |
| `metadata` | PackageMetadata | Package metadata. |
| `name` | String! | Name of the package. |
| `packageType` | PackageTypeEnum! | Package type. |
| `pipelines` | PipelineConnection | Pipelines that built the package. |
| `project` | Project! | Project where the package is stored. |
| `tags` | PackageTagConnection | Package tags. |
| `updatedAt` | Time! | Date of most recent update. |
| `version` | String | Version string. |
### PageInfo
Information about pagination in a connection..
......
{
"type": "object",
"allOf": [{ "$ref": "./package_details.json" }],
"properties": {
"target_sha": {
"type": "string"
},
"composer_json": {
"type": "object"
}
}
}
{
"type": "object",
"additionalProperties": false,
"required": ["targetSha", "composerJson"],
"properties": {
"targetSha": {
"type": "string"
},
"composerJson": {
"type": "object",
"additionalProperties": false,
"required": ["name", "type", "license", "version"],
"properties": {
"name": { "type": "string" },
"type": { "type": "string" },
"license": { "type": "string" },
"version": { "type": "string" }
}
}
}
}
{
"type": "object",
"additionalProperties": false,
"required": [
"id", "name", "createdAt", "updatedAt", "version", "packageType",
"project", "tags", "pipelines", "versions", "metadata"
],
"properties": {
"id": {
"type": "string"
......@@ -16,21 +21,46 @@
"version": {
"type": ["string", "null"]
},
"package_type": {
"packageType": {
"type": ["string"],
"enum": ["MAVEN", "NPM", "CONAN", "NUGET", "PYPI", "COMPOSER", "GENERIC", "GOLANG", "DEBIAN"]
},
"tags": {
"type": "object"
"type": "object",
"additionalProperties": false,
"properties": {
"pageInfo": { "type": "object" },
"edges": { "type": "array" },
"nodes": { "type": "array" }
}
},
"project": {
"type": "object"
},
"pipelines": {
"type": "object"
"type": "object",
"additionalProperties": false,
"properties": {
"pageInfo": { "type": "object" },
"count": { "type": "integer" },
"edges": { "type": "array" },
"nodes": { "type": "array" }
}
},
"versions": {
"type": "object"
"type": "object",
"additionalProperties": false,
"properties": {
"pageInfo": { "type": "object" },
"edges": { "type": "array" },
"nodes": { "type": "array" }
}
},
"metadata": {
"anyOf": [
{ "$ref": "./package_composer_metadata.json" },
{ "type": "null" }
]
}
}
}
......@@ -4,6 +4,7 @@ require 'spec_helper'
RSpec.describe Resolvers::PackageDetailsResolver do
include GraphqlHelpers
include ::Gitlab::Graphql::Laziness
let_it_be_with_reload(:project) { create(:project) }
let_it_be(:user) { project.owner }
......@@ -11,10 +12,10 @@ RSpec.describe Resolvers::PackageDetailsResolver do
describe '#resolve' do
let(:args) do
{ id: package.to_global_id.to_s }
{ id: global_id_of(package) }
end
subject { resolve(described_class, ctx: { current_user: user }, args: args).sync }
subject { force(resolve(described_class, ctx: { current_user: user }, args: args)) }
it { is_expected.to eq(package) }
end
......
......@@ -2,9 +2,7 @@
require 'spec_helper'
RSpec.describe GitlabSchema.types['PackageComposerMetadatumType'] do
it { expect(described_class.graphql_name).to eq('PackageComposerMetadatumType') }
RSpec.describe GitlabSchema.types['ComposerMetadata'] do
it 'includes composer metadatum fields' do
expected_fields = %w[
target_sha composer_json
......
......@@ -3,11 +3,12 @@
require 'spec_helper'
RSpec.describe GitlabSchema.types['Package'] do
it { expect(described_class.graphql_name).to eq('Package') }
it 'includes all the package fields' do
expected_fields = %w[
id name version created_at updated_at package_type tags project pipelines versions
id name version package_type
created_at updated_at
project
tags pipelines versions
]
expect(described_class).to include_graphql_fields(*expected_fields)
......
......@@ -2,20 +2,10 @@
require 'spec_helper'
RSpec.describe GitlabSchema.types['PackageComposerDetails'] do
it { expect(described_class.graphql_name).to eq('PackageComposerDetails') }
RSpec.describe GitlabSchema.types['PackageWithoutVersions'] do
it 'includes all the package fields' do
expected_fields = %w[
id name version created_at updated_at package_type tags project pipelines versions
]
expect(described_class).to include_graphql_fields(*expected_fields)
end
it 'includes composer specific files' do
expected_fields = %w[
composer_metadatum
id name version created_at updated_at package_type tags project pipelines
]
expect(described_class).to include_graphql_fields(*expected_fields)
......
......@@ -95,9 +95,9 @@ RSpec.describe GitlabSchema.types['Query'] do
it { is_expected.to have_graphql_type(Types::ContainerRepositoryDetailsType) }
end
describe 'package_composer_details field' do
subject { described_class.fields['packageComposerDetails'] }
describe 'package field' do
subject { described_class.fields['package'] }
it { is_expected.to have_graphql_type(Types::Packages::Composer::DetailsType) }
it { is_expected.to have_graphql_type(Types::Packages::PackageType) }
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'package composer details' do
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_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: { name: 'name', type: 'type', license: 'license', version: 1 })
create(:composer_metadatum, package: package, target_sha: 'foo_sha', composer_json: composer_json)
end
let(:depth) { 3 }
let(:excluded) { ['metadata'] }
let(:query) do
graphql_query_for(
'packageComposerDetails',
{ id: package_global_id },
all_graphql_fields_for('PackageComposerDetails', max_depth: 2)
)
graphql_query_for(:package, { id: package_global_id }, <<~FIELDS)
#{all_graphql_fields_for('Package', max_depth: depth, excluded: excluded)}
metadata {
#{query_graphql_fragment('ComposerMetadata')}
}
FIELDS
end
let(:user) { project.owner }
let(:package_global_id) { package.to_global_id.to_s }
let(:package_composer_details_response) { graphql_data.dig('packageComposerDetails') }
let(:package_global_id) { global_id_of(package) }
let(:package_details) { graphql_data_at(:package) }
subject { post_graphql(query, current_user: user) }
......@@ -33,7 +38,43 @@ RSpec.describe 'package composer details' do
end
it 'matches the JSON schema' do
expect(package_composer_details_response).to match_schema('graphql/packages/package_composer_details')
expect(package_details).to match_schema('graphql/packages/package_details')
end
it 'includes the fields of the correct package' do
expect(package_details).to include(
'id' => package_global_id,
'metadata' => {
'targetSha' => 'foo_sha',
'composerJson' => composer_json.transform_keys(&:to_s).transform_values(&:to_s)
}
)
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) }
it 'includes the sibling versions' do
subject
expect(graphql_data_at(:package, :versions, :nodes)).to match_array(
siblings.map { |p| a_hash_including('id' => global_id_of(p)) }
)
end
context 'going deeper' do
let(:depth) { 6 }
it 'does not create a cycle of versions' 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
end
end
end
end
......@@ -5,16 +5,27 @@ require 'spec_helper'
RSpec.describe 'getting a package list for a project' do
include GraphqlHelpers
let_it_be(:project) { create(:project) }
let_it_be(:project) { create(:project, :repository) }
let_it_be(:current_user) { create(:user) }
let_it_be(:package) { create(:package, project: project) }
let(:packages_data) { graphql_data['project']['packages']['edges'] }
let_it_be(:maven_package) { create(:maven_package, project: project) }
let_it_be(:debian_package) { create(:debian_package, project: project) }
let_it_be(:composer_package) { create(:composer_package, project: project) }
let_it_be(:composer_metadatum) do
create(:composer_metadatum, package: composer_package,
target_sha: 'afdeh',
composer_json: { name: 'x', type: 'y', license: 'z', version: 1 })
end
let(:package_names) { graphql_data_at(:project, :packages, :edges, :node, :name) }
let(:fields) do
<<~QUERY
edges {
node {
#{all_graphql_fields_for('packages'.classify)}
#{all_graphql_fields_for('packages'.classify, excluded: ['project'])}
metadata { #{query_graphql_fragment('ComposerMetadata')} }
}
}
QUERY
......@@ -37,7 +48,17 @@ RSpec.describe 'getting a package list for a project' do
it_behaves_like 'a working graphql query'
it 'returns packages successfully' do
expect(packages_data[0]['node']['name']).to eq package.name
expect(package_names).to contain_exactly(
package.name,
maven_package.name,
debian_package.name,
composer_package.name
)
end
it 'deals with metadata' do
target_shas = graphql_data_at(:project, :packages, :edges, :node, :metadata, :target_sha)
expect(target_shas).to contain_exactly(composer_metadatum.target_sha)
end
end
......@@ -53,7 +74,7 @@ RSpec.describe 'getting a package list for a project' do
end
end
context 'when the user is not autenthicated' do
context 'when the user is not authenticated' do
before do
post_graphql(query)
end
......
......@@ -47,7 +47,7 @@ module Graphql
NO_SKIP = ->(_name, _field) { false }
def self.select_fields(type, skip = NO_SKIP, parent_types = Set.new, max_depth = 3)
return new if max_depth <= 0
return new if max_depth <= 0 || !type.kind.fields?
new(type.fields.flat_map do |name, field|
next [] if skip[name, field]
......
......@@ -237,6 +237,10 @@ module GraphqlHelpers
query_graphql_path([[name, args], node_selection], fields)
end
def query_graphql_fragment(name)
"... on #{name} { #{all_graphql_fields_for(name)} }"
end
# e.g:
# query_graphql_path(%i[foo bar baz], all_graphql_fields_for('Baz'))
# => foo { bar { baz { x y z } } }
......
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