diff options
Diffstat (limited to 'app/graphql/types/work_items/widgets/award_emoji_type.rb')
-rw-r--r-- | app/graphql/types/work_items/widgets/award_emoji_type.rb | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/app/graphql/types/work_items/widgets/award_emoji_type.rb b/app/graphql/types/work_items/widgets/award_emoji_type.rb new file mode 100644 index 00000000000..421bb8f0e98 --- /dev/null +++ b/app/graphql/types/work_items/widgets/award_emoji_type.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +module Types + module WorkItems + module Widgets + # Disabling widget level authorization as it might be too granular + # and we already authorize the parent work item + # rubocop:disable Graphql/AuthorizeTypes + class AwardEmojiType < BaseObject + graphql_name 'WorkItemWidgetAwardEmoji' + description 'Represents the award emoji widget' + + implements Types::WorkItems::WidgetInterface + + field :award_emoji, + ::Types::AwardEmojis::AwardEmojiType.connection_type, + null: true, + description: 'Award emoji on the work item.' + field :downvotes, + GraphQL::Types::Int, + null: false, + description: 'Number of downvotes the work item has received.' + field :upvotes, + GraphQL::Types::Int, + null: false, + description: 'Number of upvotes the work item has received.' + + def downvotes + BatchLoaders::AwardEmojiVotesBatchLoader + .load_downvotes(object.work_item, awardable_class: 'Issue') + end + + def upvotes + BatchLoaders::AwardEmojiVotesBatchLoader + .load_upvotes(object.work_item, awardable_class: 'Issue') + end + end + # rubocop:enable Graphql/AuthorizeTypes + end + end +end |