2020-05-06 20:11:11 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Resolvers
|
|
|
|
class ReleasesResolver < BaseResolver
|
|
|
|
type Types::ReleaseType.connection_type, null: true
|
|
|
|
|
2020-10-23 05:08:41 -04:00
|
|
|
argument :sort, Types::ReleaseSortEnum,
|
|
|
|
required: false, default_value: :released_at_desc,
|
2021-01-11 19:10:42 -05:00
|
|
|
description: 'Sort releases by this criteria.'
|
2020-10-23 05:08:41 -04:00
|
|
|
|
2020-05-06 20:11:11 -04:00
|
|
|
alias_method :project, :object
|
|
|
|
|
|
|
|
# This resolver has a custom singular resolver
|
|
|
|
def self.single
|
|
|
|
Resolvers::ReleaseResolver
|
|
|
|
end
|
|
|
|
|
2020-10-23 05:08:41 -04:00
|
|
|
SORT_TO_PARAMS_MAP = {
|
|
|
|
released_at_desc: { order_by: 'released_at', sort: 'desc' },
|
|
|
|
released_at_asc: { order_by: 'released_at', sort: 'asc' },
|
|
|
|
created_desc: { order_by: 'created_at', sort: 'desc' },
|
|
|
|
created_asc: { order_by: 'created_at', sort: 'asc' }
|
|
|
|
}.freeze
|
|
|
|
|
|
|
|
def resolve(sort:)
|
2020-05-06 20:11:11 -04:00
|
|
|
ReleasesFinder.new(
|
|
|
|
project,
|
2020-10-23 05:08:41 -04:00
|
|
|
current_user,
|
|
|
|
SORT_TO_PARAMS_MAP[sort]
|
2020-05-06 20:11:11 -04:00
|
|
|
).execute
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|