diff options
Diffstat (limited to 'app/graphql/resolvers')
-rw-r--r-- | app/graphql/resolvers/base_resolver.rb | 5 | ||||
-rw-r--r-- | app/graphql/resolvers/ci_configuration/sast_resolver.rb | 17 | ||||
-rw-r--r-- | app/graphql/resolvers/concerns/resolves_merge_requests.rb | 28 | ||||
-rw-r--r-- | app/graphql/resolvers/environments_resolver.rb | 2 | ||||
-rw-r--r-- | app/graphql/resolvers/issues_resolver.rb | 17 | ||||
-rw-r--r-- | app/graphql/resolvers/last_commit_resolver.rb | 2 | ||||
-rw-r--r-- | app/graphql/resolvers/milestone_resolver.rb | 6 | ||||
-rw-r--r-- | app/graphql/resolvers/packages_resolver.rb | 19 | ||||
-rw-r--r-- | app/graphql/resolvers/projects/jira_projects_resolver.rb | 42 | ||||
-rw-r--r-- | app/graphql/resolvers/projects_resolver.rb | 2 | ||||
-rw-r--r-- | app/graphql/resolvers/release_resolver.rb | 2 | ||||
-rw-r--r-- | app/graphql/resolvers/releases_resolver.rb | 2 |
12 files changed, 64 insertions, 80 deletions
diff --git a/app/graphql/resolvers/base_resolver.rb b/app/graphql/resolvers/base_resolver.rb index 7daff68c069..791c6eab42f 100644 --- a/app/graphql/resolvers/base_resolver.rb +++ b/app/graphql/resolvers/base_resolver.rb @@ -83,5 +83,10 @@ module Resolvers def current_user context[:current_user] end + + # Overridden in sub-classes (see .single, .last) + def select_result(results) + results + end end end diff --git a/app/graphql/resolvers/ci_configuration/sast_resolver.rb b/app/graphql/resolvers/ci_configuration/sast_resolver.rb new file mode 100644 index 00000000000..e8c42076ea2 --- /dev/null +++ b/app/graphql/resolvers/ci_configuration/sast_resolver.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +require "json" + +module Resolvers + module CiConfiguration + class SastResolver < BaseResolver + SAST_UI_SCHEMA_PATH = 'app/validators/json_schemas/security_ci_configuration_schemas/sast_ui_schema.json' + + type ::Types::CiConfiguration::Sast::Type, null: true + + def resolve(**args) + Gitlab::Json.parse(File.read(Rails.root.join(SAST_UI_SCHEMA_PATH))) + end + end + end +end diff --git a/app/graphql/resolvers/concerns/resolves_merge_requests.rb b/app/graphql/resolvers/concerns/resolves_merge_requests.rb index a2140728a27..7ed88be52b9 100644 --- a/app/graphql/resolvers/concerns/resolves_merge_requests.rb +++ b/app/graphql/resolvers/concerns/resolves_merge_requests.rb @@ -11,16 +11,10 @@ module ResolvesMergeRequests end def resolve_with_lookahead(**args) - args[:iids] = Array.wrap(args[:iids]) if args[:iids] - args.compact! + mr_finder = MergeRequestsFinder.new(current_user, args.compact) + finder = Gitlab::Graphql::Loaders::IssuableLoader.new(project, mr_finder) - if project && args.keys == [:iids] - batch_load_merge_requests(args[:iids]) - else - args[:project_id] ||= project - - apply_lookahead(MergeRequestsFinder.new(current_user, args).execute) - end.then(&(single? ? :first : :itself)) + select_result(finder.batching_find_all { |query| apply_lookahead(query) }) end def ready?(**args) @@ -35,22 +29,6 @@ module ResolvesMergeRequests private - def batch_load_merge_requests(iids) - iids.map { |iid| batch_load(iid) }.select(&:itself) # .compact doesn't work on BatchLoader - end - - # rubocop: disable CodeReuse/ActiveRecord - def batch_load(iid) - BatchLoader::GraphQL.for(iid.to_s).batch(key: project) do |iids, loader, args| - query = args[:key].merge_requests.where(iid: iids) - - apply_lookahead(query).each do |mr| - loader.call(mr.iid.to_s, mr) - end - end - end - # rubocop: enable CodeReuse/ActiveRecord - def unconditional_includes [:target_project] end diff --git a/app/graphql/resolvers/environments_resolver.rb b/app/graphql/resolvers/environments_resolver.rb index 4e9a17f1e17..1b916a89796 100644 --- a/app/graphql/resolvers/environments_resolver.rb +++ b/app/graphql/resolvers/environments_resolver.rb @@ -8,7 +8,7 @@ module Resolvers argument :search, GraphQL::STRING_TYPE, required: false, - description: 'Search query' + description: 'Search query for environment name' argument :states, [GraphQL::STRING_TYPE], required: false, diff --git a/app/graphql/resolvers/issues_resolver.rb b/app/graphql/resolvers/issues_resolver.rb index f103da07666..9d0535a208f 100644 --- a/app/graphql/resolvers/issues_resolver.rb +++ b/app/graphql/resolvers/issues_resolver.rb @@ -44,7 +44,7 @@ module Resolvers description: 'Issues closed after this date' argument :search, GraphQL::STRING_TYPE, required: false, - description: 'Search query for finding issues by title or description' + description: 'Search query for issue title or description' argument :sort, Types::IssueSortEnum, description: 'Sort issues by this criteria', required: false, @@ -63,18 +63,13 @@ module Resolvers parent = object.respond_to?(:sync) ? object.sync : object return Issue.none if parent.nil? - if parent.is_a?(Group) - args[:group_id] = parent.id - else - args[:project_id] = parent.id - end - # Will need to be be made group & namespace aware with # https://gitlab.com/gitlab-org/gitlab-foss/issues/54520 - args[:iids] ||= [args[:iid]].compact - args[:attempt_project_search_optimizations] = args[:search].present? + args[:iids] ||= [args.delete(:iid)].compact if args[:iid] + args[:attempt_project_search_optimizations] = true if args[:search].present? - issues = IssuesFinder.new(context[:current_user], args).execute + finder = IssuesFinder.new(current_user, args) + issues = Gitlab::Graphql::Loaders::IssuableLoader.new(parent, finder).batching_find_all if non_stable_cursor_sort?(args[:sort]) # Certain complex sorts are not supported by the stable cursor pagination yet. @@ -97,3 +92,5 @@ module Resolvers end end end + +Resolvers::IssuesResolver.prepend_if_ee('::EE::Resolvers::IssuesResolver') diff --git a/app/graphql/resolvers/last_commit_resolver.rb b/app/graphql/resolvers/last_commit_resolver.rb index 7a433d6556f..dd89c322617 100644 --- a/app/graphql/resolvers/last_commit_resolver.rb +++ b/app/graphql/resolvers/last_commit_resolver.rb @@ -9,7 +9,7 @@ module Resolvers def resolve(**args) # Ensure merge commits can be returned by sending nil to Gitaly instead of '/' path = tree.path == '/' ? nil : tree.path - commit = Gitlab::Git::Commit.last_for_path(tree.repository, tree.sha, path) + commit = Gitlab::Git::Commit.last_for_path(tree.repository, tree.sha, path, literal_pathspec: true) ::Commit.new(commit, tree.repository.project) if commit end diff --git a/app/graphql/resolvers/milestone_resolver.rb b/app/graphql/resolvers/milestone_resolver.rb index 6c6513e0ee4..bcfbc63c31f 100644 --- a/app/graphql/resolvers/milestone_resolver.rb +++ b/app/graphql/resolvers/milestone_resolver.rb @@ -52,7 +52,7 @@ module Resolvers end def group_parameters(args) - return { group_ids: parent.id } unless include_descendants?(args) + return { group_ids: parent.id } unless args[:include_descendants].present? { group_ids: parent.self_and_descendants.public_or_visible_to_user(current_user).select(:id), @@ -60,10 +60,6 @@ module Resolvers } end - def include_descendants?(args) - args[:include_descendants].present? && Feature.enabled?(:group_milestone_descendants, parent) - end - def group_projects GroupProjectsFinder.new( group: parent, diff --git a/app/graphql/resolvers/packages_resolver.rb b/app/graphql/resolvers/packages_resolver.rb new file mode 100644 index 00000000000..519fb87183e --- /dev/null +++ b/app/graphql/resolvers/packages_resolver.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +module Resolvers + class PackagesResolver < BaseResolver + type Types::PackageType, null: true + + def resolve(**args) + return unless packages_available? + + ::Packages::PackagesFinder.new(object).execute + end + + private + + def packages_available? + ::Gitlab.config.packages.enabled + end + end +end diff --git a/app/graphql/resolvers/projects/jira_projects_resolver.rb b/app/graphql/resolvers/projects/jira_projects_resolver.rb index a8c3768df41..2dc712128cc 100644 --- a/app/graphql/resolvers/projects/jira_projects_resolver.rb +++ b/app/graphql/resolvers/projects/jira_projects_resolver.rb @@ -13,11 +13,10 @@ module Resolvers def resolve(name: nil, **args) authorize!(project) - response, start_cursor, end_cursor = jira_projects(name: name, **compute_pagination_params(args)) - end_cursor = nil if !!response.payload[:is_last] + response = jira_projects(name: name) if response.success? - Gitlab::Graphql::ExternallyPaginatedArray.new(start_cursor, end_cursor, *response.payload[:projects]) + response.payload[:projects] else raise Gitlab::Graphql::Errors::BaseError, response.message end @@ -35,41 +34,10 @@ module Resolvers jira_service&.project end - def compute_pagination_params(params) - after_cursor = Base64.decode64(params[:after].to_s) - before_cursor = Base64.decode64(params[:before].to_s) + def jira_projects(name:) + args = { query: name }.compact - # differentiate between 0 cursor and nil or invalid cursor that decodes into zero. - after_index = after_cursor.to_i == 0 && after_cursor != "0" ? nil : after_cursor.to_i - before_index = before_cursor.to_i == 0 && before_cursor != "0" ? nil : before_cursor.to_i - - if after_index.present? && before_index.present? - if after_index >= before_index - { start_at: 0, limit: 0 } - else - { start_at: after_index + 1, limit: before_index - after_index - 1 } - end - elsif after_index.present? - { start_at: after_index + 1, limit: nil } - elsif before_index.present? - { start_at: 0, limit: before_index - 1 } - else - { start_at: 0, limit: nil } - end - end - - def jira_projects(name:, start_at:, limit:) - args = { query: name, start_at: start_at, limit: limit }.compact - - response = Jira::Requests::Projects.new(project.jira_service, args).execute - - return [response, nil, nil] if response.error? - - projects = response.payload[:projects] - start_cursor = start_at == 0 ? nil : Base64.encode64((start_at - 1).to_s) - end_cursor = Base64.encode64((start_at + projects.size - 1).to_s) - - [response, start_cursor, end_cursor] + Jira::Requests::Projects::ListService.new(project.jira_service, args).execute end end end diff --git a/app/graphql/resolvers/projects_resolver.rb b/app/graphql/resolvers/projects_resolver.rb index 068546cd39f..f75f591b381 100644 --- a/app/graphql/resolvers/projects_resolver.rb +++ b/app/graphql/resolvers/projects_resolver.rb @@ -10,7 +10,7 @@ module Resolvers argument :search, GraphQL::STRING_TYPE, required: false, - description: 'Search criteria' + description: 'Search query for project name, path, or description' def resolve(**args) ProjectsFinder diff --git a/app/graphql/resolvers/release_resolver.rb b/app/graphql/resolvers/release_resolver.rb index 9bae8b8cd13..1edcc8c70b5 100644 --- a/app/graphql/resolvers/release_resolver.rb +++ b/app/graphql/resolvers/release_resolver.rb @@ -15,6 +15,8 @@ module Resolvers end def resolve(tag_name:) + return unless Feature.enabled?(:graphql_release_data, project, default_enabled: true) + ReleasesFinder.new( project, current_user, diff --git a/app/graphql/resolvers/releases_resolver.rb b/app/graphql/resolvers/releases_resolver.rb index b2afbb92684..85892c2abeb 100644 --- a/app/graphql/resolvers/releases_resolver.rb +++ b/app/graphql/resolvers/releases_resolver.rb @@ -12,6 +12,8 @@ module Resolvers end def resolve(**args) + return unless Feature.enabled?(:graphql_release_data, project, default_enabled: true) + ReleasesFinder.new( project, current_user |