diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-20 12:40:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-20 12:40:42 +0300 |
commit | ee664acb356f8123f4f6b00b73c1e1cf0866c7fb (patch) | |
tree | f8479f94a28f66654c6a4f6fb99bad6b4e86a40e /app/graphql/resolvers | |
parent | 62f7d5c5b69180e82ae8196b7b429eeffc8e7b4f (diff) |
Add latest changes from gitlab-org/gitlab@15-5-stable-eev15.5.0-rc42
Diffstat (limited to 'app/graphql/resolvers')
-rw-r--r-- | app/graphql/resolvers/base_issues_resolver.rb | 2 | ||||
-rw-r--r-- | app/graphql/resolvers/bulk_labels_resolver.rb | 27 | ||||
-rw-r--r-- | app/graphql/resolvers/ci/all_jobs_resolver.rb | 17 | ||||
-rw-r--r-- | app/graphql/resolvers/ci/runner_projects_resolver.rb | 4 | ||||
-rw-r--r-- | app/graphql/resolvers/concerns/looks_ahead.rb | 27 | ||||
-rw-r--r-- | app/graphql/resolvers/concerns/resolves_merge_requests.rb | 4 | ||||
-rw-r--r-- | app/graphql/resolvers/down_votes_count_resolver.rb | 15 | ||||
-rw-r--r-- | app/graphql/resolvers/project_pipeline_schedules_resolver.rb | 17 | ||||
-rw-r--r-- | app/graphql/resolvers/projects/branch_rules_resolver.rb | 8 | ||||
-rw-r--r-- | app/graphql/resolvers/projects_resolver.rb | 4 | ||||
-rw-r--r-- | app/graphql/resolvers/up_votes_count_resolver.rb | 15 | ||||
-rw-r--r-- | app/graphql/resolvers/work_items_resolver.rb | 26 |
12 files changed, 144 insertions, 22 deletions
diff --git a/app/graphql/resolvers/base_issues_resolver.rb b/app/graphql/resolvers/base_issues_resolver.rb index ec47a8996eb..6357132705e 100644 --- a/app/graphql/resolvers/base_issues_resolver.rb +++ b/app/graphql/resolvers/base_issues_resolver.rb @@ -47,8 +47,8 @@ module Resolvers def preloads { alert_management_alert: [:alert_management_alert], - labels: [:labels], assignees: [:assignees], + participants: Issue.participant_includes, timelogs: [:timelogs], customer_relations_contacts: { customer_relations_contacts: [:group] }, escalation_status: [:incident_management_issuable_escalation_status] diff --git a/app/graphql/resolvers/bulk_labels_resolver.rb b/app/graphql/resolvers/bulk_labels_resolver.rb new file mode 100644 index 00000000000..7362e257fb6 --- /dev/null +++ b/app/graphql/resolvers/bulk_labels_resolver.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +module Resolvers + class BulkLabelsResolver < BaseResolver + include Gitlab::Graphql::Authorize::AuthorizeResource + + type Types::LabelType.connection_type, null: true + + def resolve + authorize!(object) + + BatchLoader::GraphQL.for(object.id).batch(cache: false) do |ids, loader, args| + labels = Label.for_targets(object.class.id_in(ids)).group_by(&:target_id) + + ids.each do |id| + loader.call(id, labels[id] || []) + end + end + end + + private + + def authorized_resource?(object) + Ability.allowed?(current_user, :read_label, object.issuing_parent) + end + end +end diff --git a/app/graphql/resolvers/ci/all_jobs_resolver.rb b/app/graphql/resolvers/ci/all_jobs_resolver.rb new file mode 100644 index 00000000000..d918bed9f57 --- /dev/null +++ b/app/graphql/resolvers/ci/all_jobs_resolver.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +module Resolvers + module Ci + class AllJobsResolver < BaseResolver + type ::Types::Ci::JobType.connection_type, null: true + + argument :statuses, [::Types::Ci::JobStatusEnum], + required: false, + description: 'Filter jobs by status.' + + def resolve(statuses: nil) + ::Ci::JobsFinder.new(current_user: current_user, params: { scope: statuses }).execute + end + end + end +end diff --git a/app/graphql/resolvers/ci/runner_projects_resolver.rb b/app/graphql/resolvers/ci/runner_projects_resolver.rb index ca3b4ebb797..af9a67acfda 100644 --- a/app/graphql/resolvers/ci/runner_projects_resolver.rb +++ b/app/graphql/resolvers/ci/runner_projects_resolver.rb @@ -21,8 +21,8 @@ module Resolvers 'Specify `"id_asc"` if query results\' order is important', milestone: '15.4' }, - description: "Sort order of results. Format: '<field_name>_<sort_direction>', " \ - "for example: 'id_desc' or 'name_asc'" + description: "Sort order of results. Format: `<field_name>_<sort_direction>`, " \ + "for example: `id_desc` or `name_asc`" def resolve_with_lookahead(**args) return unless runner.project_type? diff --git a/app/graphql/resolvers/concerns/looks_ahead.rb b/app/graphql/resolvers/concerns/looks_ahead.rb index b548dc1e175..81099c04e9f 100644 --- a/app/graphql/resolvers/concerns/looks_ahead.rb +++ b/app/graphql/resolvers/concerns/looks_ahead.rb @@ -32,16 +32,37 @@ module LooksAhead {} end + def nested_preloads + {} + end + def filtered_preloads nodes = node_selection return [] unless nodes selected_fields = nodes.selections.map(&:name) + root_level_preloads = preloads_from_node_selection(selected_fields, preloads) - preloads.each.flat_map do |name, requirements| - selected_fields.include?(name) ? requirements : [] - end + root_level_preloads + nested_filtered_preloads(nodes, selected_fields) + end + + def nested_filtered_preloads(nodes, selected_root_fields) + return [] if nested_preloads.empty? + + nested_preloads.each_with_object([]) do |(root_field, fields), result| + next unless selected_root_fields.include?(root_field) + + selected_fields = nodes.selection(root_field).selections.map(&:name) + + result << preloads_from_node_selection(selected_fields, fields) + end.flatten + end + + def preloads_from_node_selection(selected_fields, fields) + fields.each_with_object([]) do |(field, requirements), result| + result << requirements if selected_fields.include?(field) + end.flatten end def node_selection diff --git a/app/graphql/resolvers/concerns/resolves_merge_requests.rb b/app/graphql/resolvers/concerns/resolves_merge_requests.rb index 697cc6f5b03..d56951bc821 100644 --- a/app/graphql/resolvers/concerns/resolves_merge_requests.rb +++ b/app/graphql/resolvers/concerns/resolves_merge_requests.rb @@ -42,7 +42,6 @@ module ResolvesMergeRequests assignees: [:assignees], reviewers: [:reviewers], participants: MergeRequest.participant_includes, - labels: [:labels], author: [:author], merged_at: [:metrics], commit_count: [:metrics], @@ -53,7 +52,8 @@ module ResolvesMergeRequests head_pipeline: [:merge_request_diff, { head_pipeline: [:merge_request] }], timelogs: [:timelogs], pipelines: [:merge_request_diffs], # used by `recent_diff_head_shas` to load pipelines - committers: [merge_request_diff: [:merge_request_diff_commits]] + committers: [merge_request_diff: [:merge_request_diff_commits]], + suggested_reviewers: [:predictions] } end end diff --git a/app/graphql/resolvers/down_votes_count_resolver.rb b/app/graphql/resolvers/down_votes_count_resolver.rb new file mode 100644 index 00000000000..0e7772f988a --- /dev/null +++ b/app/graphql/resolvers/down_votes_count_resolver.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module Resolvers + class DownVotesCountResolver < BaseResolver + include Gitlab::Graphql::Authorize::AuthorizeResource + include BatchLoaders::AwardEmojiVotesBatchLoader + + type GraphQL::Types::Int, null: true + + def resolve + authorize!(object) + load_votes(object, AwardEmoji::DOWNVOTE_NAME) + end + end +end diff --git a/app/graphql/resolvers/project_pipeline_schedules_resolver.rb b/app/graphql/resolvers/project_pipeline_schedules_resolver.rb new file mode 100644 index 00000000000..eb980f72717 --- /dev/null +++ b/app/graphql/resolvers/project_pipeline_schedules_resolver.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +module Resolvers + class ProjectPipelineSchedulesResolver < BaseResolver + alias_method :project, :object + + type ::Types::Ci::PipelineScheduleType.connection_type, null: true + + argument :status, ::Types::Ci::PipelineScheduleStatusEnum, + required: false, + description: 'Filter pipeline schedules by active status.' + + def resolve(status: nil) + ::Ci::PipelineSchedulesFinder.new(project).execute(scope: status) + end + end +end diff --git a/app/graphql/resolvers/projects/branch_rules_resolver.rb b/app/graphql/resolvers/projects/branch_rules_resolver.rb index 6c8b416bcea..e99d7ae4d5f 100644 --- a/app/graphql/resolvers/projects/branch_rules_resolver.rb +++ b/app/graphql/resolvers/projects/branch_rules_resolver.rb @@ -3,13 +3,17 @@ module Resolvers module Projects class BranchRulesResolver < BaseResolver + include LooksAhead + type Types::Projects::BranchRuleType.connection_type, null: false alias_method :project, :object - def resolve(**args) - project.protected_branches + def resolve_with_lookahead(**args) + apply_lookahead(project.protected_branches) end end end end + +Resolvers::Projects::BranchRulesResolver.prepend_mod_with('Resolvers::Projects::BranchRulesResolver') diff --git a/app/graphql/resolvers/projects_resolver.rb b/app/graphql/resolvers/projects_resolver.rb index 4d1e1b867da..0bdba53c7af 100644 --- a/app/graphql/resolvers/projects_resolver.rb +++ b/app/graphql/resolvers/projects_resolver.rb @@ -12,8 +12,8 @@ module Resolvers argument :sort, GraphQL::Types::String, required: false, - description: "Sort order of results. Format: '<field_name>_<sort_direction>', " \ - "for example: 'id_desc' or 'name_asc'" + description: "Sort order of results. Format: `<field_name>_<sort_direction>`, " \ + "for example: `id_desc` or `name_asc`" def resolve(**args) ProjectsFinder diff --git a/app/graphql/resolvers/up_votes_count_resolver.rb b/app/graphql/resolvers/up_votes_count_resolver.rb new file mode 100644 index 00000000000..1c78facb694 --- /dev/null +++ b/app/graphql/resolvers/up_votes_count_resolver.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module Resolvers + class UpVotesCountResolver < BaseResolver + include Gitlab::Graphql::Authorize::AuthorizeResource + include BatchLoaders::AwardEmojiVotesBatchLoader + + type GraphQL::Types::Int, null: true + + def resolve + authorize!(object) + load_votes(object, AwardEmoji::UPVOTE_NAME) + end + end +end diff --git a/app/graphql/resolvers/work_items_resolver.rb b/app/graphql/resolvers/work_items_resolver.rb index a8c0d363325..a4cbcc61ead 100644 --- a/app/graphql/resolvers/work_items_resolver.rb +++ b/app/graphql/resolvers/work_items_resolver.rb @@ -37,20 +37,26 @@ module Resolvers def preloads { - last_edited_by: :last_edited_by, - web_url: { project: { namespace: :route } } + work_item_type: :work_item_type, + web_url: { project: { namespace: :route } }, + widgets: :work_item_type } end - # Allows to apply lookahead for fields - # selected from WidgetInterface - override :node_selection - def node_selection - selected_fields = super - - return unless selected_fields + def nested_preloads + { + widgets: widget_preloads, + user_permissions: { update_work_item: :assignees } + } + end - selected_fields.selection(:widgets) + def widget_preloads + { + last_edited_by: :last_edited_by, + assignees: :assignees, + parent: :work_item_parent, + labels: :labels + } end def unconditional_includes |