Permalink
Browse files

BaseMutation and CreateUser mutations added

  • Loading branch information...
mattboldt committed Dec 30, 2018
1 parent e062713 commit a9da3b891f7454736056a4b03cc0671b60899373
@@ -0,0 +1,2 @@
class Mutations::BaseMutation < GraphQL::Schema::RelayClassicMutation
end
@@ -0,0 +1,24 @@
class Mutations::CreateUser < Mutations::BaseMutation
argument :name, String, required: true
argument :email, String, required: true

field :user, Types::UserType, null: false
field :errors, [String], null: false

def resolve(name:, email:)
user = User.new(name: name, email: email)
if user.save
# Successful creation, return the created object with no errors
{
user: user,
errors: [],
}
else
# Failed save, return the errors to the client
{
user: nil,
errors: user.errors.full_messages
}
end
end
end
@@ -1,10 +1,5 @@
module Types
class MutationType < Types::BaseObject
# TODO: remove me
field :test_field, String, null: false,
description: "An example field added by the generator"
def test_field
"Hello World"
end
field :create_user, mutation: Mutations::CreateUser
end
end

0 comments on commit a9da3b8

Please sign in to comment.