debian-mirror-gitlab/app/graphql/resolvers/milestones_resolver.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

90 lines
2.4 KiB
Ruby
Raw Normal View History

2020-10-24 23:57:45 +05:30
# frozen_string_literal: true
module Resolvers
class MilestonesResolver < BaseResolver
include Gitlab::Graphql::Authorize::AuthorizeResource
include TimeFrameArguments
2022-07-23 23:45:48 +05:30
include LooksAhead
# authorize before resolution
authorize :read_milestone
authorizes_object!
2020-10-24 23:57:45 +05:30
2021-10-27 15:23:28 +05:30
argument :ids, [GraphQL::Types::ID],
2020-10-24 23:57:45 +05:30
required: false,
2021-04-29 21:17:54 +05:30
description: 'Array of global milestone IDs, e.g., `"gid://gitlab/Milestone/1"`.'
2020-10-24 23:57:45 +05:30
argument :state, Types::MilestoneStateEnum,
required: false,
2021-03-08 18:12:59 +05:30
description: 'Filter milestones by state.'
2020-10-24 23:57:45 +05:30
2021-10-27 15:23:28 +05:30
argument :title, GraphQL::Types::String,
2021-01-03 14:25:43 +05:30
required: false,
2021-11-11 11:23:49 +05:30
description: 'Title of the milestone.'
2021-01-03 14:25:43 +05:30
2021-10-27 15:23:28 +05:30
argument :search_title, GraphQL::Types::String,
2021-01-03 14:25:43 +05:30
required: false,
2021-11-11 11:23:49 +05:30
description: 'Search string for the title.'
2021-01-03 14:25:43 +05:30
argument :containing_date, Types::TimeType,
required: false,
2021-11-11 11:23:49 +05:30
description: 'Date the milestone contains.'
2021-01-03 14:25:43 +05:30
2021-09-30 23:02:18 +05:30
argument :sort, Types::MilestoneSortEnum,
description: 'Sort milestones by this criteria.',
required: false,
default_value: :due_date_asc
2021-01-29 00:20:46 +05:30
type Types::MilestoneType.connection_type, null: true
2020-10-24 23:57:45 +05:30
2021-09-30 23:02:18 +05:30
NON_STABLE_CURSOR_SORTS = %i[expired_last_due_date_asc expired_last_due_date_desc].freeze
2022-07-23 23:45:48 +05:30
def resolve_with_lookahead(**args)
2020-10-24 23:57:45 +05:30
validate_timeframe_params!(args)
2022-07-23 23:45:48 +05:30
milestones = apply_lookahead(MilestonesFinder.new(milestones_finder_params(args)).execute)
2021-09-30 23:02:18 +05:30
if non_stable_cursor_sort?(args[:sort])
offset_pagination(milestones)
else
milestones
end
2020-10-24 23:57:45 +05:30
end
private
2022-07-23 23:45:48 +05:30
def preloads
{
releases: :releases
}
end
2020-10-24 23:57:45 +05:30
def milestones_finder_params(args)
{
ids: parse_gids(args[:ids]),
state: args[:state] || 'all',
2021-01-03 14:25:43 +05:30
title: args[:title],
search_title: args[:search_title],
2021-09-30 23:02:18 +05:30
sort: args[:sort],
2021-01-03 14:25:43 +05:30
containing_date: args[:containing_date]
2021-09-04 01:27:46 +05:30
}.merge!(transform_timeframe_parameters(args)).merge!(parent_id_parameters(args))
2020-10-24 23:57:45 +05:30
end
def parent
2021-04-29 21:17:54 +05:30
object
2020-10-24 23:57:45 +05:30
end
def parent_id_parameters(args)
raise NotImplementedError
end
def parse_gids(gids)
gids&.map { |gid| GitlabSchema.parse_gid(gid, expected_type: Milestone).model_id }
end
2021-09-30 23:02:18 +05:30
def non_stable_cursor_sort?(sort)
NON_STABLE_CURSOR_SORTS.include?(sort)
end
2020-10-24 23:57:45 +05:30
end
end