diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-05-19 18:44:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-05-19 18:44:42 +0300 |
commit | 4555e1b21c365ed8303ffb7a3325d773c9b8bf31 (patch) | |
tree | 5423a1c7516cffe36384133ade12572cf709398d /app/graphql/resolvers | |
parent | e570267f2f6b326480d284e0164a6464ba4081bc (diff) |
Add latest changes from gitlab-org/gitlab@13-12-stable-eev13.12.0-rc42
Diffstat (limited to 'app/graphql/resolvers')
-rw-r--r-- | app/graphql/resolvers/ci/runner_resolver.rb | 36 | ||||
-rw-r--r-- | app/graphql/resolvers/ci/runners_resolver.rb | 43 | ||||
-rw-r--r-- | app/graphql/resolvers/ci/template_resolver.rb | 18 | ||||
-rw-r--r-- | app/graphql/resolvers/concerns/board_issue_filterable.rb | 2 | ||||
-rw-r--r-- | app/graphql/resolvers/concerns/issue_resolver_arguments.rb | 70 | ||||
-rw-r--r-- | app/graphql/resolvers/design_management/versions_resolver.rb | 1 | ||||
-rw-r--r-- | app/graphql/resolvers/environments_resolver.rb | 4 | ||||
-rw-r--r-- | app/graphql/resolvers/group_packages_resolver.rb | 26 | ||||
-rw-r--r-- | app/graphql/resolvers/issues_resolver.rb | 2 | ||||
-rw-r--r-- | app/graphql/resolvers/namespace_projects_resolver.rb | 2 | ||||
-rw-r--r-- | app/graphql/resolvers/packages_base_resolver.rb | 53 | ||||
-rw-r--r-- | app/graphql/resolvers/project_packages_resolver.rb | 16 | ||||
-rw-r--r-- | app/graphql/resolvers/projects/services_resolver.rb | 2 | ||||
-rw-r--r-- | app/graphql/resolvers/release_resolver.rb | 2 | ||||
-rw-r--r-- | app/graphql/resolvers/releases_resolver.rb | 2 | ||||
-rw-r--r-- | app/graphql/resolvers/repository_branch_names_resolver.rb | 12 |
16 files changed, 224 insertions, 67 deletions
diff --git a/app/graphql/resolvers/ci/runner_resolver.rb b/app/graphql/resolvers/ci/runner_resolver.rb new file mode 100644 index 00000000000..ca94e28b2e9 --- /dev/null +++ b/app/graphql/resolvers/ci/runner_resolver.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +module Resolvers + module Ci + class RunnerResolver < BaseResolver + include LooksAhead + + type Types::Ci::RunnerType, null: true + extras [:lookahead] + description 'Runner information.' + + argument :id, + type: ::Types::GlobalIDType[::Ci::Runner], + required: true, + description: 'Runner ID.' + + def resolve_with_lookahead(id:) + find_runner(id: id) + end + + private + + def find_runner(id:) + runner_id = GitlabSchema.parse_gid(id, expected_type: ::Ci::Runner).model_id.to_i + preload_tag_list = lookahead.selects?(:tag_list) + + BatchLoader::GraphQL.for(runner_id).batch(key: { preload_tag_list: preload_tag_list }) do |ids, loader, batch| + results = ::Ci::Runner.id_in(ids) + results = results.with_tags if batch[:key][:preload_tag_list] + + results.each { |record| loader.call(record.id, record) } + end + end + end + end +end diff --git a/app/graphql/resolvers/ci/runners_resolver.rb b/app/graphql/resolvers/ci/runners_resolver.rb new file mode 100644 index 00000000000..710706325cc --- /dev/null +++ b/app/graphql/resolvers/ci/runners_resolver.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +module Resolvers + module Ci + class RunnersResolver < BaseResolver + type Types::Ci::RunnerType.connection_type, null: true + + argument :status, ::Types::Ci::RunnerStatusEnum, + required: false, + description: 'Filter runners by status.' + + argument :type, ::Types::Ci::RunnerTypeEnum, + required: false, + description: 'Filter runners by type.' + + argument :tag_list, [GraphQL::STRING_TYPE], + required: false, + description: 'Filter by tags associated with the runner (comma-separated or array).' + + argument :sort, ::Types::Ci::RunnerSortEnum, + required: false, + description: 'Sort order of results.' + + def resolve(**args) + ::Ci::RunnersFinder + .new(current_user: current_user, params: runners_finder_params(args)) + .execute + end + + private + + def runners_finder_params(params) + { + status_status: params[:status]&.to_s, + type_type: params[:type], + tag_name: params[:tag_list], + search: params[:search], + sort: params[:sort]&.to_s + }.compact + end + end + end +end diff --git a/app/graphql/resolvers/ci/template_resolver.rb b/app/graphql/resolvers/ci/template_resolver.rb new file mode 100644 index 00000000000..dd910116544 --- /dev/null +++ b/app/graphql/resolvers/ci/template_resolver.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +module Resolvers + module Ci + class TemplateResolver < BaseResolver + type Types::Ci::TemplateType, null: true + + argument :name, GraphQL::STRING_TYPE, required: true, + description: 'Name of the CI/CD template to search for.' + + alias_method :project, :object + + def resolve(name: nil) + ::TemplateFinder.new(:gitlab_ci_ymls, project, name: name).execute + end + end + end +end diff --git a/app/graphql/resolvers/concerns/board_issue_filterable.rb b/app/graphql/resolvers/concerns/board_issue_filterable.rb index 3484a1cc4ba..88de69a3844 100644 --- a/app/graphql/resolvers/concerns/board_issue_filterable.rb +++ b/app/graphql/resolvers/concerns/board_issue_filterable.rb @@ -32,4 +32,4 @@ module BoardIssueFilterable end end -::BoardIssueFilterable.prepend_if_ee('::EE::Resolvers::BoardIssueFilterable') +::BoardIssueFilterable.prepend_mod_with('Resolvers::BoardIssueFilterable') diff --git a/app/graphql/resolvers/concerns/issue_resolver_arguments.rb b/app/graphql/resolvers/concerns/issue_resolver_arguments.rb index 0ff3997f3bc..aa08d62c6a5 100644 --- a/app/graphql/resolvers/concerns/issue_resolver_arguments.rb +++ b/app/graphql/resolvers/concerns/issue_resolver_arguments.rb @@ -7,57 +7,57 @@ module IssueResolverArguments include LooksAhead argument :iid, GraphQL::STRING_TYPE, - required: false, - description: 'IID of the issue. For example, "1".' + required: false, + description: 'IID of the issue. For example, "1".' argument :iids, [GraphQL::STRING_TYPE], - required: false, - description: 'List of IIDs of issues. For example, [1, 2].' + required: false, + description: 'List of IIDs of issues. For example, ["1", "2"].' argument :label_name, [GraphQL::STRING_TYPE, null: true], - required: false, - description: 'Labels applied to this issue.' + required: false, + description: 'Labels applied to this issue.' argument :milestone_title, [GraphQL::STRING_TYPE, null: true], - required: false, - description: 'Milestone applied to this issue.' + required: false, + description: 'Milestone applied to this issue.' argument :author_username, GraphQL::STRING_TYPE, - required: false, - description: 'Username of the author of the issue.' + required: false, + description: 'Username of the author of the issue.' argument :assignee_username, GraphQL::STRING_TYPE, - required: false, - description: 'Username of a user assigned to the issue.', - deprecated: { reason: 'Use `assigneeUsernames`', milestone: '13.11' } + required: false, + description: 'Username of a user assigned to the issue.', + deprecated: { reason: 'Use `assigneeUsernames`', milestone: '13.11' } argument :assignee_usernames, [GraphQL::STRING_TYPE], - required: false, - description: 'Usernames of users assigned to the issue.' + required: false, + description: 'Usernames of users assigned to the issue.' argument :assignee_id, GraphQL::STRING_TYPE, - required: false, - description: 'ID of a user assigned to the issues, "none" and "any" values are supported.' + required: false, + description: 'ID of a user assigned to the issues, "none" and "any" values are supported.' argument :created_before, Types::TimeType, - required: false, - description: 'Issues created before this date.' + required: false, + description: 'Issues created before this date.' argument :created_after, Types::TimeType, - required: false, - description: 'Issues created after this date.' + required: false, + description: 'Issues created after this date.' argument :updated_before, Types::TimeType, - required: false, - description: 'Issues updated before this date.' + required: false, + description: 'Issues updated before this date.' argument :updated_after, Types::TimeType, - required: false, - description: 'Issues updated after this date.' + required: false, + description: 'Issues updated after this date.' argument :closed_before, Types::TimeType, - required: false, - description: 'Issues closed before this date.' + required: false, + description: 'Issues closed before this date.' argument :closed_after, Types::TimeType, - required: false, - description: 'Issues closed after this date.' + required: false, + description: 'Issues closed after this date.' argument :search, GraphQL::STRING_TYPE, - required: false, - description: 'Search query for issue title or description.' + required: false, + description: 'Search query for issue title or description.' argument :types, [Types::IssueTypeEnum], - as: :issue_types, - description: 'Filter issues by the given issue types.', - required: false + as: :issue_types, + description: 'Filter issues by the given issue types.', + required: false argument :not, Types::Issues::NegatedIssueFilterInputType, - description: 'List of negated params.', + description: 'Negated arguments.', prepare: ->(negated_args, ctx) { negated_args.to_h }, required: false end diff --git a/app/graphql/resolvers/design_management/versions_resolver.rb b/app/graphql/resolvers/design_management/versions_resolver.rb index 619448cbc18..08b29d884b0 100644 --- a/app/graphql/resolvers/design_management/versions_resolver.rb +++ b/app/graphql/resolvers/design_management/versions_resolver.rb @@ -62,6 +62,7 @@ module Resolvers ::DesignManagement::VersionsFinder .new(design_or_collection, current_user, params) .execute + .with_author end def by_id(gid) diff --git a/app/graphql/resolvers/environments_resolver.rb b/app/graphql/resolvers/environments_resolver.rb index df04e70e250..ee604e7b307 100644 --- a/app/graphql/resolvers/environments_resolver.rb +++ b/app/graphql/resolvers/environments_resolver.rb @@ -21,8 +21,8 @@ module Resolvers def resolve(**args) return unless project.present? - EnvironmentsFinder.new(project, context[:current_user], args).execute - rescue EnvironmentsFinder::InvalidStatesError => exception + Environments::EnvironmentsFinder.new(project, context[:current_user], args).execute + rescue Environments::EnvironmentsFinder::InvalidStatesError => exception raise Gitlab::Graphql::Errors::ArgumentError, exception.message end end diff --git a/app/graphql/resolvers/group_packages_resolver.rb b/app/graphql/resolvers/group_packages_resolver.rb index d441cd80249..d91fe84317d 100644 --- a/app/graphql/resolvers/group_packages_resolver.rb +++ b/app/graphql/resolvers/group_packages_resolver.rb @@ -1,8 +1,19 @@ # frozen_string_literal: true +# rubocop: disable Graphql/ResolverType module Resolvers - class GroupPackagesResolver < BaseResolver - type Types::Packages::PackageType.connection_type, null: true + class GroupPackagesResolver < PackagesBaseResolver + # The GraphQL type is defined in the extended class + + argument :sort, Types::Packages::PackageGroupSortEnum, + description: 'Sort packages by this criteria.', + required: false, + default_value: :created_desc + + GROUP_SORT_TO_PARAMS_MAP = SORT_TO_PARAMS_MAP.merge({ + project_path_desc: { order_by: 'project_path', sort: 'desc' }, + project_path_asc: { order_by: 'project_path', sort: 'asc' } + }).freeze def ready?(**args) context[self.class] ||= { executions: 0 } @@ -12,16 +23,11 @@ module Resolvers super end - def resolve(**args) + def resolve(sort:, **filters) return unless packages_available? - ::Packages::GroupPackagesFinder.new(current_user, object).execute - end - - private - - def packages_available? - ::Gitlab.config.packages.enabled + ::Packages::GroupPackagesFinder.new(current_user, object, filters.merge(GROUP_SORT_TO_PARAMS_MAP.fetch(sort))).execute end end end +# rubocop: enable Graphql/ResolverType diff --git a/app/graphql/resolvers/issues_resolver.rb b/app/graphql/resolvers/issues_resolver.rb index 7a67f115abf..93e679b2d0c 100644 --- a/app/graphql/resolvers/issues_resolver.rb +++ b/app/graphql/resolvers/issues_resolver.rb @@ -55,4 +55,4 @@ module Resolvers end end -Resolvers::IssuesResolver.prepend_if_ee('::EE::Resolvers::IssuesResolver') +Resolvers::IssuesResolver.prepend_mod_with('Resolvers::IssuesResolver') diff --git a/app/graphql/resolvers/namespace_projects_resolver.rb b/app/graphql/resolvers/namespace_projects_resolver.rb index 7320c3ce141..86286a744bd 100644 --- a/app/graphql/resolvers/namespace_projects_resolver.rb +++ b/app/graphql/resolvers/namespace_projects_resolver.rb @@ -64,4 +64,4 @@ module Resolvers end end -Resolvers::NamespaceProjectsResolver.prepend_if_ee('::EE::Resolvers::NamespaceProjectsResolver') +Resolvers::NamespaceProjectsResolver.prepend_mod_with('Resolvers::NamespaceProjectsResolver') diff --git a/app/graphql/resolvers/packages_base_resolver.rb b/app/graphql/resolvers/packages_base_resolver.rb new file mode 100644 index 00000000000..3378cc32c9f --- /dev/null +++ b/app/graphql/resolvers/packages_base_resolver.rb @@ -0,0 +1,53 @@ +# frozen_string_literal: true + +module Resolvers + class PackagesBaseResolver < BaseResolver + type Types::Packages::PackageType.connection_type, null: true + + argument :sort, Types::Packages::PackageSortEnum, + description: 'Sort packages by this criteria.', + required: false, + default_value: :created_desc + + argument :package_name, GraphQL::STRING_TYPE, + description: 'Search a package by name.', + required: false, + default_value: nil + + argument :package_type, Types::Packages::PackageTypeEnum, + description: 'Filter a package by type.', + required: false, + default_value: nil + + argument :status, Types::Packages::PackageStatusEnum, + description: 'Filter a package by status.', + required: false, + default_value: nil + + argument :include_versionless, GraphQL::BOOLEAN_TYPE, + description: 'Include versionless packages.', + required: false, + default_value: false + + SORT_TO_PARAMS_MAP = { + created_desc: { order_by: 'created', sort: 'desc' }, + created_asc: { order_by: 'created', sort: 'asc' }, + name_desc: { order_by: 'name', sort: 'desc' }, + name_asc: { order_by: 'name', sort: 'asc' }, + version_desc: { order_by: 'version', sort: 'desc' }, + version_asc: { order_by: 'version', sort: 'asc' }, + type_desc: { order_by: 'type', sort: 'desc' }, + type_asc: { order_by: 'type', sort: 'asc' } + }.freeze + + def resolve + raise NotImplementedError + end + + private + + def packages_available? + ::Gitlab.config.packages.enabled + end + end +end diff --git a/app/graphql/resolvers/project_packages_resolver.rb b/app/graphql/resolvers/project_packages_resolver.rb index 288e14b41d0..6d66c2fe460 100644 --- a/app/graphql/resolvers/project_packages_resolver.rb +++ b/app/graphql/resolvers/project_packages_resolver.rb @@ -1,19 +1,15 @@ # frozen_string_literal: true +# rubocop: disable Graphql/ResolverType module Resolvers - class ProjectPackagesResolver < BaseResolver - type Types::Packages::PackageType.connection_type, null: true + class ProjectPackagesResolver < PackagesBaseResolver + # The GraphQL type is defined in the extended class - def resolve(**args) + def resolve(sort:, **filters) return unless packages_available? - ::Packages::PackagesFinder.new(object).execute - end - - private - - def packages_available? - ::Gitlab.config.packages.enabled + ::Packages::PackagesFinder.new(object, filters.merge(SORT_TO_PARAMS_MAP.fetch(sort))).execute end end end +# rubocop: enable Graphql/ResolverType diff --git a/app/graphql/resolvers/projects/services_resolver.rb b/app/graphql/resolvers/projects/services_resolver.rb index ec31a7dbe6d..db3037ec591 100644 --- a/app/graphql/resolvers/projects/services_resolver.rb +++ b/app/graphql/resolvers/projects/services_resolver.rb @@ -21,7 +21,7 @@ module Resolvers alias_method :project, :object def resolve(active: nil, type: nil) - servs = project.services + servs = project.integrations servs = servs.by_active_flag(active) unless active.nil? servs = servs.by_type(type) unless type.blank? servs diff --git a/app/graphql/resolvers/release_resolver.rb b/app/graphql/resolvers/release_resolver.rb index 20ef01f8593..67ff5fed0bb 100644 --- a/app/graphql/resolvers/release_resolver.rb +++ b/app/graphql/resolvers/release_resolver.rb @@ -15,8 +15,6 @@ 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 01c1e9b11e7..358f3c33836 100644 --- a/app/graphql/resolvers/releases_resolver.rb +++ b/app/graphql/resolvers/releases_resolver.rb @@ -23,8 +23,6 @@ module Resolvers }.freeze def resolve(sort:) - return unless Feature.enabled?(:graphql_release_data, project, default_enabled: true) - ReleasesFinder.new( project, current_user, diff --git a/app/graphql/resolvers/repository_branch_names_resolver.rb b/app/graphql/resolvers/repository_branch_names_resolver.rb index 45cfe229b2f..c0a5ea0366f 100644 --- a/app/graphql/resolvers/repository_branch_names_resolver.rb +++ b/app/graphql/resolvers/repository_branch_names_resolver.rb @@ -10,8 +10,16 @@ module Resolvers required: true, description: 'The pattern to search for branch names by.' - def resolve(search_pattern:) - Repositories::BranchNamesFinder.new(object, search: search_pattern).execute + argument :offset, GraphQL::INT_TYPE, + required: true, + description: 'The number of branch names to skip.' + + argument :limit, GraphQL::INT_TYPE, + required: true, + description: 'The number of branch names to return.' + + def resolve(search_pattern:, offset:, limit:) + Repositories::BranchNamesFinder.new(object, offset: offset, limit: limit, search: search_pattern).execute end end end |