diff options
author | Robert Speicher <rspeicher@gmail.com> | 2021-01-20 22:34:23 +0300 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2021-01-20 22:34:23 +0300 |
commit | 6438df3a1e0fb944485cebf07976160184697d72 (patch) | |
tree | 00b09bfd170e77ae9391b1a2f5a93ef6839f2597 /app/graphql/types | |
parent | 42bcd54d971da7ef2854b896a7b34f4ef8601067 (diff) |
Add latest changes from gitlab-org/gitlab@13-8-stable-eev13.8.0-rc42
Diffstat (limited to 'app/graphql/types')
33 files changed, 332 insertions, 60 deletions
diff --git a/app/graphql/types/admin/analytics/instance_statistics/measurement_type.rb b/app/graphql/types/admin/analytics/instance_statistics/measurement_type.rb index d45341077a4..eab42c2b78d 100644 --- a/app/graphql/types/admin/analytics/instance_statistics/measurement_type.rb +++ b/app/graphql/types/admin/analytics/instance_statistics/measurement_type.rb @@ -1,14 +1,16 @@ # frozen_string_literal: true -# rubocop:disable Graphql/AuthorizeTypes module Types module Admin module Analytics module InstanceStatistics class MeasurementType < BaseObject + include Gitlab::Graphql::Authorize::AuthorizeResource graphql_name 'InstanceStatisticsMeasurement' description 'Represents a recorded measurement (object count) for the Admins' + authorize :read_instance_statistics_measurements + field :recorded_at, Types::TimeType, null: true, description: 'The time the measurement was recorded' diff --git a/app/graphql/types/alert_management/domain_filter_enum.rb b/app/graphql/types/alert_management/domain_filter_enum.rb index 58dbc8bb2cf..a798cfb9ee9 100644 --- a/app/graphql/types/alert_management/domain_filter_enum.rb +++ b/app/graphql/types/alert_management/domain_filter_enum.rb @@ -6,7 +6,7 @@ module Types graphql_name 'AlertManagementDomainFilter' description 'Filters the alerts based on given domain' - value 'operations', description: 'Alerts for operations domain ' + value 'operations', description: 'Alerts for operations domain' value 'threat_monitoring', description: 'Alerts for threat monitoring domain' end end diff --git a/app/graphql/types/base_enum.rb b/app/graphql/types/base_enum.rb index 159443641bc..cbd45b46dd6 100644 --- a/app/graphql/types/base_enum.rb +++ b/app/graphql/types/base_enum.rb @@ -5,6 +5,25 @@ module Types extend GitlabStyleDeprecations class << self + # Registers enum definition by the given DeclarativeEnum module + # + # @param enum_mod [Module] The enum module to be used + # @param use_name [Boolean] Does not override the name if set `false` + # @param use_description [Boolean] Does not override the description if set `false` + # + # Example: + # + # class MyEnum < BaseEnum + # declarative_enum MyDeclarativeEnum + # end + # + def declarative_enum(enum_mod, use_name: true, use_description: true) + graphql_name(enum_mod.name) if use_name + description(enum_mod.description) if use_description + + enum_mod.definition.each { |key, content| value(key.to_s.upcase, content) } + end + def value(*args, **kwargs, &block) enum[args[0].downcase] = kwargs[:value] || args[0] kwargs = gitlab_deprecation(kwargs) diff --git a/app/graphql/types/board_type.rb b/app/graphql/types/board_type.rb index f47c744d1bb..f576fd83840 100644 --- a/app/graphql/types/board_type.rb +++ b/app/graphql/types/board_type.rb @@ -7,6 +7,8 @@ module Types accepts ::Board authorize :read_board + present_using BoardPresenter + field :id, type: GraphQL::ID_TYPE, null: false, description: 'ID (global ID) of the board' field :name, type: GraphQL::STRING_TYPE, null: true, @@ -24,6 +26,12 @@ module Types description: 'Lists of the board', resolver: Resolvers::BoardListsResolver, extras: [:lookahead] + + field :web_path, GraphQL::STRING_TYPE, null: false, + description: 'Web path of the board.' + + field :web_url, GraphQL::STRING_TYPE, null: false, + description: 'Web URL of the board.' end end diff --git a/app/graphql/types/ci/build_need_type.rb b/app/graphql/types/ci/build_need_type.rb new file mode 100644 index 00000000000..3bd81f8fa8f --- /dev/null +++ b/app/graphql/types/ci/build_need_type.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +module Types + module Ci + # rubocop: disable Graphql/AuthorizeTypes + # This type is only accessible from CiJob + class BuildNeedType < BaseObject + graphql_name 'CiBuildNeed' + + field :name, GraphQL::STRING_TYPE, null: true, + description: 'Name of the job we need to complete.' + end + end +end diff --git a/app/graphql/types/ci/ci_cd_setting_type.rb b/app/graphql/types/ci/ci_cd_setting_type.rb index 207c37f9538..e80771cdf9d 100644 --- a/app/graphql/types/ci/ci_cd_setting_type.rb +++ b/app/graphql/types/ci/ci_cd_setting_type.rb @@ -11,8 +11,10 @@ module Types description: 'Whether merge pipelines are enabled.', method: :merge_pipelines_enabled? field :merge_trains_enabled, GraphQL::BOOLEAN_TYPE, null: true, - description: 'Whether merge trains are enabled.', + description: 'Whether merge trains are enabled.', method: :merge_trains_enabled? + field :keep_latest_artifact, GraphQL::BOOLEAN_TYPE, null: true, + description: 'Whether to keep the latest builds artifacts.' field :project, Types::ProjectType, null: true, description: 'Project the CI/CD settings belong to.' end diff --git a/app/graphql/types/ci/config/config_type.rb b/app/graphql/types/ci/config/config_type.rb index e54b345f3d3..29093c6d3c9 100644 --- a/app/graphql/types/ci/config/config_type.rb +++ b/app/graphql/types/ci/config/config_type.rb @@ -11,7 +11,7 @@ module Types description: 'Linting errors' field :merged_yaml, GraphQL::STRING_TYPE, null: true, description: 'Merged CI config YAML' - field :stages, [Types::Ci::Config::StageType], null: true, + field :stages, Types::Ci::Config::StageType.connection_type, null: true, description: 'Stages of the pipeline' field :status, Types::Ci::Config::StatusEnum, null: true, description: 'Status of linting, can be either valid or invalid' diff --git a/app/graphql/types/ci/config/group_type.rb b/app/graphql/types/ci/config/group_type.rb index 8b0db2934a4..8e133bbcba8 100644 --- a/app/graphql/types/ci/config/group_type.rb +++ b/app/graphql/types/ci/config/group_type.rb @@ -9,7 +9,7 @@ module Types field :name, GraphQL::STRING_TYPE, null: true, description: 'Name of the job group' - field :jobs, [Types::Ci::Config::JobType], null: true, + field :jobs, Types::Ci::Config::JobType.connection_type, null: true, description: 'Jobs in group' field :size, GraphQL::INT_TYPE, null: true, description: 'Size of the job group' diff --git a/app/graphql/types/ci/config/job_restriction_type.rb b/app/graphql/types/ci/config/job_restriction_type.rb new file mode 100644 index 00000000000..294e3c94571 --- /dev/null +++ b/app/graphql/types/ci/config/job_restriction_type.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module Types + module Ci + # rubocop: disable Graphql/AuthorizeTypes + module Config + class JobRestrictionType < BaseObject + graphql_name 'CiConfigJobRestriction' + + field :refs, [GraphQL::STRING_TYPE], null: true, + description: 'The Git refs the job restriction applies to.' + end + end + end +end diff --git a/app/graphql/types/ci/config/job_type.rb b/app/graphql/types/ci/config/job_type.rb index 59bcbd9ef49..65fdc4c2615 100644 --- a/app/graphql/types/ci/config/job_type.rb +++ b/app/graphql/types/ci/config/job_type.rb @@ -8,13 +8,36 @@ module Types graphql_name 'CiConfigJob' field :name, GraphQL::STRING_TYPE, null: true, - description: 'Name of the job' + description: 'Name of the job.' field :group_name, GraphQL::STRING_TYPE, null: true, - description: 'Name of the job group' + description: 'Name of the job group.' field :stage, GraphQL::STRING_TYPE, null: true, - description: 'Name of the job stage' - field :needs, [Types::Ci::Config::NeedType], null: true, - description: 'Builds that must complete before the jobs run' + description: 'Name of the job stage.' + field :needs, Types::Ci::Config::NeedType.connection_type, null: true, + description: 'Builds that must complete before the jobs run.' + field :allow_failure, GraphQL::BOOLEAN_TYPE, null: true, + description: 'Allow job to fail.' + field :before_script, [GraphQL::STRING_TYPE], null: true, + description: 'Override a set of commands that are executed before the job.' + field :script, [GraphQL::STRING_TYPE], null: true, + description: 'Shell script that is executed by a runner.' + field :after_script, [GraphQL::STRING_TYPE], null: true, + description: 'Override a set of commands that are executed after the job.' + field :when, GraphQL::STRING_TYPE, null: true, + description: 'When to run the job.', + resolver_method: :restrict_when_to_run_jobs + field :environment, GraphQL::STRING_TYPE, null: true, + description: 'Name of an environment to which the job deploys.' + field :except, Types::Ci::Config::JobRestrictionType, null: true, + description: 'Limit when jobs are not created.' + field :only, Types::Ci::Config::JobRestrictionType, null: true, + description: 'Jobs are created when these conditions do not apply.' + field :tags, [GraphQL::STRING_TYPE], null: true, + description: 'List of tags that are used to select a runner.' + + def restrict_when_to_run_jobs + object[:when] + end end end end diff --git a/app/graphql/types/ci/config/stage_type.rb b/app/graphql/types/ci/config/stage_type.rb index 20618bc41f8..2008c553629 100644 --- a/app/graphql/types/ci/config/stage_type.rb +++ b/app/graphql/types/ci/config/stage_type.rb @@ -9,7 +9,7 @@ module Types field :name, GraphQL::STRING_TYPE, null: true, description: 'Name of the stage' - field :groups, [Types::Ci::Config::GroupType], null: true, + field :groups, Types::Ci::Config::GroupType.connection_type, null: true, description: 'Groups of jobs for the stage' end end diff --git a/app/graphql/types/ci/job_type.rb b/app/graphql/types/ci/job_type.rb index 5b6e8fe8567..f8bf1732e63 100644 --- a/app/graphql/types/ci/job_type.rb +++ b/app/graphql/types/ci/job_type.rb @@ -2,16 +2,16 @@ module Types module Ci - # rubocop: disable Graphql/AuthorizeTypes class JobType < BaseObject graphql_name 'CiJob' + authorize :read_commit_status field :pipeline, Types::Ci::PipelineType, null: true, description: 'Pipeline the job belongs to' field :name, GraphQL::STRING_TYPE, null: true, description: 'Name of the job' - field :needs, JobType.connection_type, null: true, - description: 'Builds that must complete before the jobs run' + field :needs, BuildNeedType.connection_type, null: true, + description: 'References to builds that must complete before the jobs run' field :detailed_status, Types::Ci::DetailedStatusType, null: true, description: 'Detailed status of the job' field :scheduled_at, Types::TimeType, null: true, diff --git a/app/graphql/types/ci/stage_type.rb b/app/graphql/types/ci/stage_type.rb index fd0bde90836..695e7c61bd9 100644 --- a/app/graphql/types/ci/stage_type.rb +++ b/app/graphql/types/ci/stage_type.rb @@ -9,6 +9,7 @@ module Types field :name, GraphQL::STRING_TYPE, null: true, description: 'Name of the stage' field :groups, Ci::GroupType.connection_type, null: true, + extras: [:lookahead], description: 'Group of jobs for the stage' field :detailed_status, Types::Ci::DetailedStatusType, null: true, description: 'Detailed status of the stage' @@ -16,6 +17,38 @@ module Types def detailed_status object.detailed_status(context[:current_user]) end + + # Issues one query per pipeline + def groups(lookahead:) + key = ::Gitlab::Graphql::BatchKey.new(object, lookahead, object_name: :stage) + + BatchLoader::GraphQL.for(key).batch(default_value: []) do |keys, loader| + by_pipeline = keys.group_by(&:pipeline) + include_needs = keys.any? { |k| k.requires?(%i[nodes jobs nodes needs]) } + + by_pipeline.each do |pl, key_group| + project = pl.project + indexed = key_group.index_by(&:id) + + jobs_for_pipeline(pl, indexed.keys, include_needs).each do |stage_id, statuses| + key = indexed[stage_id] + groups = ::Ci::Group.fabricate(project, key.stage, statuses) + loader.call(key, groups) + end + end + end + end + + private + + # rubocop: disable CodeReuse/ActiveRecord + def jobs_for_pipeline(pipeline, stage_ids, include_needs) + results = pipeline.latest_statuses.where(stage_id: stage_ids) + results = results.preload(:needs) if include_needs + + results.group_by(&:stage_id) + end + # rubocop: enable CodeReuse/ActiveRecord end end end diff --git a/app/graphql/types/data_visualization_palette/color_enum.rb b/app/graphql/types/data_visualization_palette/color_enum.rb new file mode 100644 index 00000000000..d55dde44048 --- /dev/null +++ b/app/graphql/types/data_visualization_palette/color_enum.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +module Types + module DataVisualizationPalette + class ColorEnum < BaseEnum + graphql_name 'DataVisualizationColorEnum' + description 'Color of the data visualization palette' + + Enums::DataVisualizationPalette.colors.keys.each do |unit| + value unit.upcase, value: unit, description: "#{unit.to_s.titleize} color" + end + end + end +end diff --git a/app/graphql/types/data_visualization_palette/weight_enum.rb b/app/graphql/types/data_visualization_palette/weight_enum.rb new file mode 100644 index 00000000000..b2b12a90ee4 --- /dev/null +++ b/app/graphql/types/data_visualization_palette/weight_enum.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +module Types + module DataVisualizationPalette + class WeightEnum < BaseEnum + graphql_name 'DataVisualizationWeightEnum' + description 'Weight of the data visualization palette' + + ::Enums::DataVisualizationPalette.weights.keys.each do |unit| + value "weight_#{unit}".upcase, value: unit, description: "#{unit.to_s.titleize} weight" + end + end + end +end diff --git a/app/graphql/types/issue_type.rb b/app/graphql/types/issue_type.rb index 83b8a834801..78fb20650e9 100644 --- a/app/graphql/types/issue_type.rb +++ b/app/graphql/types/issue_type.rb @@ -121,6 +121,9 @@ module Types field :moved_to, Types::IssueType, null: true, description: 'Updated Issue after it got moved to another project' + field :create_note_email, GraphQL::STRING_TYPE, null: true, + description: 'User specific email address for the issue' + def author Gitlab::Graphql::Loaders::BatchModelLoader.new(User, object.author_id).find end @@ -140,6 +143,10 @@ module Types def discussion_locked !!object.discussion_locked end + + def create_note_email + object.creatable_note_email_address(context[:current_user]) + end end end diff --git a/app/graphql/types/merge_request_type.rb b/app/graphql/types/merge_request_type.rb index 816160e58f7..ee7d5780f7a 100644 --- a/app/graphql/types/merge_request_type.rb +++ b/app/graphql/types/merge_request_type.rb @@ -96,6 +96,8 @@ module Types description: 'Default merge commit message of the merge request' field :default_merge_commit_message_with_description, GraphQL::STRING_TYPE, null: true, description: 'Default merge commit message of the merge request with description' + field :default_squash_commit_message, GraphQL::STRING_TYPE, null: true, calls_gitaly: true, + description: 'Default squash commit message of the merge request' field :merge_ongoing, GraphQL::BOOLEAN_TYPE, method: :merge_ongoing?, null: false, description: 'Indicates if a merge is currently occurring' field :source_branch_exists, GraphQL::BOOLEAN_TYPE, @@ -126,10 +128,12 @@ module Types description: 'The milestone of the merge request' field :assignees, Types::UserType.connection_type, null: true, complexity: 5, description: 'Assignees of the merge request' + field :reviewers, Types::UserType.connection_type, null: true, complexity: 5, + description: 'Users from whom a review has been requested.' field :author, Types::UserType, null: true, description: 'User who created this merge request' - field :participants, Types::UserType.connection_type, null: true, complexity: 5, - description: 'Participants in the merge request' + field :participants, Types::UserType.connection_type, null: true, complexity: 15, + description: 'Participants in the merge request. This includes the author, assignees, reviewers, and users mentioned in notes.' field :subscribed, GraphQL::BOOLEAN_TYPE, method: :subscribed?, null: false, complexity: 5, description: 'Indicates if the currently logged in user is subscribed to this merge request' field :labels, Types::LabelType.connection_type, null: true, complexity: 5, @@ -159,6 +163,8 @@ module Types description: 'Users who approved the merge request' field :squash_on_merge, GraphQL::BOOLEAN_TYPE, null: false, method: :squash_on_merge?, description: 'Indicates if squash on merge is enabled' + field :squash, GraphQL::BOOLEAN_TYPE, null: false, + description: 'Indicates if squash on merge is enabled' field :available_auto_merge_strategies, [GraphQL::STRING_TYPE], null: true, calls_gitaly: true, description: 'Array of available auto merge strategies' field :has_ci, GraphQL::BOOLEAN_TYPE, null: false, method: :has_ci?, @@ -169,6 +175,10 @@ module Types calls_gitaly: true, description: 'Merge request commits excluding merge commits' field :security_auto_fix, GraphQL::BOOLEAN_TYPE, null: true, description: 'Indicates if the merge request is created by @GitLab-Security-Bot.' + field :auto_merge_strategy, GraphQL::STRING_TYPE, null: true, + description: 'Selected auto merge strategy' + field :merge_user, Types::UserType, null: true, + description: 'User who merged this merge request' def approved_by object.approved_by_users @@ -235,6 +245,10 @@ module Types def security_auto_fix object.author == User.security_bot end + + def reviewers + object.reviewers if object.allows_reviewers? + end end end diff --git a/app/graphql/types/mutation_type.rb b/app/graphql/types/mutation_type.rb index 9eea81c9d3e..f9dd11cbe37 100644 --- a/app/graphql/types/mutation_type.rb +++ b/app/graphql/types/mutation_type.rb @@ -88,9 +88,11 @@ module Types mount_mutation Mutations::ContainerExpirationPolicies::Update mount_mutation Mutations::ContainerRepositories::Destroy mount_mutation Mutations::ContainerRepositories::DestroyTags - mount_mutation Mutations::Ci::PipelineCancel - mount_mutation Mutations::Ci::PipelineDestroy - mount_mutation Mutations::Ci::PipelineRetry + mount_mutation Mutations::Ci::Pipeline::Cancel + mount_mutation Mutations::Ci::Pipeline::Destroy + mount_mutation Mutations::Ci::Pipeline::Retry + mount_mutation Mutations::Ci::CiCdSettingsUpdate + mount_mutation Mutations::Namespace::PackageSettings::Update end end diff --git a/app/graphql/types/namespace/package_settings_type.rb b/app/graphql/types/namespace/package_settings_type.rb new file mode 100644 index 00000000000..0720a1cfb4b --- /dev/null +++ b/app/graphql/types/namespace/package_settings_type.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +module Types + class Namespace::PackageSettingsType < BaseObject + graphql_name 'PackageSettings' + + description 'Namespace-level Package Registry settings' + + authorize :read_package_settings + + field :maven_duplicates_allowed, GraphQL::BOOLEAN_TYPE, null: false, description: 'Indicates whether duplicate Maven packages are allowed for this namespace.' + field :maven_duplicate_exception_regex, Types::UntrustedRegexp, null: true, description: 'When maven_duplicates_allowed is false, you can publish duplicate packages with names that match this regex. Otherwise, this setting has no effect.' + end +end diff --git a/app/graphql/types/namespace_type.rb b/app/graphql/types/namespace_type.rb index 4dec6f4c5e6..ab614d92b06 100644 --- a/app/graphql/types/namespace_type.rb +++ b/app/graphql/types/namespace_type.rb @@ -37,6 +37,11 @@ module Types description: 'Projects within this namespace', resolver: ::Resolvers::NamespaceProjectsResolver + field :package_settings, + Types::Namespace::PackageSettingsType, + null: true, + description: 'The package settings for the namespace' + def root_storage_statistics Gitlab::Graphql::Loaders::BatchRootStorageStatisticsLoader.new(object.id).find end diff --git a/app/graphql/types/notes/note_type.rb b/app/graphql/types/notes/note_type.rb index f4e05e19eca..84b61340e93 100644 --- a/app/graphql/types/notes/note_type.rb +++ b/app/graphql/types/notes/note_type.rb @@ -46,6 +46,13 @@ module Types field :confidential, GraphQL::BOOLEAN_TYPE, null: true, description: 'Indicates if this note is confidential', method: :confidential? + field :url, GraphQL::STRING_TYPE, + null: true, + description: 'URL to view this Note in the Web UI' + + def url + ::Gitlab::UrlBuilder.build(object) + end def system_note_icon_name SystemNoteHelper.system_note_icon_name(object) if object.system? diff --git a/app/graphql/types/package_type.rb b/app/graphql/types/package_type.rb deleted file mode 100644 index 0604bf827a5..00000000000 --- a/app/graphql/types/package_type.rb +++ /dev/null @@ -1,16 +0,0 @@ -# frozen_string_literal: true - -module Types - class PackageType < BaseObject - graphql_name 'Package' - description 'Represents a package' - 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 update date' - field :version, GraphQL::STRING_TYPE, null: true, description: 'The version of the package' - field :package_type, Types::PackageTypeEnum, null: false, description: 'The type of the package' - end -end diff --git a/app/graphql/types/package_type_enum.rb b/app/graphql/types/package_type_enum.rb deleted file mode 100644 index 6f50c166da3..00000000000 --- a/app/graphql/types/package_type_enum.rb +++ /dev/null @@ -1,15 +0,0 @@ -# frozen_string_literal: true - -module Types - class PackageTypeEnum < BaseEnum - PACKAGE_TYPE_NAMES = { - pypi: 'PyPI', - npm: 'NPM' - }.freeze - - ::Packages::Package.package_types.keys.each do |package_type| - type_name = PACKAGE_TYPE_NAMES.fetch(package_type.to_sym, package_type.capitalize) - value package_type.to_s.upcase, "Packages from the #{type_name} package manager", value: package_type.to_s - end - end -end diff --git a/app/graphql/types/packages/composer/details_type.rb b/app/graphql/types/packages/composer/details_type.rb new file mode 100644 index 00000000000..8c6845a6fb3 --- /dev/null +++ b/app/graphql/types/packages/composer/details_type.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +module Types + module Packages + module Composer + class DetailsType < Types::Packages::PackageType + graphql_name 'PackageComposerDetails' + description 'Details of a Composer package' + + authorize :read_package + + field :composer_metadatum, Types::Packages::Composer::MetadatumType, null: false, description: 'The Composer metadatum.' + end + end + end +end diff --git a/app/graphql/types/packages/composer/json_type.rb b/app/graphql/types/packages/composer/json_type.rb new file mode 100644 index 00000000000..b7aa32f0170 --- /dev/null +++ b/app/graphql/types/packages/composer/json_type.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +module Types + module Packages + module Composer + # rubocop: disable Graphql/AuthorizeTypes + class JsonType < BaseObject + graphql_name 'PackageComposerJsonType' + description 'Represents a composer JSON file' + + field :name, GraphQL::STRING_TYPE, null: true, description: 'The name set in the Composer JSON file.' + field :type, GraphQL::STRING_TYPE, null: true, description: 'The type set in the Composer JSON file.' + field :license, GraphQL::STRING_TYPE, null: true, description: 'The license set in the Composer JSON file.' + field :version, GraphQL::STRING_TYPE, null: true, description: 'The version set in the Composer JSON file.' + end + end + end +end diff --git a/app/graphql/types/packages/composer/metadatum_type.rb b/app/graphql/types/packages/composer/metadatum_type.rb new file mode 100644 index 00000000000..a97818b1fb8 --- /dev/null +++ b/app/graphql/types/packages/composer/metadatum_type.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +module Types + module Packages + module Composer + class MetadatumType < BaseObject + graphql_name 'PackageComposerMetadatumType' + description 'Composer metadatum' + + authorize :read_package + + field :target_sha, GraphQL::STRING_TYPE, null: false, description: 'Target SHA of the package.' + field :composer_json, Types::Packages::Composer::JsonType, null: false, description: 'Data of the Composer JSON file.' + end + end + end +end diff --git a/app/graphql/types/packages/package_tag_type.rb b/app/graphql/types/packages/package_tag_type.rb new file mode 100644 index 00000000000..a05ce03da67 --- /dev/null +++ b/app/graphql/types/packages/package_tag_type.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +module Types + module Packages + class PackageTagType < BaseObject + graphql_name 'PackageTag' + description 'Represents a package tag' + authorize :read_package + + field :id, GraphQL::ID_TYPE, null: false, description: 'The ID of the tag.' + field :name, GraphQL::STRING_TYPE, null: false, description: 'The name of the tag.' + field :created_at, Types::TimeType, null: false, description: 'The created date.' + field :updated_at, Types::TimeType, null: false, description: 'The updated date.' + end + end +end diff --git a/app/graphql/types/packages/package_type.rb b/app/graphql/types/packages/package_type.rb new file mode 100644 index 00000000000..b13d16e91c6 --- /dev/null +++ b/app/graphql/types/packages/package_type.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +module Types + module Packages + class PackageType < BaseObject + 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 + end + end +end diff --git a/app/graphql/types/packages/package_type_enum.rb b/app/graphql/types/packages/package_type_enum.rb new file mode 100644 index 00000000000..9713c9d49b1 --- /dev/null +++ b/app/graphql/types/packages/package_type_enum.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +module Types + module Packages + class PackageTypeEnum < BaseEnum + PACKAGE_TYPE_NAMES = { + pypi: 'PyPI', + npm: 'NPM' + }.freeze + + ::Packages::Package.package_types.keys.each do |package_type| + type_name = PACKAGE_TYPE_NAMES.fetch(package_type.to_sym, package_type.capitalize) + value package_type.to_s.upcase, "Packages from the #{type_name} package manager", value: package_type.to_s + end + end + end +end diff --git a/app/graphql/types/project_type.rb b/app/graphql/types/project_type.rb index a7d9548610e..f66d8926a9f 100644 --- a/app/graphql/types/project_type.rb +++ b/app/graphql/types/project_type.rb @@ -175,7 +175,7 @@ module Types description: 'A single issue of the project', resolver: Resolvers::IssuesResolver.single - field :packages, Types::PackageType.connection_type, null: true, + field :packages, Types::Packages::PackageType.connection_type, null: true, description: 'Packages of the project', resolver: Resolvers::PackagesResolver @@ -315,9 +315,6 @@ module Types description: 'Pipeline analytics', resolver: Resolvers::ProjectPipelineStatisticsResolver - field :total_pipeline_duration, GraphQL::INT_TYPE, null: true, - description: 'Total pipeline duration for all of the pipelines in a project' - def label(title:) BatchLoader::GraphQL.for(title).batch(key: project) do |titles, loader, args| LabelsFinder @@ -362,10 +359,6 @@ module Types project.container_repositories.size end - def total_pipeline_duration - object.all_pipelines.total_duration - end - private def project diff --git a/app/graphql/types/query_type.rb b/app/graphql/types/query_type.rb index 05bb371088c..0e0c060f374 100644 --- a/app/graphql/types/query_type.rb +++ b/app/graphql/types/query_type.rb @@ -58,6 +58,11 @@ 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', + resolver: Resolvers::PackageDetailsResolver + field :user, Types::UserType, null: true, description: 'Find a user', diff --git a/app/graphql/types/release_type.rb b/app/graphql/types/release_type.rb index b715b981483..e7afa7ce7f7 100644 --- a/app/graphql/types/release_type.rb +++ b/app/graphql/types/release_type.rb @@ -35,7 +35,8 @@ module Types field :links, Types::ReleaseLinksType, null: true, method: :itself, description: 'Links of the release' field :milestones, Types::MilestoneType.connection_type, null: true, - description: 'Milestones associated to the release' + description: 'Milestones associated to the release', + resolver: ::Resolvers::ReleaseMilestonesResolver field :evidences, Types::EvidenceType.connection_type, null: true, description: 'Evidence for the release' diff --git a/app/graphql/types/repository_type.rb b/app/graphql/types/repository_type.rb index f0c25e13a26..5b86871142c 100644 --- a/app/graphql/types/repository_type.rb +++ b/app/graphql/types/repository_type.rb @@ -10,7 +10,7 @@ module Types description: 'Default branch of the repository' field :empty, GraphQL::BOOLEAN_TYPE, null: false, method: :empty?, calls_gitaly: true, description: 'Indicates repository has no visible content' - field :exists, GraphQL::BOOLEAN_TYPE, null: false, method: :exists?, + field :exists, GraphQL::BOOLEAN_TYPE, null: false, method: :exists?, calls_gitaly: true, description: 'Indicates a corresponding Git repository exists on disk' field :tree, Types::Tree::TreeType, null: true, resolver: Resolvers::TreeResolver, calls_gitaly: true, description: 'Tree of the repository' |