From da1e783f267ed322e40bc474d77f2661ea1a2e8f Mon Sep 17 00:00:00 2001 From: Guillaume Ferland Date: Sun, 7 Apr 2019 10:33:34 -0400 Subject: [PATCH 01/11] add configurable sign up and update account inputs type --- README.md | 3 ++ app/graphql/mutations/auth/sign_in.rb | 4 +- app/graphql/mutations/auth/sign_up.rb | 16 ++----- app/graphql/mutations/auth/update_account.rb | 16 ++----- app/graphql/mutations/auth/update_password.rb | 43 +++++++++++++++++++ app/graphql/mutations/auth/validate_token.rb | 6 ++- app/graphql/types/auth/inputs/sign_up.rb | 15 +++++++ .../types/auth/inputs/update_account.rb | 7 +++ .../types/auth/inputs/update_password.rb | 15 +++++++ app/graphql/types/graphql_auth.rb | 4 +- app/helpers/graphql/auth_helper.rb | 3 +- app/helpers/graphql/lock_account_helper.rb | 12 ++++++ .../templates/graphql_auth.rb.erb | 5 ++- lib/graphql-auth/configuration.rb | 5 +++ lib/graphql-auth/version.rb | 4 +- 15 files changed, 125 insertions(+), 33 deletions(-) create mode 100644 app/graphql/mutations/auth/update_password.rb create mode 100644 app/graphql/types/auth/inputs/sign_up.rb create mode 100644 app/graphql/types/auth/inputs/update_account.rb create mode 100644 app/graphql/types/auth/inputs/update_password.rb create mode 100644 app/helpers/graphql/lock_account_helper.rb diff --git a/README.md b/README.md index a2b8e60..4b9cdc0 100644 --- a/README.md +++ b/README.md @@ -100,6 +100,9 @@ GraphQL::Auth.configure do |config| # config.app_url = ENV['APP_URL'] # config.user_type = '::Types::Auth::User' + # config.sign_up_input_type = '::Types::Auth::Inputs::SignUp' + # config.update_account_input_type = '::Types::Auth::Inputs::UpdateAccount' + # config.update_password_input_type = '::Types::Inputs::UpdatePassword' # config.sign_up_mutation = false # config.lock_account_mutation = false diff --git a/app/graphql/mutations/auth/sign_in.rb b/app/graphql/mutations/auth/sign_in.rb index 78b29d8..1b2bfd6 100644 --- a/app/graphql/mutations/auth/sign_in.rb +++ b/app/graphql/mutations/auth/sign_in.rb @@ -22,7 +22,9 @@ class Mutations::Auth::SignIn < GraphQL::Schema::Mutation def resolve(email:, password:, remember_me:) response = context[:response] - user = User.where(locked_at: nil).find_by email: email + user = User + user = user.where(locked_at: nil) if GraphQL::Auth.configuration.lock_account_mutation + user = user.find_by email: email valid_sign_in = user.present? && user.valid_password?(password) diff --git a/app/graphql/mutations/auth/sign_up.rb b/app/graphql/mutations/auth/sign_up.rb index cd90cc2..242d272 100644 --- a/app/graphql/mutations/auth/sign_up.rb +++ b/app/graphql/mutations/auth/sign_up.rb @@ -3,25 +3,17 @@ class Mutations::Auth::SignUp < GraphQL::Schema::Mutation include ::Graphql::TokenHelper - argument :email, String, required: true do - description "New user's email" - end - - argument :password, String, required: true do - description "New user's password" - end - - argument :password_confirmation, String, required: true do - description "New user's password confirmation" + argument :input, GraphQL::Auth.configuration.sign_up_input_type.constantize, required: true do + description "Sign up input" end field :errors, [::Types::Auth::Error], null: false field :success, Boolean, null: false field :user, GraphQL::Auth.configuration.user_type.constantize, null: true - def resolve(args) + def resolve(input:) response = context[:response] - user = User.new args + user = User.new input.to_h if user.save generate_access_token(user, response) diff --git a/app/graphql/mutations/auth/update_account.rb b/app/graphql/mutations/auth/update_account.rb index 368487b..9d71fa2 100644 --- a/app/graphql/mutations/auth/update_account.rb +++ b/app/graphql/mutations/auth/update_account.rb @@ -1,23 +1,15 @@ # frozen_string_literal: true class Mutations::Auth::UpdateAccount < GraphQL::Schema::Mutation - argument :current_password, String, required: true do - description "User's current password" - end - - argument :password, String, required: true do - description "User's new password" - end - - argument :password_confirmation, String, required: true do - description "User's new password confirmation" + argument :input, GraphQL::Auth.configuration.update_password_input_type.constantize, required: true do + description "Update account input" end field :errors, [::Types::Auth::Error], null: false field :success, Boolean, null: false field :user, GraphQL::Auth.configuration.user_type.constantize, null: true - def resolve(args) + def resolve(input:) user = context[:current_user] if user.blank? @@ -30,7 +22,7 @@ def resolve(args) } end - user.update_with_password args + user.update_without_password input.to_h if user.errors.any? { diff --git a/app/graphql/mutations/auth/update_password.rb b/app/graphql/mutations/auth/update_password.rb new file mode 100644 index 0000000..50cbd5e --- /dev/null +++ b/app/graphql/mutations/auth/update_password.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +class Mutations::Auth::UpdatePassword < GraphQL::Schema::Mutation + argument :input, GraphQL::Auth.configuration.update_account_input_type.constantize, required: true do + description "Update password input" + end + + field :errors, [::Types::Auth::Error], null: false + field :success, Boolean, null: false + field :user, GraphQL::Auth.configuration.user_type.constantize, null: true + + def resolve(input:) + user = context[:current_user] + + if user.blank? + return { + errors: [ + { field: :_error, message: I18n.t('devise.failure.unauthenticated') } + ], + success: false, + user: nil + } + end + + user.update_with_password input.to_h + + if user.errors.any? + { + errors: user.errors.messages.map do |field, messages| + { field: field.to_s.camelize(:lower), message: messages.first.capitalize } + end, + success: false, + user: nil + } + else + { + errors: [], + success: true, + user: user + } + end + end +end diff --git a/app/graphql/mutations/auth/validate_token.rb b/app/graphql/mutations/auth/validate_token.rb index 43aba9c..bd0f18a 100644 --- a/app/graphql/mutations/auth/validate_token.rb +++ b/app/graphql/mutations/auth/validate_token.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class Mutations::Auth::ValidateToken < GraphQL::Schema::Mutation + include ::Graphql::LockAccountHelper + field :errors, [::Types::Auth::Error], null: false field :success, Boolean, null: false field :user, GraphQL::Auth.configuration.user_type.constantize, null: true @@ -9,7 +11,7 @@ class Mutations::Auth::ValidateToken < GraphQL::Schema::Mutation def resolve user = context[:current_user] - if user.present? && !user.access_locked? + if user.present? && !locked_account?(user) { errors: [], success: true, @@ -25,4 +27,4 @@ def resolve } end end -end \ No newline at end of file +end diff --git a/app/graphql/types/auth/inputs/sign_up.rb b/app/graphql/types/auth/inputs/sign_up.rb new file mode 100644 index 0000000..e14722d --- /dev/null +++ b/app/graphql/types/auth/inputs/sign_up.rb @@ -0,0 +1,15 @@ +class Types::Auth::Inputs::SignUp < Types::BaseInputObject + description 'Sign up arguments' + + argument :email, String, required: true do + description "New user's email" + end + + argument :password, String, required: true do + description "New user's password" + end + + argument :password_confirmation, String, required: true do + description "New user's password confirmation" + end +end diff --git a/app/graphql/types/auth/inputs/update_account.rb b/app/graphql/types/auth/inputs/update_account.rb new file mode 100644 index 0000000..be38bec --- /dev/null +++ b/app/graphql/types/auth/inputs/update_account.rb @@ -0,0 +1,7 @@ +class Types::Auth::Inputs::UpdateAccount < Types::BaseInputObject + description 'Update account arguments' + + argument :email, String, required: true do + description "User's new password" + end +end diff --git a/app/graphql/types/auth/inputs/update_password.rb b/app/graphql/types/auth/inputs/update_password.rb new file mode 100644 index 0000000..cad54ec --- /dev/null +++ b/app/graphql/types/auth/inputs/update_password.rb @@ -0,0 +1,15 @@ +class Types::Auth::Inputs::UpdatePassword < Types::BaseInputObject + description 'Update password arguments' + + argument :current_password, String, required: true do + description "User's current password" + end + + argument :password, String, required: true do + description "User's new password" + end + + argument :password_confirmation, String, required: true do + description "User's new password confirmation" + end +end diff --git a/app/graphql/types/graphql_auth.rb b/app/graphql/types/graphql_auth.rb index 6ee901c..c0ee3c4 100644 --- a/app/graphql/types/graphql_auth.rb +++ b/app/graphql/types/graphql_auth.rb @@ -5,7 +5,7 @@ module Types::GraphqlAuth field :sign_in, mutation: ::Mutations::Auth::SignIn - if GraphQL::Auth.configuration.lock_account_mutation + if GraphQL::Auth.configuration.sign_up_mutation field :sign_up, mutation: ::Mutations::Auth::SignUp end @@ -23,4 +23,4 @@ module Types::GraphqlAuth if GraphQL::Auth.configuration.unlock_account_mutation field :unlock_account, mutation: Mutations::Auth::UnlockAccount end -end \ No newline at end of file +end diff --git a/app/helpers/graphql/auth_helper.rb b/app/helpers/graphql/auth_helper.rb index b967713..067714e 100644 --- a/app/helpers/graphql/auth_helper.rb +++ b/app/helpers/graphql/auth_helper.rb @@ -5,6 +5,7 @@ module Graphql module AuthHelper include ::Graphql::TokenHelper + include ::Graphql::LockAccountHelper def context { @@ -20,7 +21,7 @@ def current_user decrypted_token = GraphQL::Auth::JwtManager.decode(authorization_token) user = User.find_by id: decrypted_token['user'] - return nil if user.blank? || user.access_locked? + return nil if user.blank? || locked_account?(user) # update token if user is found with token generate_access_token(user, response) diff --git a/app/helpers/graphql/lock_account_helper.rb b/app/helpers/graphql/lock_account_helper.rb new file mode 100644 index 0000000..d79ef13 --- /dev/null +++ b/app/helpers/graphql/lock_account_helper.rb @@ -0,0 +1,12 @@ +# include this helper in GraphqlController to use context method so that current_user will be available +# +# ::GraphqlSchema.execute(query, variables: variables, context: context, operation_name: operation_name) + +module Graphql + module LockAccountHelper + def locked_account?(user) + return false unless GraphQL::Auth.configuration.lock_account_mutation + user.access_locked? + end + end +end diff --git a/lib/generators/graphql_auth/templates/graphql_auth.rb.erb b/lib/generators/graphql_auth/templates/graphql_auth.rb.erb index 18aeeeb..00d2c80 100644 --- a/lib/generators/graphql_auth/templates/graphql_auth.rb.erb +++ b/lib/generators/graphql_auth/templates/graphql_auth.rb.erb @@ -4,8 +4,11 @@ GraphQL::Auth.configure do |config| # config.app_url = ENV['APP_URL'] # config.user_type = '::Types::Auth::User' + # config.sign_up_input_type = '::Types::Auth::Inputs::SignUp' + # config.update_account_input_type = '::Types::Auth::Inputs::UpdateAccount' + # config.update_password_input_type = '::Types::Inputs::UpdatePassword' # config.sign_up_mutation = false # config.lock_account_mutation = false # config.unlock_account_mutation = false -end \ No newline at end of file +end diff --git a/lib/graphql-auth/configuration.rb b/lib/graphql-auth/configuration.rb index f1a6408..349d8cc 100644 --- a/lib/graphql-auth/configuration.rb +++ b/lib/graphql-auth/configuration.rb @@ -5,6 +5,8 @@ class Configuration :jwt_secret_key, :app_url, :user_type, + :sign_up_input_type, + :update_account_input_type, :sign_up_mutation, :lock_account_mutation, :unlock_account_mutation @@ -15,6 +17,9 @@ def initialize @app_url = ENV['APP_URL'] @user_type = '::Types::Auth::User' + @sign_up_input_type = '::Types::Inputs::SignUp' + @update_account_input_type = '::Types::Inputs::UpdateAccount' + @update_password_input_type = '::Types::Inputs::UpdatePassword' @sign_up_mutation = false @lock_account_mutation = false diff --git a/lib/graphql-auth/version.rb b/lib/graphql-auth/version.rb index e67fdb8..7e83ade 100644 --- a/lib/graphql-auth/version.rb +++ b/lib/graphql-auth/version.rb @@ -1,5 +1,5 @@ module GraphQL module Auth - VERSION = '0.4.2' + VERSION = '0.4.3' end -end \ No newline at end of file +end From a370381afd10434f144a78df2577da7427030a6d Mon Sep 17 00:00:00 2001 From: Guillaume Ferland Date: Sun, 7 Apr 2019 21:24:32 -0400 Subject: [PATCH 02/11] add update password tests --- ...ccount_spec.rb => update_password_spec.rb} | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) rename spec/graphql/mutations/auth/{update_account_spec.rb => update_password_spec.rb} (73%) diff --git a/spec/graphql/mutations/auth/update_account_spec.rb b/spec/graphql/mutations/auth/update_password_spec.rb similarity index 73% rename from spec/graphql/mutations/auth/update_account_spec.rb rename to spec/graphql/mutations/auth/update_password_spec.rb index f7b6a1b..092b15c 100644 --- a/spec/graphql/mutations/auth/update_account_spec.rb +++ b/spec/graphql/mutations/auth/update_password_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Mutations::Auth::UpdateAccount, type: :request do +RSpec.describe Mutations::Auth::UpdatePassword, type: :request do let!(:user) do User.create!( email: 'email@example.com', @@ -21,7 +21,7 @@ let(:query_string) do <<-GRAPHQL mutation($currentPassword: String!, $password: String!, $passwordConfirmation: String!) { - updateAccount(currentPassword: $currentPassword, password: $password, passwordConfirmation: $passwordConfirmation) { + updatePassword(currentPassword: $currentPassword, password: $password, passwordConfirmation: $passwordConfirmation) { success user { email @@ -54,11 +54,11 @@ } end - it 'succeeds to update the account' do + it 'succeeds to update the password' do subject - expect(result['data']['updateAccount']['success']).to be_truthy - expect(result['data']['updateAccount']['user']['email']).to eq(user.email) + expect(result['data']['updatePassword']['success']).to be_truthy + expect(result['data']['updatePassword']['user']['email']).to eq(user.email) end end @@ -71,9 +71,9 @@ } end - it 'fails to update the account' do + it 'fails to update the password' do subject - expect(result['data']['updateAccount']['success']).to be_falsey + expect(result['data']['updatePassword']['success']).to be_falsey end end @@ -90,9 +90,9 @@ } end - it 'fails to update the account' do + it 'fails to update the password' do subject - expect(result['data']['updateAccount']['success']).to be_falsey + expect(result['data']['updatePassword']['success']).to be_falsey end end end @@ -114,9 +114,9 @@ } end - it 'fails to update the account' do + it 'fails to update the password' do subject - expect(result['data']['updateAccount']['success']).to be_falsey + expect(result['data']['updatePassword']['success']).to be_falsey end end @@ -129,9 +129,9 @@ } end - it 'fails to update the account' do + it 'fails to update the password' do subject - expect(result['data']['updateAccount']['success']).to be_falsey + expect(result['data']['updatePassword']['success']).to be_falsey end end @@ -148,9 +148,9 @@ } end - it 'fails to update the account' do + it 'fails to update the password' do subject - expect(result['data']['updateAccount']['success']).to be_falsey + expect(result['data']['updatePassword']['success']).to be_falsey end end end From d128a7bcb1c503441cd0a920ea25997dd0580d05 Mon Sep 17 00:00:00 2001 From: Guillaume Ferland Date: Sun, 7 Apr 2019 21:52:44 -0400 Subject: [PATCH 03/11] fix update_password_input_type class --- README.md | 2 +- lib/generators/graphql_auth/templates/graphql_auth.rb.erb | 2 +- lib/graphql-auth/configuration.rb | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 4b9cdc0..b97829b 100644 --- a/README.md +++ b/README.md @@ -102,7 +102,7 @@ GraphQL::Auth.configure do |config| # config.user_type = '::Types::Auth::User' # config.sign_up_input_type = '::Types::Auth::Inputs::SignUp' # config.update_account_input_type = '::Types::Auth::Inputs::UpdateAccount' - # config.update_password_input_type = '::Types::Inputs::UpdatePassword' + # config.update_password_input_type = '::Types::Auth::Inputs::UpdatePassword' # config.sign_up_mutation = false # config.lock_account_mutation = false diff --git a/lib/generators/graphql_auth/templates/graphql_auth.rb.erb b/lib/generators/graphql_auth/templates/graphql_auth.rb.erb index 00d2c80..f164e68 100644 --- a/lib/generators/graphql_auth/templates/graphql_auth.rb.erb +++ b/lib/generators/graphql_auth/templates/graphql_auth.rb.erb @@ -6,7 +6,7 @@ GraphQL::Auth.configure do |config| # config.user_type = '::Types::Auth::User' # config.sign_up_input_type = '::Types::Auth::Inputs::SignUp' # config.update_account_input_type = '::Types::Auth::Inputs::UpdateAccount' - # config.update_password_input_type = '::Types::Inputs::UpdatePassword' + # config.update_password_input_type = '::Types::Auth::Inputs::UpdatePassword' # config.sign_up_mutation = false # config.lock_account_mutation = false diff --git a/lib/graphql-auth/configuration.rb b/lib/graphql-auth/configuration.rb index 349d8cc..888f4ab 100644 --- a/lib/graphql-auth/configuration.rb +++ b/lib/graphql-auth/configuration.rb @@ -17,9 +17,9 @@ def initialize @app_url = ENV['APP_URL'] @user_type = '::Types::Auth::User' - @sign_up_input_type = '::Types::Inputs::SignUp' - @update_account_input_type = '::Types::Inputs::UpdateAccount' - @update_password_input_type = '::Types::Inputs::UpdatePassword' + @sign_up_input_type = '::Types::Auth::Inputs::SignUp' + @update_account_input_type = '::Types::Auth::Inputs::UpdateAccount' + @update_password_input_type = '::Types::Auth::Inputs::UpdatePassword' @sign_up_mutation = false @lock_account_mutation = false From 66bf9c9b5d704248e4c4be532e4903668e89431e Mon Sep 17 00:00:00 2001 From: Guillaume Ferland Date: Sun, 7 Apr 2019 22:17:02 -0400 Subject: [PATCH 04/11] add missing update password input type config --- lib/graphql-auth/configuration.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/graphql-auth/configuration.rb b/lib/graphql-auth/configuration.rb index 888f4ab..07d189a 100644 --- a/lib/graphql-auth/configuration.rb +++ b/lib/graphql-auth/configuration.rb @@ -7,6 +7,7 @@ class Configuration :user_type, :sign_up_input_type, :update_account_input_type, + :update_password_input_type, :sign_up_mutation, :lock_account_mutation, :unlock_account_mutation From c08bb9cf7ce7d1ce39549c13b758001cc0d6dedc Mon Sep 17 00:00:00 2001 From: Guillaume Ferland Date: Sun, 14 Apr 2019 21:08:59 -0400 Subject: [PATCH 05/11] fix update password and update account input argument type --- app/graphql/mutations/auth/update_account.rb | 2 +- app/graphql/mutations/auth/update_password.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/graphql/mutations/auth/update_account.rb b/app/graphql/mutations/auth/update_account.rb index 9d71fa2..b31ecad 100644 --- a/app/graphql/mutations/auth/update_account.rb +++ b/app/graphql/mutations/auth/update_account.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class Mutations::Auth::UpdateAccount < GraphQL::Schema::Mutation - argument :input, GraphQL::Auth.configuration.update_password_input_type.constantize, required: true do + argument :input, GraphQL::Auth.configuration.update_account_input_type.constantize, required: true do description "Update account input" end diff --git a/app/graphql/mutations/auth/update_password.rb b/app/graphql/mutations/auth/update_password.rb index 50cbd5e..f021cc2 100644 --- a/app/graphql/mutations/auth/update_password.rb +++ b/app/graphql/mutations/auth/update_password.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class Mutations::Auth::UpdatePassword < GraphQL::Schema::Mutation - argument :input, GraphQL::Auth.configuration.update_account_input_type.constantize, required: true do + argument :input, GraphQL::Auth.configuration.update_password_input_type.constantize, required: true do description "Update password input" end From f7c588eaf20433d5198448fdf2690734ccdcc633 Mon Sep 17 00:00:00 2001 From: Guillaume Ferland Date: Sun, 14 Apr 2019 21:15:25 -0400 Subject: [PATCH 06/11] add update password mutation --- app/graphql/types/graphql_auth.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/graphql/types/graphql_auth.rb b/app/graphql/types/graphql_auth.rb index c0ee3c4..a4b99c0 100644 --- a/app/graphql/types/graphql_auth.rb +++ b/app/graphql/types/graphql_auth.rb @@ -11,6 +11,7 @@ module Types::GraphqlAuth field :forgot_password, mutation: ::Mutations::Auth::ForgotPassword field :reset_password, mutation: ::Mutations::Auth::ResetPassword + field :update_password, mutation: ::Mutations::Auth::UpdatePassword field :update_account, mutation: ::Mutations::Auth::UpdateAccount From 9013a261c643479de029e354b6cbf809ada98757 Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Wed, 2 Oct 2019 22:47:24 -0400 Subject: [PATCH 07/11] Fix arg email description --- app/graphql/types/auth/inputs/update_account.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/graphql/types/auth/inputs/update_account.rb b/app/graphql/types/auth/inputs/update_account.rb index be38bec..469a86e 100644 --- a/app/graphql/types/auth/inputs/update_account.rb +++ b/app/graphql/types/auth/inputs/update_account.rb @@ -2,6 +2,6 @@ class Types::Auth::Inputs::UpdateAccount < Types::BaseInputObject description 'Update account arguments' argument :email, String, required: true do - description "User's new password" + description "User's email" end end From c72216db3f1aa9c7c1d094b36aaf7e7a753ca548 Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Wed, 2 Oct 2019 22:47:37 -0400 Subject: [PATCH 08/11] Remove unused LockAccountHelper --- app/helpers/graphql/lock_account_helper.rb | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 app/helpers/graphql/lock_account_helper.rb diff --git a/app/helpers/graphql/lock_account_helper.rb b/app/helpers/graphql/lock_account_helper.rb deleted file mode 100644 index d79ef13..0000000 --- a/app/helpers/graphql/lock_account_helper.rb +++ /dev/null @@ -1,12 +0,0 @@ -# include this helper in GraphqlController to use context method so that current_user will be available -# -# ::GraphqlSchema.execute(query, variables: variables, context: context, operation_name: operation_name) - -module Graphql - module LockAccountHelper - def locked_account?(user) - return false unless GraphQL::Auth.configuration.lock_account_mutation - user.access_locked? - end - end -end From 2882f14981c1b4ab95ad3f7cfdd460b7200cff8e Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Wed, 2 Oct 2019 23:34:49 -0400 Subject: [PATCH 09/11] Declare graphql_name on inputs --- app/graphql/types/auth/inputs/sign_up.rb | 1 + app/graphql/types/auth/inputs/update_account.rb | 1 + app/graphql/types/auth/inputs/update_password.rb | 1 + 3 files changed, 3 insertions(+) diff --git a/app/graphql/types/auth/inputs/sign_up.rb b/app/graphql/types/auth/inputs/sign_up.rb index e14722d..f50f825 100644 --- a/app/graphql/types/auth/inputs/sign_up.rb +++ b/app/graphql/types/auth/inputs/sign_up.rb @@ -1,4 +1,5 @@ class Types::Auth::Inputs::SignUp < Types::BaseInputObject + graphql_name 'SignUpInput' description 'Sign up arguments' argument :email, String, required: true do diff --git a/app/graphql/types/auth/inputs/update_account.rb b/app/graphql/types/auth/inputs/update_account.rb index 469a86e..fa7dda6 100644 --- a/app/graphql/types/auth/inputs/update_account.rb +++ b/app/graphql/types/auth/inputs/update_account.rb @@ -1,4 +1,5 @@ class Types::Auth::Inputs::UpdateAccount < Types::BaseInputObject + graphql_name 'UpdateAccountInput' description 'Update account arguments' argument :email, String, required: true do diff --git a/app/graphql/types/auth/inputs/update_password.rb b/app/graphql/types/auth/inputs/update_password.rb index cad54ec..4b7d332 100644 --- a/app/graphql/types/auth/inputs/update_password.rb +++ b/app/graphql/types/auth/inputs/update_password.rb @@ -1,4 +1,5 @@ class Types::Auth::Inputs::UpdatePassword < Types::BaseInputObject + graphql_name 'UpdatePasswordInput' description 'Update password arguments' argument :current_password, String, required: true do From ffd7a512f277dfb7b44be8567dc3c10460cc0a04 Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Wed, 2 Oct 2019 23:35:03 -0400 Subject: [PATCH 10/11] Update dummy graphql_auth initializer --- spec/dummy/config/initializers/graphql_auth.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/spec/dummy/config/initializers/graphql_auth.rb b/spec/dummy/config/initializers/graphql_auth.rb index 40920c5..8b47d26 100644 --- a/spec/dummy/config/initializers/graphql_auth.rb +++ b/spec/dummy/config/initializers/graphql_auth.rb @@ -4,14 +4,17 @@ # config.app_url = ENV['APP_URL'] # config.user_type = '::Types::Auth::User' + # config.sign_up_input_type = '::Types::Auth::Inputs::SignUp' + # config.update_account_input_type = '::Types::Auth::Inputs::UpdateAccount' + # config.update_password_input_type = '::Types::Auth::Inputs::UpdatePassword' # Devise allowed actions # Don't forget to enable the lockable setting in your Devise user model if you plan on using the lock_account feature - config.allow_sign_up = true + # config.allow_sign_up = true config.allow_lock_account = true config.allow_unlock_account = true # Allow custom mutations for signup and update account # config.sign_up_mutation = '::Mutations::Auth::SignUp' - # config.udpate_account_mutation = '::Mutations::Auth::UpdateAccount' -end \ No newline at end of file + # config.update_account_mutation = '::Mutations::Auth::UpdateAccount' +end From ecdd37e2630995292b3c1f1662df1b36850dd65b Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Wed, 2 Oct 2019 23:35:12 -0400 Subject: [PATCH 11/11] Update specs --- spec/graphql/mutations/auth/sign_up_spec.rb | 20 +++--- .../mutations/auth/update_password_spec.rb | 63 ++++++++----------- 2 files changed, 39 insertions(+), 44 deletions(-) diff --git a/spec/graphql/mutations/auth/sign_up_spec.rb b/spec/graphql/mutations/auth/sign_up_spec.rb index ec5da41..a09e818 100644 --- a/spec/graphql/mutations/auth/sign_up_spec.rb +++ b/spec/graphql/mutations/auth/sign_up_spec.rb @@ -13,8 +13,8 @@ let(:query_string) do <<-GRAPHQL - mutation($email: String!, $password: String!, $passwordConfirmation: String!) { - signUp(email: $email, password: $password, passwordConfirmation: $passwordConfirmation) { + mutation($input: SignUpInput!) { + signUp(input: $input) { success user { email @@ -40,9 +40,11 @@ context 'when valid parameters are given' do let(:variables) do { - 'email' => 'email@example.com', - 'password' => 'password', - 'passwordConfirmation' => 'password' + 'input' => { + 'email' => 'email@example.com', + 'password' => 'password', + 'passwordConfirmation' => 'password' + } } end @@ -55,9 +57,11 @@ context 'when invalid parameters are given' do let(:variables) do { - 'email' => 'emailexample.com', - 'password' => 'password', - 'passwordConfirmation' => 'password2' + 'input' => { + 'email' => 'email@example.com', + 'password' => 'password', + 'passwordConfirmation' => 'password2' + } } end diff --git a/spec/graphql/mutations/auth/update_password_spec.rb b/spec/graphql/mutations/auth/update_password_spec.rb index 092b15c..e10247a 100644 --- a/spec/graphql/mutations/auth/update_password_spec.rb +++ b/spec/graphql/mutations/auth/update_password_spec.rb @@ -20,8 +20,8 @@ let(:query_string) do <<-GRAPHQL - mutation($currentPassword: String!, $password: String!, $passwordConfirmation: String!) { - updatePassword(currentPassword: $currentPassword, password: $password, passwordConfirmation: $passwordConfirmation) { + mutation($input: UpdatePasswordInput!) { + updatePassword(input: $input) { success user { email @@ -48,9 +48,11 @@ context 'when valid parameters are given' do let(:variables) do { - 'currentPassword' => 'password', - 'password' => 'newpassword', - 'passwordConfirmation' => 'newpassword' + 'input' => { + 'currentPassword' => 'password', + 'password' => 'newpassword', + 'passwordConfirmation' => 'newpassword' + } } end @@ -65,28 +67,11 @@ context 'when invalid parameters are given' do let(:variables) do { - 'currentPassword' => 'badpassword', - 'password' => 'newpassword', - 'passwordConfirmation' => 'newpassword' - } - end - - it 'fails to update the password' do - subject - expect(result['data']['updatePassword']['success']).to be_falsey - end - end - - context 'when user is locked' do - before do - user.lock_access! - end - - let(:variables) do - { - 'currentPassword' => 'badpassword', - 'password' => 'newpassword', - 'passwordConfirmation' => 'newpassword' + 'input' => { + 'currentPassword' => 'badpassword', + 'password' => 'newpassword', + 'passwordConfirmation' => 'newpassword' + } } end @@ -108,9 +93,11 @@ context 'when valid parameters are given' do let(:variables) do { - 'currentPassword' => 'password', - 'password' => 'newpassword', - 'passwordConfirmation' => 'newpassword' + 'input' => { + 'currentPassword' => 'password', + 'password' => 'newpassword', + 'passwordConfirmation' => 'newpassword' + } } end @@ -123,9 +110,11 @@ context 'when invalid parameters are given' do let(:variables) do { - 'currentPassword' => 'badpassword', - 'password' => 'newpassword', - 'passwordConfirmation' => 'newpassword' + 'input' => { + 'currentPassword' => 'badpassword', + 'password' => 'newpassword', + 'passwordConfirmation' => 'newpassword' + } } end @@ -142,9 +131,11 @@ let(:variables) do { - 'currentPassword' => 'badpassword', - 'password' => 'newpassword', - 'passwordConfirmation' => 'newpassword' + 'input' => { + 'currentPassword' => 'password', + 'password' => 'newpassword', + 'passwordConfirmation' => 'newpassword' + } } end