Skip to content

Commit

Permalink
Merge pull request #187 from graphql-devise/deprecate-redirect-querie…
Browse files Browse the repository at this point in the history
…s-mutations

Deprecate mutations and queries that required a redirect
  • Loading branch information
mcelicalderon authored Jun 7, 2021
2 parents 4f7a929 + 40ad103 commit ea64b98
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
4 changes: 2 additions & 2 deletions lib/graphql_devise/default_operations/mutations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ module DefaultOperations
MUTATIONS = {
login: { klass: GraphqlDevise::Mutations::Login, authenticatable: true },
logout: { klass: GraphqlDevise::Mutations::Logout, authenticatable: true },
sign_up: { klass: GraphqlDevise::Mutations::SignUp, authenticatable: true },
sign_up: { klass: GraphqlDevise::Mutations::SignUp, authenticatable: true, deprecation_reason: 'use register instead' },
register: { klass: GraphqlDevise::Mutations::Register, authenticatable: true },
update_password: { klass: GraphqlDevise::Mutations::UpdatePassword, authenticatable: true },
update_password_with_token: { klass: GraphqlDevise::Mutations::UpdatePasswordWithToken, authenticatable: true },
send_password_reset: { klass: GraphqlDevise::Mutations::SendPasswordReset, authenticatable: false },
send_password_reset_with_token: { klass: GraphqlDevise::Mutations::SendPasswordResetWithToken, authenticatable: false },
resend_confirmation: { klass: GraphqlDevise::Mutations::ResendConfirmation, authenticatable: false },
resend_confirmation: { klass: GraphqlDevise::Mutations::ResendConfirmation, authenticatable: false, deprecation_reason: 'use resendConfirmationWithToken instead' },
resend_confirmation_with_token: { klass: GraphqlDevise::Mutations::ResendConfirmationWithToken, authenticatable: false },
confirm_registration_with_token: { klass: GraphqlDevise::Mutations::ConfirmRegistrationWithToken, authenticatable: true }
}.freeze
Expand Down
4 changes: 2 additions & 2 deletions lib/graphql_devise/default_operations/resolvers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
module GraphqlDevise
module DefaultOperations
QUERIES = {
confirm_account: { klass: GraphqlDevise::Resolvers::ConfirmAccount },
check_password_token: { klass: GraphqlDevise::Resolvers::CheckPasswordToken }
confirm_account: { klass: GraphqlDevise::Resolvers::ConfirmAccount, deprecation_reason: 'use the new confirmation flow as it does not require this query anymore' },
check_password_token: { klass: GraphqlDevise::Resolvers::CheckPasswordToken, deprecation_reason: 'use the new password reset flow as it does not require this query anymore' }
}.freeze
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def call
@selected_operations.except(*@custom_keys).each_with_object({}) do |(action, operation_info), result|
mapped_action = "#{mapping_name}_#{action}"
operation = operation_info[:klass]
options = operation_info.except(:klass)
options = operation_info.except(:klass, :deprecation_reason)

result[mapped_action.to_sym] = [
OperationPreparers::GqlNameSetter.new(mapped_action),
Expand Down
13 changes: 12 additions & 1 deletion lib/graphql_devise/mount_method/operation_sanitizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,24 @@ def initialize(default:, only:, skipped:)
end

def call
if @only.present?
operations = if @only.present?
@default.slice(*@only)
elsif @skipped.present?
@default.except(*@skipped)
else
@default
end

operations.each do |operation, values|
if values[:deprecation_reason].present?
ActiveSupport::Deprecation.warn(<<-DEPRECATION.strip_heredoc, caller)
`#{operation}` is deprecated and will be removed in a future version of this gem.
#{values[:deprecation_reason]}
You can supress this message by skipping `#{operation}` on your ResourceLoader.
DEPRECATION
end
end
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions spec/services/mount_method/operation_sanitizer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
context 'when the operations passed are mutations' do
let(:skipped) { [] }
let(:only) { [] }
let(:default) { { operation1: op_class1, operation2: op_class2 } }
let(:default) { { operation1: { klass: op_class1 }, operation2: { klass: op_class2 } } }

context 'when no other option besides default is passed' do
it { is_expected.to eq(default) }
Expand All @@ -22,13 +22,13 @@
context 'when there are only operations' do
let(:only) { [:operation1] }

it { is_expected.to eq(operation1: op_class1) }
it { is_expected.to eq(operation1: { klass: op_class1 }) }
end

context 'when there are skipped operations' do
let(:skipped) { [:operation2] }

it { is_expected.to eq(operation1: op_class1) }
it { is_expected.to eq(operation1: { klass: op_class1 }) }
end
end
end
Expand Down

0 comments on commit ea64b98

Please sign in to comment.