add createUser mutation
This commit is contained in:
9
app/graphql/inputs/user_attributes_input.rb
Normal file
9
app/graphql/inputs/user_attributes_input.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
# frozen_string_literal: true
|
||||
module Inputs
|
||||
class UserAttributesInput < Types::BaseInputObject
|
||||
graphql_name "UserAttributesInput"
|
||||
|
||||
argument :first_name, String, required: true
|
||||
argument :last_name, String, required: true
|
||||
end
|
||||
end
|
||||
@@ -5,5 +5,9 @@ module Mutations
|
||||
field_class Types::BaseField
|
||||
input_object_class Types::BaseInputObject
|
||||
object_class Types::BaseObject
|
||||
|
||||
field :errors, [String],
|
||||
null: true,
|
||||
description: "Errors encountered during execution of the mutation."
|
||||
end
|
||||
end
|
||||
|
||||
16
app/graphql/mutations/create_user.rb
Normal file
16
app/graphql/mutations/create_user.rb
Normal file
@@ -0,0 +1,16 @@
|
||||
# frozen_string_literal: true
|
||||
module Mutations
|
||||
class CreateUser < BaseMutation
|
||||
field :success, Boolean, null: false
|
||||
|
||||
argument :user, Inputs::UserAttributesInput, required: true
|
||||
|
||||
def resolve(user:)
|
||||
User.create!({ **user, email: context[:current_auth].email })
|
||||
|
||||
{ success: true }
|
||||
rescue ActiveRecord::RecordInvalid => e
|
||||
{ success: false, errors: [e.message] }
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,11 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user