Skip to content

Instantly share code, notes, and snippets.

@RyanCCollins
Last active October 12, 2016 02:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RyanCCollins/7147ce9040552463d393bd2d171df9ad to your computer and use it in GitHub Desktop.
Save RyanCCollins/7147ce9040552463d393bd2d171df9ad to your computer and use it in GitHub Desktop.
module UserMutations
// removed for brevity, see the rest
// here: https://github.com/RyanCCollins/meetup-event-planner/blob/master/app/graph/mutations/user_mutations.rb
UpdateProfile = GraphQL::Relay::Mutation.define do
name 'UpdateProfile'
description 'Update the user profile'
input_field :auth_token, !types.String
input_field :profile, ProfileInputType
return_field :user, AuthUserType
resolve -> (args, ctx) {
@user = User.find_by(auth_token: args[:auth_token])
@user.name = args[:profile][:name] if args[:profile][:name]
@user.bio = args[:profile][:bio] if args[:profile][:bio]
@user.avatar = args[:profile][:avatar] if args[:profile][:avatar]
@user.email = args[:profile][:email] if args[:profile][:email]
@user.employer = args[:profile][:employer] if args[:profile][:employer]
@user.save!
{
user: @user
}
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment