Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Rails.application.routes.draw do
mount_graphql_devise_for(
'User',
at: 'api/v1',
authenticable_type: Types::MyCustomUserType,
authenticatable_type: Types::MyCustomUserType,
operations: {
login: Mutations::Login
},
Expand All @@ -81,8 +81,8 @@ and [queries](https://github.com/graphql-devise/graphql_devise/blob/b5985036e01e
All mutations and queries are built so you can extend default behavior just by extending
our default classes and yielding your customized code after calling `super`, example
[here](https://github.com/graphql-devise/graphql_devise/blob/b5985036e01ea064e43e457b4f0c8516f172471c/spec/dummy/app/graphql/mutations/login.rb#L6).
1. `authenticable_type`: By default, the gem will add an `authenticable` field to every mutation
and an `authenticable` type to every query. Gem will try to use `Types::<model>Type` by
1. `authenticatable_type`: By default, the gem will add an `authenticatable` field to every mutation
and an `authenticatable` type to every query. Gem will try to use `Types::<model>Type` by
default, so in our example you could define `Types::UserType` and every query and mutation
will use it. But, you can override this type with this option like in the example.
1. `skip`: An array of the operations that should not be available in the authentication schema. All these operations are
Expand Down Expand Up @@ -170,7 +170,7 @@ Here is a list of the available mutations and queries assuming your mounted mode
1. `userSendResetPassword(email: String!, redirectUrl: String!): UserSendReserPasswordPayload`
1. `userResendConfirmation(email: String!, redirectUrl: String!): UserResendConfirmationPayload`

The `UserResendConfirmationPayload` will return the `authenticable` resource that was sent the confirmation instructions but also has a `message: String!` that can be used to notify a user what to do after the instructions were sent to them
The `UserResendConfirmationPayload` will return the `authenticatable` resource that was sent the confirmation instructions but also has a `message: String!` that can be used to notify a user what to do after the instructions were sent to them

#### Queries
1. `userConfirmAccount(confirmationToken: String!, redirectUrl: String!): User`
Expand Down
2 changes: 1 addition & 1 deletion app/graphql/graphql_devise/mutations/login.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def resolve(email:, password:)

yield resource if block_given?

{ authenticable: resource}
{ authenticatable: resource}
elsif resource && !active_for_authentication?(resource)
if locked?(resource)
raise_user_error(I18n.t('graphql_devise.mailer.unlock_instructions.account_lock_msg'))
Expand Down
2 changes: 1 addition & 1 deletion app/graphql/graphql_devise/mutations/logout.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def resolve

yield current_resource if block_given?

{ authenticable: current_resource }
{ authenticatable: current_resource }
else
raise_user_error(I18n.t('graphql_devise.user_not_found'))
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def resolve(email:, redirect_url:)
)

{
authenticable: resource,
authenticatable: resource,
message: I18n.t('graphql_devise.confirmations.send_instructions', email: email)
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def resolve(email:, redirect_url:)
)

if resource.errors.empty?
{ authenticable: resource }
{ authenticatable: resource }
else
raise_user_error_list(I18n.t('graphql_devise.invalid_resource'), errors: resource.errors.full_messages)
end
Expand Down
2 changes: 1 addition & 1 deletion app/graphql/graphql_devise/mutations/sign_up.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def resolve(confirm_success_url: nil, **attrs)

set_auth_headers(resource) if resource.active_for_authentication?

{ authenticable: resource }
{ authenticatable: resource }
else
clean_up_passwords(resource)
raise_user_error_list(
Expand Down
2 changes: 1 addition & 1 deletion app/graphql/graphql_devise/mutations/update_password.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def resolve(current_password: nil, **attrs)

yield current_resource if block_given?

{ authenticable: current_resource }
{ authenticatable: current_resource }
else
raise_user_error_list(
I18n.t('graphql_devise.passwords.update_password_error'),
Expand Down
2 changes: 1 addition & 1 deletion app/graphql/graphql_devise/resolvers/confirm_account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def resolve(confirmation_token:, redirect_url:)
end

controller.redirect_to(redirect_to_link)
{ authenticable: resource }
{ authenticatable: resource }
else
raise_user_error(I18n.t('graphql_devise.confirmations.invalid_token'))
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module GraphqlDevise
module Types
class AuthenticableType < GraphQL::Schema::Object
class AuthenticatableType < GraphQL::Schema::Object
field :email, String, null: false
end
end
Expand Down
10 changes: 5 additions & 5 deletions lib/graphql_devise/rails/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ def mount_graphql_devise_for(resource, opts = {})
skip: [:sessions, :registrations, :passwords, :confirmations, :omniauth_callbacks, :unlocks]
)

authenticable_type = opts[:authenticable_type] ||
"Types::#{resource}Type".safe_constantize ||
GraphqlDevise::Types::AuthenticableType
authenticatable_type = opts[:authenticatable_type] ||
"Types::#{resource}Type".safe_constantize ||
GraphqlDevise::Types::AuthenticatableType

used_mutations = if only_operations.present?
default_mutations.slice(*only_operations)
Expand All @@ -54,7 +54,7 @@ def mount_graphql_devise_for(resource, opts = {})
else
new_mutation = Class.new(mutation)
new_mutation.graphql_name("#{resource}#{action.to_s.camelize(:upper)}")
new_mutation.field(:authenticable, authenticable_type, null: true)
new_mutation.field(:authenticatable, authenticatable_type, null: true)

new_mutation
end
Expand All @@ -74,7 +74,7 @@ def mount_graphql_devise_for(resource, opts = {})
else
new_query = Class.new(query)
new_query.graphql_name("#{resource}#{action.to_s.camelize(:upper)}")
new_query.type(authenticable_type, null: true)
new_query.type(authenticatable_type, null: true)

new_query
end
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy/app/graphql/mutations/login.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def resolve(email:, password:)
user.reload
end

original_payload.merge(user: original_payload[:authenticable])
original_payload.merge(user: original_payload[:authenticatable])
end
end
end
2 changes: 1 addition & 1 deletion spec/dummy/app/graphql/mutations/sign_up.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class SignUp < GraphqlDevise::Mutations::SignUp

def resolve(email:, **attrs)
original_payload = super
original_payload.merge(user: original_payload[:authenticable])
original_payload.merge(user: original_payload[:authenticatable])
end
end
end
6 changes: 3 additions & 3 deletions spec/dummy/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

mount_graphql_devise_for(
'Admin',
authenticable_type: Types::CustomAdminType,
skip: [:sign_up, :check_password_token],
at: '/api/v1/admin/graphql_auth'
authenticatable_type: Types::CustomAdminType,
skip: [:sign_up, :check_password_token],
at: '/api/v1/admin/graphql_auth'
)

mount_graphql_devise_for(
Expand Down
8 changes: 4 additions & 4 deletions spec/requests/mutations/login_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
email: "#{admin.email}",
password: "#{password}"
) {
authenticable { email customField }
authenticatable { email customField }
}
}
GRAPHQL
Expand All @@ -110,7 +110,7 @@

it 'works alongside the user mount point' do
expect(json_response[:data][:adminLogin]).to include(
authenticable: { email: admin.email, customField: "email: #{admin.email}" }
authenticatable: { email: admin.email, customField: "email: #{admin.email}" }
)
end
end
Expand All @@ -124,7 +124,7 @@
email: "#{guest.email}",
password: "#{password}"
) {
authenticable { email }
authenticatable { email }
}
}
GRAPHQL
Expand All @@ -134,7 +134,7 @@

it 'works alongside the user mount point' do
expect(json_response[:data][:guestLogin]).to include(
authenticable: { email: guest.email }
authenticatable: { email: guest.email }
)
end
end
Expand Down
8 changes: 4 additions & 4 deletions spec/requests/mutations/logout_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<<-GRAPHQL
mutation {
userLogout {
authenticable { email }
authenticatable { email }
}
}
GRAPHQL
Expand All @@ -23,7 +23,7 @@
expect(response).not_to include_auth_headers
expect(user.reload.tokens.keys).to be_empty
expect(json_response[:data][:userLogout]).to match(
authenticable: { email: user.email }
authenticatable: { email: user.email }
)
expect(json_response[:errors]).to be_nil
end
Expand All @@ -45,7 +45,7 @@
<<-GRAPHQL
mutation {
adminLogout {
authenticable { email }
authenticatable { email }
}
}
GRAPHQL
Expand All @@ -57,7 +57,7 @@
expect(response).not_to include_auth_headers
expect(admin.reload.tokens.keys).to be_empty
expect(json_response[:data][:adminLogout]).to match(
authenticable: { email: admin.email }
authenticatable: { email: admin.email }
)
expect(json_response[:errors]).to be_nil
end
Expand Down
4 changes: 2 additions & 2 deletions spec/requests/mutations/resend_confirmation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
redirectUrl:"#{redirect}"
) {
message
authenticable {
authenticatable {
id
email
}
Expand All @@ -28,7 +28,7 @@
it 'sends an email to the user with confirmation url and returns a success message' do
expect { post_request }.to change(ActionMailer::Base.deliveries, :count).by(1)
expect(json_response[:data][:userResendConfirmation]).to include(
authenticable: {
authenticatable: {
id: id,
email: email
},
Expand Down
2 changes: 1 addition & 1 deletion spec/requests/mutations/send_password_reset_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
email: "#{email}",
redirectUrl: "#{redirect_url}"
) {
authenticable {
authenticatable {
email
}
}
Expand Down
4 changes: 2 additions & 2 deletions spec/requests/mutations/sign_up_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
passwordConfirmation: "#{password}"
confirmSuccessUrl: "#{redirect}"
) {
authenticable {
authenticatable {
email
}
}
Expand All @@ -114,7 +114,7 @@
passwordConfirmation: "#{password}"
confirmSuccessUrl: "#{redirect}"
) {
authenticable {
authenticatable {
email
}
}
Expand Down
4 changes: 2 additions & 2 deletions spec/requests/mutations/update_password_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

expect(response).to include_auth_headers
expect(json_response[:data][:userUpdatePassword]).to match(
authenticable: { email: user.email }
authenticatable: { email: user.email }
)
expect(json_response[:errors]).to be_nil
expect(user).to be_valid_password(password)
Expand All @@ -33,7 +33,7 @@
passwordConfirmation: "#{password_confirmation}",
currentPassword: "#{current_password}"
) {
authenticable { email }
authenticatable { email }
}
}
GRAPHQL
Expand Down
2 changes: 1 addition & 1 deletion spec/requests/queries/check_password_token_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
context 'when redirect_url is not provided' do
let(:redirect_url) { nil }

it 'returns authenticable and credentials in the headers' do
it 'returns authenticatable and credentials in the headers' do
get_request

expect(response).to include_auth_headers
Expand Down