Class: Mutations::Auth::UpdateAccount

Inherits:
GraphQL::Schema::Mutation
  • Object
show all
Defined in:
app/graphql/mutations/auth/update_account.rb

Overview

mutation {

updateAccount(current_password: "currentPassword", password: "newPassword", password_confirmation: "newPassword") {
  success
  user {
    email
  }
  errors {
    field
    message
  }
}

}

Instance Method Summary collapse

Instance Method Details

#resolve(args) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/graphql/mutations/auth/update_account.rb', line 33

def resolve(args)
  user = context[:current_user]
  user.update_with_password args

  if user.errors.any?
    {
      errors: user.errors.messages.map do |field, messages|
        { field: field.to_s.camelize(:lower), message: messages.first.capitalize }
      end,
      success: false,
      user: nil
    }
  else
    {
      errors: [],
      success: true,
      user: user
    }
  end
end