add createUser mutation
This commit is contained in:
@@ -9,8 +9,8 @@ class GraphqlController < ApplicationController
|
||||
query = params[:query]
|
||||
operation_name = params[:operationName]
|
||||
context = {
|
||||
current_user: current_admin_user, # || current_auth.current_user,
|
||||
current_auth: current_auth,
|
||||
current_user: current_admin_user, # || current_auth.current_user,
|
||||
}
|
||||
result = XStakeSchema.execute(query, variables: variables, context: context, operation_name: operation_name)
|
||||
render(json: result)
|
||||
|
||||
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
|
||||
|
||||
@@ -19,6 +19,7 @@ class User < ApplicationRecord
|
||||
has_many :documents, class_name: "UserDocument", dependent: :destroy
|
||||
|
||||
validates :first_name, :last_name, :email, presence: true
|
||||
validates :email, uniqueness: true
|
||||
|
||||
def full_name
|
||||
"#{first_name} #{last_name}"
|
||||
|
||||
@@ -8,6 +8,8 @@ module Auth
|
||||
end
|
||||
|
||||
def profile
|
||||
return nil if jwt_token.blank?
|
||||
|
||||
Auth0Client.find_profile(jwt_token)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user