diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-07-19 17:16:28 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-07-19 17:16:28 +0300 |
commit | e4384360a16dd9a19d4d2d25d0ef1f2b862ed2a6 (patch) | |
tree | 2fcdfa7dcdb9db8f5208b2562f4b4e803d671243 /app/graphql/resolvers | |
parent | ffda4e7bcac36987f936b4ba515995a6698698f0 (diff) |
Add latest changes from gitlab-org/gitlab@16-2-stable-eev16.2.0-rc42
Diffstat (limited to 'app/graphql/resolvers')
10 files changed, 82 insertions, 46 deletions
diff --git a/app/graphql/resolvers/alert_management/http_integrations_resolver.rb b/app/graphql/resolvers/alert_management/http_integrations_resolver.rb index 225e20bab83..ac04e0967e6 100644 --- a/app/graphql/resolvers/alert_management/http_integrations_resolver.rb +++ b/app/graphql/resolvers/alert_management/http_integrations_resolver.rb @@ -35,7 +35,7 @@ module Resolvers end def http_integrations - ::AlertManagement::HttpIntegrationsFinder.new(project, {}).execute + ::AlertManagement::HttpIntegrationsFinder.new(project, { type_identifier: :http }).execute end end end diff --git a/app/graphql/resolvers/alert_management/integrations_resolver.rb b/app/graphql/resolvers/alert_management/integrations_resolver.rb index a97650e95d9..9b20d3367f1 100644 --- a/app/graphql/resolvers/alert_management/integrations_resolver.rb +++ b/app/graphql/resolvers/alert_management/integrations_resolver.rb @@ -40,7 +40,7 @@ module Resolvers def http_integrations return [] unless http_integrations_allowed? - ::AlertManagement::HttpIntegrationsFinder.new(project, {}).execute + ::AlertManagement::HttpIntegrationsFinder.new(project, { type_identifier: :http }).execute end def prometheus_integrations_allowed? diff --git a/app/graphql/resolvers/ci/inherited_variables_resolver.rb b/app/graphql/resolvers/ci/inherited_variables_resolver.rb index 01f966942a4..4e83265e247 100644 --- a/app/graphql/resolvers/ci/inherited_variables_resolver.rb +++ b/app/graphql/resolvers/ci/inherited_variables_resolver.rb @@ -5,8 +5,12 @@ module Resolvers class InheritedVariablesResolver < BaseResolver type Types::Ci::ProjectVariableType.connection_type, null: true - def resolve - object.group&.self_and_ancestors&.flat_map(&:variables) || [] + argument :sort, Types::Ci::GroupVariablesSortEnum, + required: false, default_value: :created_desc, + description: 'Sort variables by the criteria.' + + def resolve(sort:) + ::Ci::GroupVariablesFinder.new(object, sort).execute end end end diff --git a/app/graphql/resolvers/ci/runner_job_count_resolver.rb b/app/graphql/resolvers/ci/runner_job_count_resolver.rb new file mode 100644 index 00000000000..a43d3f3a100 --- /dev/null +++ b/app/graphql/resolvers/ci/runner_job_count_resolver.rb @@ -0,0 +1,49 @@ +# frozen_string_literal: true + +module Resolvers + module Ci + class RunnerJobCountResolver < BaseResolver + include Gitlab::Graphql::Authorize::AuthorizeResource + + type GraphQL::Types::Int, null: true + + authorize :read_runner + authorizes_object! + + argument :statuses, [::Types::Ci::JobStatusEnum], + required: false, + description: 'Filter jobs by status.', + alpha: { milestone: '16.2' } + + alias_method :runner, :object + + def resolve(statuses: nil) + BatchLoader::GraphQL.for(runner.id).batch(key: [:job_count, statuses]) do |runner_ids, loader, _args| + counts_by_runner = calculate_job_count_per_runner(runner_ids, statuses) + + runner_ids.each do |runner_id| + loader.call(runner_id, counts_by_runner[runner_id]&.count || 0) + end + end + end + + private + + def calculate_job_count_per_runner(runner_ids, statuses) + # rubocop: disable CodeReuse/ActiveRecord + builds_tbl = ::Ci::Build.arel_table + runners_tbl = ::Ci::Runner.arel_table + lateral_query = ::Ci::Build.select(1).where(builds_tbl['runner_id'].eq(runners_tbl['id'])) + lateral_query = lateral_query.where(status: statuses) if statuses + # We limit to 1 above the JOB_COUNT_LIMIT to indicate that more items exist after JOB_COUNT_LIMIT + lateral_query = lateral_query.limit(::Types::Ci::RunnerType::JOB_COUNT_LIMIT + 1) + ::Ci::Runner.joins("JOIN LATERAL (#{lateral_query.to_sql}) builds_with_limit ON true") + .id_in(runner_ids) + .select(:id, Arel.star.count.as('count')) + .group(:id) + .index_by(&:id) + # rubocop: enable CodeReuse/ActiveRecord + end + end + end +end diff --git a/app/graphql/resolvers/ci/runners_resolver.rb b/app/graphql/resolvers/ci/runners_resolver.rb index 735e38c1a5c..632655d3681 100644 --- a/app/graphql/resolvers/ci/runners_resolver.rb +++ b/app/graphql/resolvers/ci/runners_resolver.rb @@ -4,6 +4,7 @@ module Resolvers module Ci class RunnersResolver < BaseResolver include LooksAhead + include Gitlab::Graphql::Authorize::AuthorizeResource type Types::Ci::RunnerType.connection_type, null: true @@ -105,3 +106,5 @@ module Resolvers end end end + +Resolvers::Ci::RunnersResolver.prepend_mod diff --git a/app/graphql/resolvers/concerns/issues/look_ahead_preloads.rb b/app/graphql/resolvers/concerns/issues/look_ahead_preloads.rb index 2ea7a02bf15..d9bcf39b818 100644 --- a/app/graphql/resolvers/concerns/issues/look_ahead_preloads.rb +++ b/app/graphql/resolvers/concerns/issues/look_ahead_preloads.rb @@ -20,17 +20,15 @@ module Issues end def preloads - preload_hash = { + { alert_management_alert: [:alert_management_alert], assignees: [:assignees], participants: Issue.participant_includes, timelogs: [:timelogs], customer_relations_contacts: { customer_relations_contacts: [:group] }, - escalation_status: [:incident_management_issuable_escalation_status] + escalation_status: [:incident_management_issuable_escalation_status], + type: :work_item_type } - preload_hash[:type] = :work_item_type if Feature.enabled?(:issue_type_uses_work_item_types_table) - - preload_hash end end end diff --git a/app/graphql/resolvers/concerns/resolves_merge_requests.rb b/app/graphql/resolvers/concerns/resolves_merge_requests.rb index b9326015ac0..c0a068097a7 100644 --- a/app/graphql/resolvers/concerns/resolves_merge_requests.rb +++ b/app/graphql/resolvers/concerns/resolves_merge_requests.rb @@ -11,6 +11,11 @@ module ResolvesMergeRequests end def resolve_with_lookahead(**args) + if args[:group_id] + args[:group_id] = ::GitlabSchema.parse_gid(args[:group_id], expected_type: ::Group).model_id + args[:include_subgroups] = true + end + mr_finder = MergeRequestsFinder.new(current_user, args.compact) finder = Gitlab::Graphql::Loaders::IssuableLoader.new(mr_parent, mr_finder) diff --git a/app/graphql/resolvers/issues/base_resolver.rb b/app/graphql/resolvers/issues/base_resolver.rb index fefd17d5e20..495b72231fc 100644 --- a/app/graphql/resolvers/issues/base_resolver.rb +++ b/app/graphql/resolvers/issues/base_resolver.rb @@ -16,6 +16,9 @@ module Resolvers argument :assignee_usernames, [GraphQL::Types::String], required: false, description: 'Usernames of users assigned to the issue.' + argument :assignee_wildcard_id, ::Types::AssigneeWildcardIdEnum, + required: false, + description: 'Filter by assignee wildcard. Incompatible with assigneeUsername and assigneeUsernames.' argument :author_username, GraphQL::Types::String, required: false, description: 'Username of the author of the issue.' @@ -148,6 +151,7 @@ module Resolvers rewrite_param_name(args, :assignee_usernames, :assignee_username) rewrite_param_name(args[:or], :assignee_usernames, :assignee_username) rewrite_param_name(args[:not], :assignee_usernames, :assignee_username) + rewrite_param_name(args, :assignee_wildcard_id, :assignee_id) end def rewrite_param_name(params, old_name, new_name) @@ -163,7 +167,7 @@ module Resolvers end def mutually_exclusive_assignee_username_args - [:assignee_usernames, :assignee_username] + [:assignee_usernames, :assignee_username, :assignee_wildcard_id] end def params_not_mutually_exclusive(args, mutually_exclusive_args) @@ -171,7 +175,7 @@ module Resolvers arg_str = mutually_exclusive_args.map { |x| x.to_s.camelize(:lower) }.join(', ') raise ::Gitlab::Graphql::Errors::ArgumentError, - "only one of [#{arg_str}] arguments is allowed at the same time." + "only one of [#{arg_str}] arguments is allowed at the same time." end end # rubocop:enable Graphql/ResolverType diff --git a/app/graphql/resolvers/metrics/dashboard_resolver.rb b/app/graphql/resolvers/metrics/dashboard_resolver.rb deleted file mode 100644 index 5abad0de539..00000000000 --- a/app/graphql/resolvers/metrics/dashboard_resolver.rb +++ /dev/null @@ -1,35 +0,0 @@ -# frozen_string_literal: true - -module Resolvers - module Metrics - class DashboardResolver < Resolvers::BaseResolver - type Types::Metrics::DashboardType, null: true - calls_gitaly! - - argument :path, GraphQL::Types::String, - required: true, - description: <<~MD - Path to a file which defines a metrics dashboard eg: `"config/prometheus/common_metrics.yml"`. - MD - - alias_method :environment, :object - - def resolve(path:) - return if Feature.enabled?(:remove_monitor_metrics) - return unless environment - - ::PerformanceMonitoring::PrometheusDashboard.find_for(path: path, **service_params) - end - - private - - def service_params - { - project: environment.project, - user: current_user, - options: { environment: environment } - } - end - end - end -end diff --git a/app/graphql/resolvers/user_merge_requests_resolver_base.rb b/app/graphql/resolvers/user_merge_requests_resolver_base.rb index b2d85307c49..72dbc0a93e9 100644 --- a/app/graphql/resolvers/user_merge_requests_resolver_base.rb +++ b/app/graphql/resolvers/user_merge_requests_resolver_base.rb @@ -4,6 +4,14 @@ module Resolvers class UserMergeRequestsResolverBase < MergeRequestsResolver include ResolvesProject + argument :group_id, + type: ::Types::GlobalIDType[::Group], + required: false, + description: <<~DESC + The global ID of the group the authored merge requests should be in. + Merge requests in subgroups are included. + DESC + argument :project_path, type: GraphQL::Types::String, required: false, |