diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-11-14 11:41:52 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-11-14 11:41:52 +0300 |
commit | 585826cb22ecea5998a2c2a4675735c94bdeedac (patch) | |
tree | 5b05f0b30d33cef48963609e8a18a4dff260eab3 /app/graphql/resolvers | |
parent | df221d036e5d0c6c0ee4d55b9c97f481ee05dee8 (diff) |
Add latest changes from gitlab-org/gitlab@16-6-stable-eev16.6.0-rc42
Diffstat (limited to 'app/graphql/resolvers')
28 files changed, 357 insertions, 61 deletions
diff --git a/app/graphql/resolvers/analytics/cycle_analytics/deployment_count_resolver.rb b/app/graphql/resolvers/analytics/cycle_analytics/deployment_count_resolver.rb index 51a1afdd5ab..2d722b02bf1 100644 --- a/app/graphql/resolvers/analytics/cycle_analytics/deployment_count_resolver.rb +++ b/app/graphql/resolvers/analytics/cycle_analytics/deployment_count_resolver.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -# rubocop:disable Graphql/ResolverType (inherited from Resolvers::Analytics::CycleAnalytics::BaseCountResolver) +# rubocop:disable Graphql/ResolverType -- inherited from Resolvers::Analytics::CycleAnalytics::BaseCountResolver module Resolvers module Analytics module CycleAnalytics diff --git a/app/graphql/resolvers/analytics/cycle_analytics/issue_count_resolver.rb b/app/graphql/resolvers/analytics/cycle_analytics/issue_count_resolver.rb index fd20800ee16..32b884df84f 100644 --- a/app/graphql/resolvers/analytics/cycle_analytics/issue_count_resolver.rb +++ b/app/graphql/resolvers/analytics/cycle_analytics/issue_count_resolver.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -# rubocop:disable Graphql/ResolverType (inherited from Resolvers::Analytics::CycleAnalytics::BaseIssueResolver) +# rubocop:disable Graphql/ResolverType -- inherited from Resolvers::Analytics::CycleAnalytics::BaseIssueResolver module Resolvers module Analytics module CycleAnalytics diff --git a/app/graphql/resolvers/ci/catalog/resource_resolver.rb b/app/graphql/resolvers/ci/catalog/resource_resolver.rb new file mode 100644 index 00000000000..4b722bd3ec7 --- /dev/null +++ b/app/graphql/resolvers/ci/catalog/resource_resolver.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +module Resolvers + module Ci + module Catalog + class ResourceResolver < BaseResolver + include Gitlab::Graphql::Authorize::AuthorizeResource + + authorize :read_code + + type ::Types::Ci::Catalog::ResourceType, null: true + + argument :id, ::Types::GlobalIDType[::Ci::Catalog::Resource], + required: false, + description: 'CI/CD Catalog resource global ID.' + + argument :full_path, GraphQL::Types::ID, + required: false, + description: 'CI/CD Catalog resource full path.' + + def ready?(**args) + unless args[:id].present? ^ args[:full_path].present? + raise Gitlab::Graphql::Errors::ArgumentError, + "Exactly one of 'id' or 'full_path' arguments is required." + end + + super + end + + def resolve(id: nil, full_path: nil) + if full_path.present? + project = Project.find_by_full_path(full_path) + authorize!(project) + + raise_resource_not_available_error! unless project.catalog_resource + + project.catalog_resource + else + catalog_resource = ::Gitlab::Graphql::Lazy.force(GitlabSchema.find_by_gid(id)) + authorize!(catalog_resource&.project) + + catalog_resource + end + end + end + end + end +end diff --git a/app/graphql/resolvers/ci/catalog/resources_resolver.rb b/app/graphql/resolvers/ci/catalog/resources_resolver.rb new file mode 100644 index 00000000000..c6904dcd7f6 --- /dev/null +++ b/app/graphql/resolvers/ci/catalog/resources_resolver.rb @@ -0,0 +1,54 @@ +# frozen_string_literal: true + +module Resolvers + module Ci + module Catalog + class ResourcesResolver < BaseResolver + include LooksAhead + + type ::Types::Ci::Catalog::ResourceType.connection_type, null: true + + argument :scope, ::Types::Ci::Catalog::ResourceScopeEnum, + required: false, + default_value: :all, + description: 'Scope of the returned catalog resources.' + + argument :search, GraphQL::Types::String, + required: false, + description: 'Search term to filter the catalog resources by name or description.' + + argument :sort, ::Types::Ci::Catalog::ResourceSortEnum, + required: false, + description: 'Sort catalog resources by given criteria.' + + # TODO: https://gitlab.com/gitlab-org/gitlab/-/issues/429636 + argument :project_path, GraphQL::Types::ID, + required: false, + description: 'Project with the namespace catalog.' + + def resolve_with_lookahead(scope:, project_path: nil, search: nil, sort: nil) + if project_path.present? + project = Project.find_by_full_path(project_path) + + apply_lookahead( + ::Ci::Catalog::Listing + .new(context[:current_user]) + .resources(namespace: project.root_namespace, sort: sort, search: search) + ) + elsif scope == :all + apply_lookahead(::Ci::Catalog::Listing.new(context[:current_user]).resources(sort: sort, search: search)) + end + end + + private + + def preloads + { + web_path: { project: { namespace: :route } }, + readme_html: { project: :route } + } + end + end + end + end +end diff --git a/app/graphql/resolvers/ci/catalog/versions_resolver.rb b/app/graphql/resolvers/ci/catalog/versions_resolver.rb new file mode 100644 index 00000000000..046adeb7a67 --- /dev/null +++ b/app/graphql/resolvers/ci/catalog/versions_resolver.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +module Resolvers + module Ci + module Catalog + class VersionsResolver < ::Resolvers::ReleasesResolver + type Types::ReleaseType.connection_type, null: true + + # This allows a maximum of 1 call to the field that uses this resolver. If the + # field is evaluated on more than one node, it causes performance degradation. + extension ::Gitlab::Graphql::Limit::FieldCallCount, limit: 1 + + private + + def get_project + object.respond_to?(:project) ? object.project : object + end + + # Override the aliased method in ReleasesResolver + alias_method :project, :get_project + end + end + end +end diff --git a/app/graphql/resolvers/ci/runners_resolver.rb b/app/graphql/resolvers/ci/runners_resolver.rb index 3289f1d0056..9121c413b1f 100644 --- a/app/graphql/resolvers/ci/runners_resolver.rb +++ b/app/graphql/resolvers/ci/runners_resolver.rb @@ -41,6 +41,17 @@ module Resolvers required: false, description: 'Filter by upgrade status.' + argument :creator_id, ::Types::GlobalIDType[::User].as('UserID'), + required: false, + description: 'Filter runners by creator ID.' + + argument :version_prefix, GraphQL::Types::String, + required: false, + description: "Filter runners by version. Runners that contain runner managers with the version at " \ + "the start of the search term are returned. For example, the search term '14.' returns " \ + "runner managers with versions '14.11.1' and '14.2.3'.", + alpha: { milestone: '16.6' } + def resolve_with_lookahead(**args) apply_lookahead( ::Ci::RunnersFinder @@ -68,6 +79,9 @@ module Resolvers upgrade_status: params[:upgrade_status], search: params[:search], sort: params[:sort]&.to_s, + creator_id: + params[:creator_id] ? ::GitlabSchema.parse_gid(params[:creator_id], expected_type: ::User).model_id : nil, + version_prefix: params[:version_prefix], preload: false # we'll handle preloading ourselves }.compact .merge(parent_param) diff --git a/app/graphql/resolvers/concerns/caching_array_resolver.rb b/app/graphql/resolvers/concerns/caching_array_resolver.rb index 15bf9a90e46..f678e02533d 100644 --- a/app/graphql/resolvers/concerns/caching_array_resolver.rb +++ b/app/graphql/resolvers/concerns/caching_array_resolver.rb @@ -132,7 +132,7 @@ module CachingArrayResolver model_class.arel_table[Arel.star] end - # rubocop: disable Graphql/Descriptions (false positive!) + # rubocop: disable Graphql/Descriptions -- false positive def query_limit field&.max_page_size.presence || context.schema.default_max_page_size end diff --git a/app/graphql/resolvers/concerns/work_items/shared_filter_arguments.rb b/app/graphql/resolvers/concerns/work_items/shared_filter_arguments.rb index ecb105a64d0..1982b458143 100644 --- a/app/graphql/resolvers/concerns/work_items/shared_filter_arguments.rb +++ b/app/graphql/resolvers/concerns/work_items/shared_filter_arguments.rb @@ -17,7 +17,12 @@ module WorkItems argument :state, Types::IssuableStateEnum, required: false, - description: 'Current state of the work item.' + description: 'Current state of the work item.', + prepare: ->(state, _ctx) { + return state unless state == 'locked' + + raise Gitlab::Graphql::Errors::ArgumentError, Types::IssuableStateEnum::INVALID_LOCKED_MESSAGE + } argument :types, [Types::IssueTypeEnum], as: :issue_types, diff --git a/app/graphql/resolvers/container_repository_tags_resolver.rb b/app/graphql/resolvers/container_repository_tags_resolver.rb index 55a83dd49da..bc5006ae06c 100644 --- a/app/graphql/resolvers/container_repository_tags_resolver.rb +++ b/app/graphql/resolvers/container_repository_tags_resolver.rb @@ -14,21 +14,61 @@ module Resolvers required: false, default_value: nil + alias_method :container_repository, :object + def resolve(sort:, **filters) - result = tags + if container_repository.migrated? && Feature.enabled?(:use_repository_list_tags_on_graphql, container_repository.project) + page_size = [filters[:first], filters[:last]].map(&:to_i).max + + result = container_repository.tags_page( + before: filters[:before], + last: filters[:after], + sort: map_sort_field(sort), + name: filters[:name], + page_size: page_size + ) - if filters[:name] - result = tags.filter do |tag| - tag.name.include?(filters[:name]) + Gitlab::Graphql::ExternallyPaginatedArray.new( + parse_pagination_cursor(result, :previous), + parse_pagination_cursor(result, :next), + *result[:tags] + ) + else + result = tags + + if filters[:name] + result = tags.filter do |tag| + tag.name.include?(filters[:name]) + end end - end - result = sort_tags(result, sort) if sort - result + result = sort_tags(result, sort) if sort + result + end end private + def parse_pagination_cursor(result, direction) + pagination_uri = result.dig(:pagination, direction, :uri) + + return unless pagination_uri + + query_params = CGI.parse(pagination_uri.query) + key = direction == :previous ? 'before' : 'last' + + query_params[key]&.first + end + + def map_sort_field(sort) + return unless sort + + sort_field, direction = sort.to_s.split('_') + return sort_field if direction == 'asc' + + "-#{sort_field}" + end + def sort_tags(to_be_sorted, sort) raise StandardError unless Types::ContainerRepositoryTagsSortEnum.enum.include?(sort) @@ -41,7 +81,7 @@ module Resolvers end def tags - object.tags + container_repository.tags rescue Faraday::Error raise ::Gitlab::Graphql::Errors::ResourceNotAvailable, "Can't connect to the Container Registry. If this error persists, please review the troubleshooting documentation." end diff --git a/app/graphql/resolvers/data_transfer/group_data_transfer_resolver.rb b/app/graphql/resolvers/data_transfer/group_data_transfer_resolver.rb index 83bb144017c..133b86623f1 100644 --- a/app/graphql/resolvers/data_transfer/group_data_transfer_resolver.rb +++ b/app/graphql/resolvers/data_transfer/group_data_transfer_resolver.rb @@ -16,16 +16,12 @@ module Resolvers def resolve(**args) return { egress_nodes: [] } unless Feature.enabled?(:data_transfer_monitoring, group) - results = if Feature.enabled?(:data_transfer_monitoring_mock_data, group) - ::DataTransfer::MockedTransferFinder.new.execute - else - ::DataTransfer::GroupDataTransferFinder.new( - group: group, - from: args[:from], - to: args[:to], - user: current_user - ).execute.map(&:attributes) - end + results = ::DataTransfer::GroupDataTransferFinder.new( + group: group, + from: args[:from], + to: args[:to], + user: current_user + ).execute.map(&:attributes) { egress_nodes: results.to_a } end diff --git a/app/graphql/resolvers/data_transfer/project_data_transfer_resolver.rb b/app/graphql/resolvers/data_transfer/project_data_transfer_resolver.rb index c3296f7d4c3..d711f837251 100644 --- a/app/graphql/resolvers/data_transfer/project_data_transfer_resolver.rb +++ b/app/graphql/resolvers/data_transfer/project_data_transfer_resolver.rb @@ -16,16 +16,12 @@ module Resolvers def resolve(**args) return { egress_nodes: [] } unless Feature.enabled?(:data_transfer_monitoring, project.group) - results = if Feature.enabled?(:data_transfer_monitoring_mock_data, project.group) - ::DataTransfer::MockedTransferFinder.new.execute - else - ::DataTransfer::ProjectDataTransferFinder.new( - project: project, - from: args[:from], - to: args[:to], - user: current_user - ).execute - end + results = ::DataTransfer::ProjectDataTransferFinder.new( + project: project, + from: args[:from], + to: args[:to], + user: current_user + ).execute { egress_nodes: results } end diff --git a/app/graphql/resolvers/group_issues_resolver.rb b/app/graphql/resolvers/group_issues_resolver.rb index 5e0fb27bafa..5a6a3d678b9 100644 --- a/app/graphql/resolvers/group_issues_resolver.rb +++ b/app/graphql/resolvers/group_issues_resolver.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -# rubocop:disable Graphql/ResolverType (inherited from Issues::BaseParentResolver) +# rubocop:disable Graphql/ResolverType -- inherited from Issues::BaseParentResolver module Resolvers class GroupIssuesResolver < Issues::BaseParentResolver def self.issuable_collection_name diff --git a/app/graphql/resolvers/issues/base_parent_resolver.rb b/app/graphql/resolvers/issues/base_parent_resolver.rb index 6308e56f049..78ef4132baf 100644 --- a/app/graphql/resolvers/issues/base_parent_resolver.rb +++ b/app/graphql/resolvers/issues/base_parent_resolver.rb @@ -7,8 +7,13 @@ module Resolvers include ::Issues::SortArguments argument :state, Types::IssuableStateEnum, - required: false, - description: 'Current state of this issue.' + required: false, + description: 'Current state of this issue.', + prepare: ->(state, _ctx) { + return state unless state == 'locked' + + raise Gitlab::Graphql::Errors::ArgumentError, Types::IssuableStateEnum::INVALID_LOCKED_MESSAGE + } # see app/graphql/types/issue_connection.rb type 'Types::IssueConnection', null: true diff --git a/app/graphql/resolvers/issues_resolver.rb b/app/graphql/resolvers/issues_resolver.rb index 34f14eee0e5..bc0e7334303 100644 --- a/app/graphql/resolvers/issues_resolver.rb +++ b/app/graphql/resolvers/issues_resolver.rb @@ -14,7 +14,12 @@ module Resolvers description: 'Whether to include issues from archived projects. Defaults to `false`.' argument :state, Types::IssuableStateEnum, required: false, - description: 'Current state of this issue.' + description: 'Current state of this issue.', + prepare: ->(state, _ctx) { + return state unless state == 'locked' + + raise Gitlab::Graphql::Errors::ArgumentError, Types::IssuableStateEnum::INVALID_LOCKED_MESSAGE + } # see app/graphql/types/issue_connection.rb type 'Types::IssueConnection', null: true diff --git a/app/graphql/resolvers/namespaces/work_items_resolver.rb b/app/graphql/resolvers/namespaces/work_items_resolver.rb index 6985a7a898a..671788668b1 100644 --- a/app/graphql/resolvers/namespaces/work_items_resolver.rb +++ b/app/graphql/resolvers/namespaces/work_items_resolver.rb @@ -2,7 +2,7 @@ module Resolvers module Namespaces - # rubocop:disable Graphql/ResolverType (inherited from Resolvers::WorkItemsResolver) + # rubocop:disable Graphql/ResolverType -- inherited from Resolvers::WorkItemsResolver class WorkItemsResolver < ::Resolvers::WorkItemsResolver def ready?(**args) return false if Feature.disabled?(:namespace_level_work_items, resource_parent) diff --git a/app/graphql/resolvers/packages_base_resolver.rb b/app/graphql/resolvers/packages_base_resolver.rb index 7d153d16910..7e5d89a7897 100644 --- a/app/graphql/resolvers/packages_base_resolver.rb +++ b/app/graphql/resolvers/packages_base_resolver.rb @@ -19,6 +19,12 @@ module Resolvers required: false, default_value: nil + argument :package_version, GraphQL::Types::String, + description: 'Filter a package by version. If used in combination with `include_versionless`, + then no versionless packages are returned.', + required: false, + default_value: nil + argument :status, Types::Packages::PackageStatusEnum, description: 'Filter a package by status.', required: false, diff --git a/app/graphql/resolvers/project_issues_resolver.rb b/app/graphql/resolvers/project_issues_resolver.rb index f869d8f11c6..2bc610e8266 100644 --- a/app/graphql/resolvers/project_issues_resolver.rb +++ b/app/graphql/resolvers/project_issues_resolver.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -# rubocop:disable Graphql/ResolverType (inherited from Issues::BaseParentResolver) +# rubocop:disable Graphql/ResolverType -- inherited from Issues::BaseParentResolver module Resolvers class ProjectIssuesResolver < Issues::BaseParentResolver accept_release_tag diff --git a/app/graphql/resolvers/project_members_resolver.rb b/app/graphql/resolvers/project_members_resolver.rb index e889b47c000..a27183438cd 100644 --- a/app/graphql/resolvers/project_members_resolver.rb +++ b/app/graphql/resolvers/project_members_resolver.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true -# rubocop:disable Graphql/ResolverType (inherited from MembersResolver) + +# rubocop:disable Graphql/ResolverType -- inherited from MembersResolver module Resolvers class ProjectMembersResolver < MembersResolver @@ -17,3 +18,4 @@ module Resolvers end end end +# rubocop:enable Graphql/ResolverType diff --git a/app/graphql/resolvers/project_milestones_resolver.rb b/app/graphql/resolvers/project_milestones_resolver.rb index 567a55aa09b..cb4e9a5cdf7 100644 --- a/app/graphql/resolvers/project_milestones_resolver.rb +++ b/app/graphql/resolvers/project_milestones_resolver.rb @@ -1,5 +1,4 @@ # frozen_string_literal: true -# rubocop:disable Graphql/ResolverType (inherited from MilestonesResolver) module Resolvers class ProjectMilestonesResolver < MilestonesResolver diff --git a/app/graphql/resolvers/projects/snippets_resolver.rb b/app/graphql/resolvers/projects/snippets_resolver.rb index 448918be2f5..9ab9db21e89 100644 --- a/app/graphql/resolvers/projects/snippets_resolver.rb +++ b/app/graphql/resolvers/projects/snippets_resolver.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true -# rubocop:disable Graphql/ResolverType (inherited from ResolvesSnippets) + +# rubocop:disable Graphql/ResolverType -- inherited from ResolvesSnippets module Resolvers module Projects @@ -27,3 +28,4 @@ module Resolvers end end end +# rubocop:enable Graphql/ResolverType diff --git a/app/graphql/resolvers/projects_resolver.rb b/app/graphql/resolvers/projects_resolver.rb index 8dd409a8173..450caa9aff6 100644 --- a/app/graphql/resolvers/projects_resolver.rb +++ b/app/graphql/resolvers/projects_resolver.rb @@ -3,6 +3,7 @@ module Resolvers class ProjectsResolver < BaseResolver include ProjectSearchArguments + include LooksAhead type Types::ProjectType.connection_type, null: true @@ -10,6 +11,10 @@ module Resolvers required: false, description: 'Filter projects by IDs.' + argument :full_paths, [GraphQL::Types::String], + required: false, + description: 'Filter projects by full paths. You cannot provide more than 50 full paths.' + argument :sort, GraphQL::Types::String, required: false, description: "Sort order of results. Format: `<field_name>_<sort_direction>`, " \ @@ -23,19 +28,48 @@ module Resolvers required: false, description: "Return only projects with merge requests enabled." - def resolve(**args) - ProjectsFinder + def resolve_with_lookahead(**args) + validate_args!(args) + + projects = ProjectsFinder .new(current_user: current_user, params: finder_params(args), project_ids_relation: parse_gids(args[:ids])) .execute + + apply_lookahead(projects) end private + def validate_args!(args) + return unless args[:full_paths].present? && args[:full_paths].length > 50 + + raise Gitlab::Graphql::Errors::ArgumentError, 'You cannot provide more than 50 full_paths' + end + + def unconditional_includes + [:creator, :group, :invited_groups, :project_setting] + end + + def preloads + { + full_path: [:route], + topics: [:topics], + import_status: [:import_state], + service_desk_address: [:project_feature, :service_desk_setting], + jira_import_status: [:jira_imports], + container_repositories: [:container_repositories], + container_repositories_count: [:container_repositories], + web_url: { namespace: [:route] }, + is_catalog_resource: [:catalog_resource] + } + end + def finder_params(args) { **project_finder_params(args), with_issues_enabled: args[:with_issues_enabled], - with_merge_requests_enabled: args[:with_merge_requests_enabled] + with_merge_requests_enabled: args[:with_merge_requests_enabled], + full_paths: args[:full_paths] } end @@ -44,3 +78,5 @@ module Resolvers end end end + +Resolvers::ProjectsResolver.prepend_mod_with('Resolvers::ProjectsResolver') diff --git a/app/graphql/resolvers/saved_reply_resolver.rb b/app/graphql/resolvers/saved_reply_resolver.rb index 96bbc139c96..1a5f2c9be78 100644 --- a/app/graphql/resolvers/saved_reply_resolver.rb +++ b/app/graphql/resolvers/saved_reply_resolver.rb @@ -11,8 +11,6 @@ module Resolvers description: 'ID of a saved reply.' def resolve(id:) - return unless Feature.enabled?(:saved_replies, current_user) - saved_reply = ::Users::SavedReply.find_saved_reply(user_id: current_user.id, id: id.model_id) return unless saved_reply diff --git a/app/graphql/resolvers/snippets_resolver.rb b/app/graphql/resolvers/snippets_resolver.rb index 90f5f2cb534..759cc61a8a7 100644 --- a/app/graphql/resolvers/snippets_resolver.rb +++ b/app/graphql/resolvers/snippets_resolver.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true -# rubocop:disable Graphql/ResolverType (inherited from ResolvesSnippets) + +# rubocop:disable Graphql/ResolverType -- inherited from ResolvesSnippets module Resolvers class SnippetsResolver < BaseResolver @@ -45,3 +46,4 @@ module Resolvers end end end +# rubocop:enable Graphql/ResolverType diff --git a/app/graphql/resolvers/users/frecent_groups_resolver.rb b/app/graphql/resolvers/users/frecent_groups_resolver.rb new file mode 100644 index 00000000000..2fc757e31ab --- /dev/null +++ b/app/graphql/resolvers/users/frecent_groups_resolver.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +module Resolvers + module Users + class FrecentGroupsResolver < BaseResolver + include Gitlab::Graphql::Authorize::AuthorizeResource + + type [Types::GroupType], null: true + + def resolve + return unless current_user.present? + + if Feature.disabled?(:frecent_namespaces_suggestions, current_user) + raise_resource_not_available_error!("'frecent_namespaces_suggestions' feature flag is disabled") + end + + return unless Feature.enabled?(:frecent_namespaces_suggestions, current_user) + + ::Users::GroupVisit.frecent_groups(user_id: current_user.id) + end + end + end +end diff --git a/app/graphql/resolvers/users/frecent_projects_resolver.rb b/app/graphql/resolvers/users/frecent_projects_resolver.rb new file mode 100644 index 00000000000..397d4ca0cfd --- /dev/null +++ b/app/graphql/resolvers/users/frecent_projects_resolver.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +module Resolvers + module Users + class FrecentProjectsResolver < BaseResolver + include Gitlab::Graphql::Authorize::AuthorizeResource + + type [Types::ProjectType], null: true + + def resolve + return unless current_user.present? + + if Feature.disabled?(:frecent_namespaces_suggestions, current_user) + raise_resource_not_available_error!("'frecent_namespaces_suggestions' feature flag is disabled") + end + + ::Users::ProjectVisit.frecent_projects(user_id: current_user.id) + end + end + end +end diff --git a/app/graphql/resolvers/users/organizations_resolver.rb b/app/graphql/resolvers/users/organizations_resolver.rb new file mode 100644 index 00000000000..ffc1a141eb6 --- /dev/null +++ b/app/graphql/resolvers/users/organizations_resolver.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +module Resolvers + module Users + class OrganizationsResolver < BaseResolver + include Gitlab::Graphql::Authorize::AuthorizeResource + + type Types::Organizations::OrganizationType.connection_type, null: true + + authorize :read_user_organizations + authorizes_object! + + def resolve(**args) + ::Organizations::UserOrganizationsFinder.new(current_user, object, args).execute + end + end + end +end diff --git a/app/graphql/resolvers/users/snippets_resolver.rb b/app/graphql/resolvers/users/snippets_resolver.rb index 75bba8debab..ea5f6b7b8c9 100644 --- a/app/graphql/resolvers/users/snippets_resolver.rb +++ b/app/graphql/resolvers/users/snippets_resolver.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true -# rubocop:disable Graphql/ResolverType (inherited from ResolvesSnippets) + +# rubocop:disable Graphql/ResolverType -- inherited from ResolvesSnippets module Resolvers module Users @@ -27,3 +28,4 @@ module Resolvers end end end +# rubocop:enable Graphql/ResolverType diff --git a/app/graphql/resolvers/work_items/linked_items_resolver.rb b/app/graphql/resolvers/work_items/linked_items_resolver.rb index 108d5d41b62..f2ff1205d3a 100644 --- a/app/graphql/resolvers/work_items/linked_items_resolver.rb +++ b/app/graphql/resolvers/work_items/linked_items_resolver.rb @@ -3,6 +3,8 @@ module Resolvers module WorkItems class LinkedItemsResolver < BaseResolver + prepend ::WorkItems::LookAheadPreloads + alias_method :linked_items_widget, :object argument :filter, Types::WorkItems::RelatedLinkTypeEnum, @@ -13,30 +15,28 @@ module Resolvers type Types::WorkItems::LinkedItemType.connection_type, null: true - def resolve(filter: nil) - related_work_items(filter).map do |related_work_item| - { - link_id: related_work_item.issue_link_id, - link_type: related_work_item.issue_link_type, - link_created_at: related_work_item.issue_link_created_at, - link_updated_at: related_work_item.issue_link_updated_at, - work_item: related_work_item - } - end + def resolve_with_lookahead(**args) + apply_lookahead(related_work_items(args)) end private - def related_work_items(type) - return [] unless work_item.resource_parent.linked_work_items_feature_flag_enabled? + def related_work_items(args) + return WorkItem.none unless work_item.resource_parent.linked_work_items_feature_flag_enabled? - work_item.linked_work_items(current_user, preload: { project: [:project_feature, :group] }, link_type: type) + offset_pagination( + work_item.linked_work_items(authorize: false, link_type: args[:filter]) + ) end def work_item linked_items_widget.work_item end strong_memoize_attr :work_item + + def node_selection(selection = lookahead) + super.selection(:work_item) + end end end end |