Last active
October 12, 2016 02:06
-
-
Save RyanCCollins/7147ce9040552463d393bd2d171df9ad to your computer and use it in GitHub Desktop.
Building a full GraphQL app with Rails, React: https://medium.com/@ryancollinsio/building-a-full-on-graphql-app-b261f6cfea93#.qtjma57sx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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