From fb99da5550465b8408a6dbe69d52ece35cc9adbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Geonizeli?= Date: Tue, 10 Aug 2021 21:57:06 -0300 Subject: [PATCH] remove createUser mutation --- app/graphql/mutations/create_user.rb | 16 ----- app/graphql/types/mutation_type.rb | 1 - app/graphql/x_stake_schema.rb | 2 +- app/javascript/__generated__/schema.graphql | 41 ------------- spec/graphql/mutations/create_user_spec.rb | 66 --------------------- spec/helpers/home_helper_spec.rb | 16 ----- spec/helpers/tailwind_helper_spec.rb | 16 ----- 7 files changed, 1 insertion(+), 157 deletions(-) delete mode 100644 app/graphql/mutations/create_user.rb delete mode 100644 spec/graphql/mutations/create_user_spec.rb delete mode 100644 spec/helpers/home_helper_spec.rb delete mode 100644 spec/helpers/tailwind_helper_spec.rb diff --git a/app/graphql/mutations/create_user.rb b/app/graphql/mutations/create_user.rb deleted file mode 100644 index c314e14..0000000 --- a/app/graphql/mutations/create_user.rb +++ /dev/null @@ -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 diff --git a/app/graphql/types/mutation_type.rb b/app/graphql/types/mutation_type.rb index 7712f72..c928833 100644 --- a/app/graphql/types/mutation_type.rb +++ b/app/graphql/types/mutation_type.rb @@ -1,6 +1,5 @@ # frozen_string_literal: true module Types class MutationType < Types::BaseObject - field :create_user, mutation: Mutations::CreateUser end end diff --git a/app/graphql/x_stake_schema.rb b/app/graphql/x_stake_schema.rb index f07976a..afef4fc 100644 --- a/app/graphql/x_stake_schema.rb +++ b/app/graphql/x_stake_schema.rb @@ -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) diff --git a/app/javascript/__generated__/schema.graphql b/app/javascript/__generated__/schema.graphql index a90a765..79516c9 100644 --- a/app/javascript/__generated__/schema.graphql +++ b/app/javascript/__generated__/schema.graphql @@ -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! -} diff --git a/spec/graphql/mutations/create_user_spec.rb b/spec/graphql/mutations/create_user_spec.rb deleted file mode 100644 index ef8f711..0000000 --- a/spec/graphql/mutations/create_user_spec.rb +++ /dev/null @@ -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 diff --git a/spec/helpers/home_helper_spec.rb b/spec/helpers/home_helper_spec.rb deleted file mode 100644 index 66849f3..0000000 --- a/spec/helpers/home_helper_spec.rb +++ /dev/null @@ -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 diff --git a/spec/helpers/tailwind_helper_spec.rb b/spec/helpers/tailwind_helper_spec.rb deleted file mode 100644 index d3f70fe..0000000 --- a/spec/helpers/tailwind_helper_spec.rb +++ /dev/null @@ -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