Skip to content

Commit ea64b98

Browse files
Merge pull request #187 from graphql-devise/deprecate-redirect-queries-mutations
Deprecate mutations and queries that required a redirect
2 parents 4f7a929 + 40ad103 commit ea64b98

5 files changed

Lines changed: 20 additions & 9 deletions

File tree

lib/graphql_devise/default_operations/mutations.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ module DefaultOperations
1818
MUTATIONS = {
1919
login: { klass: GraphqlDevise::Mutations::Login, authenticatable: true },
2020
logout: { klass: GraphqlDevise::Mutations::Logout, authenticatable: true },
21-
sign_up: { klass: GraphqlDevise::Mutations::SignUp, authenticatable: true },
21+
sign_up: { klass: GraphqlDevise::Mutations::SignUp, authenticatable: true, deprecation_reason: 'use register instead' },
2222
register: { klass: GraphqlDevise::Mutations::Register, authenticatable: true },
2323
update_password: { klass: GraphqlDevise::Mutations::UpdatePassword, authenticatable: true },
2424
update_password_with_token: { klass: GraphqlDevise::Mutations::UpdatePasswordWithToken, authenticatable: true },
2525
send_password_reset: { klass: GraphqlDevise::Mutations::SendPasswordReset, authenticatable: false },
2626
send_password_reset_with_token: { klass: GraphqlDevise::Mutations::SendPasswordResetWithToken, authenticatable: false },
27-
resend_confirmation: { klass: GraphqlDevise::Mutations::ResendConfirmation, authenticatable: false },
27+
resend_confirmation: { klass: GraphqlDevise::Mutations::ResendConfirmation, authenticatable: false, deprecation_reason: 'use resendConfirmationWithToken instead' },
2828
resend_confirmation_with_token: { klass: GraphqlDevise::Mutations::ResendConfirmationWithToken, authenticatable: false },
2929
confirm_registration_with_token: { klass: GraphqlDevise::Mutations::ConfirmRegistrationWithToken, authenticatable: true }
3030
}.freeze

lib/graphql_devise/default_operations/resolvers.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
module GraphqlDevise
88
module DefaultOperations
99
QUERIES = {
10-
confirm_account: { klass: GraphqlDevise::Resolvers::ConfirmAccount },
11-
check_password_token: { klass: GraphqlDevise::Resolvers::CheckPasswordToken }
10+
confirm_account: { klass: GraphqlDevise::Resolvers::ConfirmAccount, deprecation_reason: 'use the new confirmation flow as it does not require this query anymore' },
11+
check_password_token: { klass: GraphqlDevise::Resolvers::CheckPasswordToken, deprecation_reason: 'use the new password reset flow as it does not require this query anymore' }
1212
}.freeze
1313
end
1414
end

lib/graphql_devise/mount_method/operation_preparers/default_operation_preparer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def call
1717
@selected_operations.except(*@custom_keys).each_with_object({}) do |(action, operation_info), result|
1818
mapped_action = "#{mapping_name}_#{action}"
1919
operation = operation_info[:klass]
20-
options = operation_info.except(:klass)
20+
options = operation_info.except(:klass, :deprecation_reason)
2121

2222
result[mapped_action.to_sym] = [
2323
OperationPreparers::GqlNameSetter.new(mapped_action),

lib/graphql_devise/mount_method/operation_sanitizer.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,24 @@ def initialize(default:, only:, skipped:)
1818
end
1919

2020
def call
21-
if @only.present?
21+
operations = if @only.present?
2222
@default.slice(*@only)
2323
elsif @skipped.present?
2424
@default.except(*@skipped)
2525
else
2626
@default
2727
end
28+
29+
operations.each do |operation, values|
30+
if values[:deprecation_reason].present?
31+
ActiveSupport::Deprecation.warn(<<-DEPRECATION.strip_heredoc, caller)
32+
`#{operation}` is deprecated and will be removed in a future version of this gem.
33+
#{values[:deprecation_reason]}
34+
35+
You can supress this message by skipping `#{operation}` on your ResourceLoader.
36+
DEPRECATION
37+
end
38+
end
2839
end
2940
end
3041
end

spec/services/mount_method/operation_sanitizer_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
context 'when the operations passed are mutations' do
1414
let(:skipped) { [] }
1515
let(:only) { [] }
16-
let(:default) { { operation1: op_class1, operation2: op_class2 } }
16+
let(:default) { { operation1: { klass: op_class1 }, operation2: { klass: op_class2 } } }
1717

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

25-
it { is_expected.to eq(operation1: op_class1) }
25+
it { is_expected.to eq(operation1: { klass: op_class1 }) }
2626
end
2727

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

31-
it { is_expected.to eq(operation1: op_class1) }
31+
it { is_expected.to eq(operation1: { klass: op_class1 }) }
3232
end
3333
end
3434
end

0 commit comments

Comments
 (0)