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 included from FindsByGid

#find_object

Methods inherited from BaseMutation

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

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

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

Methods included from Gitlab::Graphql::GlobalIDCompatibility

#coerce_global_id_arguments!

Instance Method Details

#resolve(args) ⇒ Object


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

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