remove createUser mutation

This commit is contained in:
João Geonizeli
2021-08-10 21:57:06 -03:00
parent fe072595ed
commit fb99da5550
7 changed files with 1 additions and 157 deletions

View File

@@ -1,16 +0,0 @@
# 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

View File

@@ -1,6 +1,5 @@
# frozen_string_literal: true
module Types
class MutationType < Types::BaseObject
field :create_user, mutation: Mutations::CreateUser
end
end

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
class XStakeSchema < GraphQL::Schema
mutation(Types::MutationType)
# mutation(Types::MutationType)
query(Types::QueryType)
def self.resolve_type(abstract_type, obj, ctx)

View File

@@ -1,39 +1,3 @@
"""
Autogenerated input type of CreateUser
"""
input CreateUserInput {
"""
A unique identifier for the client performing the mutation.
"""
clientMutationId: String
user: UserAttributesInput!
}
"""
Autogenerated return type of CreateUser
"""
type CreateUserPayload {
"""
A unique identifier for the client performing the mutation.
"""
clientMutationId: String
"""
Errors encountered during execution of the mutation.
"""
errors: [String!]
success: Boolean!
}
type Mutation {
createUser(
"""
Parameters for CreateUser
"""
input: CreateUserInput!
): CreateUserPayload
}
type Query {
currentUser: User
}
@@ -45,8 +9,3 @@ type User {
id: ID!
lastName: String!
}
input UserAttributesInput {
firstName: String!
lastName: String!
}

View File

@@ -1,66 +0,0 @@
# frozen_string_literal: true
require "rails_helper"
RSpec.describe(Mutations::CreateUser) do
describe "#resolve" do
let(:mutation_string) do
<<~GQL
mutation($input: CreateUserInput!) {
createUser(input: $input) {
success
errors
}
}
GQL
end
let(:context) do
{
current_auth: Auth::Profile.new({
id: "_",
email: "user@example.com",
}),
}
end
let(:variables) do
{
input: { user: {
firstName: "First Name",
lastName: "Last Name",
} },
}
end
context "when current_auth is not being used by any user" do
it "create a user to auth" do
result = XStakeSchema.execute(
mutation_string,
variables: variables,
context: context
).to_h
expect(result["data"]["createUser"]["success"]).to(eq(true))
end
end
context "when auth is being used by no users" do
it "returns error" do
User.create(
first_name: "First Name",
last_name: "Last Name",
email: "user@example.com"
)
result = XStakeSchema.execute(
mutation_string,
variables: variables,
context: context
).to_h
expect(result["data"]["createUser"]["success"]).to(eq(false))
expect(result["data"]["createUser"]["errors"]).to(eq(["Validation failed: Email has already been taken"]))
end
end
end
end

View File

@@ -1,16 +0,0 @@
# frozen_string_literal: true
require "rails_helper"
# Specs in this file have access to a helper object that includes
# the HomeHelper. For example:
#
# describe HomeHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# expect(helper.concat_strings("this","that")).to eq("this that")
# end
# end
# end
RSpec.describe(HomeHelper, type: :helper) do
pending "add some examples to (or delete) #{__FILE__}"
end

View File

@@ -1,16 +0,0 @@
# frozen_string_literal: true
require "rails_helper"
# Specs in this file have access to a helper object that includes
# the TailwindHelper. For example:
#
# describe TailwindHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# expect(helper.concat_strings("this","that")).to eq("this that")
# end
# end
# end
RSpec.describe(TailwindHelper, type: :helper) do
pending "add some examples to (or delete) #{__FILE__}"
end