Class: Mutations::AwardEmojis::Toggle

Inherits:
Base
  • Object
show all
Defined in:
app/graphql/mutations/award_emojis/toggle.rb

Constant Summary

Constants inherited from Base

Base::NOT_EMOJI_AWARDABLE

Constants inherited from BaseMutation

BaseMutation::ERROR_MESSAGE

Constants included from Gitlab::Graphql::Authorize::AuthorizeResource

Gitlab::Graphql::Authorize::AuthorizeResource::ConfigurationError, Gitlab::Graphql::Authorize::AuthorizeResource::RESOURCE_ACCESS_ERROR

Instance Method Summary collapse

Methods inherited from BaseMutation

#api_user?, authorization, authorized?, authorizes_object?, #current_user, #errors_on_object, #load_application_object, #read_only?, #ready?, #unauthorized_object

Methods included from Gitlab::Graphql::Authorize::AuthorizeResource

#authorize!, #authorized_find!, #authorized_resource?, #find_object, #raise_resource_not_available_error!

Instance Method Details

#resolve(args) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/graphql/mutations/award_emojis/toggle.rb', line 13

def resolve(args)
  awardable = authorized_find!(id: args[:awardable_id])

  service = ::AwardEmojis::ToggleService.new(awardable, args[:name], current_user).execute

  toggled_on = awardable.awarded_emoji?(args[:name], current_user)

  {
    # For consistency with the AwardEmojis::Remove mutation, only return
    # the AwardEmoji if it was created and not destroyed
    award_emoji: (service[:award] if toggled_on),
    errors: service[:errors] || [],
    toggled_on: toggled_on
  }
end