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