2020-05-24 23:13:21 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Resolvers
|
|
|
|
class ReleasesResolver < BaseResolver
|
|
|
|
type Types::ReleaseType.connection_type, null: true
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
argument :sort, Types::ReleaseSortEnum,
|
|
|
|
required: false, default_value: :released_at_desc,
|
|
|
|
description: 'Sort releases by this criteria'
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
alias_method :project, :object
|
|
|
|
|
|
|
|
# This resolver has a custom singular resolver
|
|
|
|
def self.single
|
|
|
|
Resolvers::ReleaseResolver
|
|
|
|
end
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
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-07-28 23:09:34 +05:30
|
|
|
return unless Feature.enabled?(:graphql_release_data, project, default_enabled: true)
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
ReleasesFinder.new(
|
|
|
|
project,
|
2021-01-29 00:20:46 +05:30
|
|
|
current_user,
|
|
|
|
SORT_TO_PARAMS_MAP[sort]
|
2020-05-24 23:13:21 +05:30
|
|
|
).execute
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|