Skip to content

Commit 9f3ab47

Browse files
committed
Remove deprecations from docs before v1 release
1 parent 7e81386 commit 9f3ab47

7 files changed

Lines changed: 47 additions & 178 deletions

File tree

README.md

Lines changed: 6 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,14 @@ GraphQL interface on top of the [Devise Token Auth](https://github.com/lynndylan
2323
* [Configuring Model](#configuring-model)
2424
* [Email Reconfirmation](#email-reconfirmation)
2525
* [Current flow](#current-flow)
26-
* [Deprecated flow - Do Not Use](#deprecated-flow---do-not-use)
2726
* [Customizing Email Templates](#customizing-email-templates)
2827
* [I18n](#i18n)
2928
* [Authenticating Controller Actions](#authenticating-controller-actions)
3029
* [Authenticate Resource in the Controller (>= v0.15.0)](#authenticate-resource-in-the-controller--v0150)
3130
* [Authentication Options](#authentication-options)
32-
* [Authenticate Before Reaching Your GQL Schema (Deprecated)](#authenticate-before-reaching-your-gql-schema-deprecated)
33-
* [Authenticate in an Existing Schema (Deprecated)](#authenticate-in-an-existing-schema-deprecated)
34-
* [Authentication Options](#authentication-options-1)
35-
* [Important](#important)
3631
* [Making Requests](#making-requests)
3732
* [Introspection query](#introspection-query)
3833
* [Mutations](#mutations)
39-
* [Queries](#queries)
4034
* [Reset Password Flow](#reset-password-flow)
4135
* [More Configuration Options](#more-configuration-options)
4236
* [Devise Token Auth Initializer](#devise-token-auth-initializer)
@@ -47,7 +41,7 @@ GraphQL interface on top of the [Devise Token Auth](https://github.com/lynndylan
4741
* [Contributing](#contributing)
4842
* [License](#license)
4943

50-
<!-- Added by: david, at: jue jun 24 18:32:27 -05 2021 -->
44+
<!-- Added by: mcelicalderon, at: Wed Oct 20 19:39:36 -05 2021 -->
5145

5246
<!--te-->
5347

@@ -297,17 +291,11 @@ The following is a list of the symbols you can provide to the `operations`, `ski
297291
```ruby
298292
:login
299293
:logout
300-
:sign_up (deprecated)
301294
:register
302-
:update_password (deprecated)
303295
:update_password_with_token
304-
:send_password_reset (deprecated)
305296
:send_password_reset_with_token
306-
:resend_confirmation (deprecated)
307297
:resend_confirmation_with_token
308298
:confirm_registration_with_token
309-
:confirm_account (deprecated)
310-
:check_password_token (deprecated)
311299
```
312300

313301
### Configuring Model
@@ -369,31 +357,6 @@ user.update_with_email(
369357
)
370358
```
371359

372-
#### Deprecated flow - Do Not Use
373-
`update_with_email` requires two additional attributes when email will change or an error
374-
will be raised:
375-
376-
- `schema_url`: The full url where your GQL schema is mounted. You can get this value from the
377-
controller available in the context of your mutations and queries like this:
378-
```ruby
379-
context[:controller].full_url_without_params
380-
```
381-
- `confirmation_success_url`: This the full url where you want users to be redirected after
382-
the email has changed successfully (usually a front-end url). This value is mandatory
383-
unless you have set `default_confirm_success_url` in your devise_token_auth initializer.
384-
385-
So, it's up to you where you require confirmation of changing emails.
386-
[Here's an example](https://github.com/graphql-devise/graphql_devise/blob/c4dcb17e98f8d84cc5ac002c66ed98a797d3bc82/spec/dummy/app/graphql/mutations/update_user.rb#L13)
387-
on how you might do this. And also a demonstration on the method usage:
388-
```ruby
389-
user.update_with_email(
390-
name: 'New Name',
391-
email: 'new@domain.com',
392-
schema_url: 'http://localhost:3000/graphql',
393-
confirmation_success_url: 'https://google.com'
394-
)
395-
```
396-
397360
### Customizing Email Templates
398361
The approach of this gem is a bit different from DeviseTokenAuth. We have placed our templates in `app/views/graphql_devise/mailer`,
399362
so if you want to change them, place yours on the same dir structure on your Rails project. You can customize these two templates:
@@ -479,87 +442,6 @@ module Types
479442
end
480443
```
481444

482-
#### Authenticate Before Reaching Your GQL Schema (Deprecated)
483-
For this you will need to call `authenticate_<model>!` in a `before_action` controller hook.
484-
In our example our model is `User`, so it would look like this:
485-
```ruby
486-
# app/controllers/my_controller.rb
487-
488-
class MyController < ApplicationController
489-
include GraphqlDevise::Concerns::SetUserByToken
490-
491-
before_action :authenticate_user!
492-
493-
def my_action
494-
result = DummySchema.execute(params[:query], context: { current_resource: current_user })
495-
render json: result unless performed?
496-
end
497-
end
498-
```
499-
500-
The install generator can include the concern in you application controller.
501-
If authentication fails for a request, execution will halt and a REST error will be returned since the request never reaches your GQL schema.
502-
503-
#### Authenticate in an Existing Schema (Deprecated)
504-
For this you will need to add the `GraphqlDevise::SchemaPlugin` to your schema as described
505-
[here](#mounting-operations-into-your-own-schema).
506-
507-
```ruby
508-
# app/controllers/my_controller.rb
509-
510-
class MyController < ApplicationController
511-
include GraphqlDevise::Concerns::SetUserByToken
512-
513-
def my_action
514-
result = DummySchema.execute(params[:query], context: graphql_context(:user))
515-
render json: result unless performed?
516-
end
517-
end
518-
```
519-
The `graphql_context` method receives a symbol identifying the resource you are trying
520-
to authenticate. So if you mounted the `User` resource, the symbol is `:user`. You can use
521-
this snippet to find the symbol for more complex scenarios
522-
`resource_klass.to_s.underscore.tr('/', '_').to_sym`. `graphql_context` can also take an
523-
array of resources if you mounted more than one into your schema. The gem will try to
524-
authenticate a resource for each element on the array until it finds one.
525-
526-
Internally in your own mutations and queries a key `current_resource` will be available in
527-
the context if a resource was successfully authenticated or `nil` otherwise.
528-
529-
Keep in mind that sending multiple values to the `graphql_context` method means that depending
530-
on who makes the request, the context value `current_resource` might contain instances of the
531-
different models you might have mounted into the schema.
532-
533-
Please note that by using this mechanism your GQL schema will be in control of what queries are
534-
restricted to authenticated users and you can only do this at the root level fields of your GQL
535-
schema. Configure the plugin as explained [here](#mounting-operations-into-your-own-schema)
536-
so this can work.
537-
538-
##### Authentication Options
539-
Whether you setup authentications as a default in the plugin, or you do it at the field level,
540-
these are the options you can use:
541-
1. **Any truthy value:** If `current_resource` is not `.present?`, query will return an authentication error.
542-
1. **A callable object:** Provided object will be called with `current_resource` as the only argument if `current_resource` is `.present?`. If return value of the callable object is false, query will return an authentication error.
543-
544-
In your main app's schema this is how you might specify if a field needs to be authenticated or not:
545-
```ruby
546-
module Types
547-
class QueryType < Types::BaseObject
548-
# user field used the default set in the Plugin's initializer
549-
field :user, resolver: Resolvers::UserShow
550-
# this field will never require authentication
551-
field :public_field, String, null: false, authenticate: false
552-
# this field requires authentication
553-
field :private_field, String, null: false, authenticate: true
554-
# this field requires authenticated users to also be admins
555-
field :admin_field, String, null: false, authenticate: ->(user) { user.admin? }
556-
end
557-
end
558-
```
559-
560-
#### Important
561-
Remember to check `performed?` before rendering the result of the graphql operation. This is required because some operations perform a redirect and without this check you will get a `AbstractController::DoubleRenderError`.
562-
563445
### Making Requests
564446
Here is a list of the available mutations and queries assuming your mounted model is `User`.
565447

@@ -572,30 +454,10 @@ Operation | Description | Example
572454
:--- | :--- | :------------------:
573455
login | This mutation has a second field by default. `credentials` can be fetched directly on the mutation return type.<br>Credentials are still returned in the headers of the response. | userLogin(email: String!, password: String!): UserLoginPayload |
574456
logout | requires authentication headers. Deletes current session if successful. | userLogout: UserLogoutPayload |
575-
signUp **(Deprecated)** | The parameter `confirmSuccessUrl` is optional unless you are using the `confirmable` plugin from Devise in your `resource`'s model. If you have `confirmable` set up, you will have to provide it unless you have `config.default_confirm_success_url` set in `config/initializers/devise_token_auth.rb`. | userSignUp(email: String!, password: String!, passwordConfirmation: String!, confirmSuccessUrl: String): UserSignUpPayload |
576457
register | The parameter `confirmUrl` is optional unless you are using the `confirmable` plugin from Devise in your `resource`'s model. If you have `confirmable` set up, you will have to provide it unless you have `config.default_confirm_success_url` set in `config/initializers/devise_token_auth.rb`. | userRegister(email: String!, password: String!, passwordConfirmation: String!, confirmUrl: String): UserRegisterPayload |
577458
sendPasswordResetWithToken | Sends an email to the provided address with a link to reset the password of the resource. First step of the most recently implemented password reset flow. | userSendPasswordResetWithToken(email: String!, redirectUrl: String!): UserSendPasswordResetWithTokenPayload |
578459
updatePasswordWithToken | Uses a `resetPasswordToken` to update the password of a resource. Second and last step of the most recently implemented password reset flow. | userSendPasswordResetWithToken(resetPasswordToken: String!, password: String!, passwordConfirmation: String!): UserUpdatePasswordWithTokenPayload |
579-
resendConfirmation **(Deprecated)** | The `UserResendConfirmationPayload` will return a `message: String!` that can be used to notify a user what to do after the instructions were sent to them | userResendConfirmation(email: String!, redirectUrl: String!): UserResendConfirmationPayload |
580460
resendConfirmationWithToken | The `UserResendConfirmationWithTokenPayload` will return a `message: String!` that can be used to notify a user what to do after the instructions were sent to them. Email will contain a link to the provided `confirmUrl` and a `confirmationToken` query param. | userResendConfirmationWithToken(email: String!, confirmUrl: String!): UserResendConfirmationWithTokenPayload |
581-
sendResetPassword **(Deprecated)** | Sends an email to the provided address with a link to reset the password of the resource. **This mutation is part of the first and soon to be deprecated password reset flow.** | userSendResetPassword(email: String!, redirectUrl: String!): UserSendResetPasswordPayload |
582-
updatePassword **(Deprecated)** | The parameter `currentPassword` is optional if you have `config.check_current_password_before_update` set to false (disabled by default) on your generated `config/initializers/devise_token_aut.rb` or if the `resource` model supports the `recoverable` Devise plugin and the `resource`'s `allow_password_change` attribute is set to true (this is done in the `userCheckPasswordToken` query when you click on the sent email's link). **This mutation is part of the first and soon to be deprecated password reset flow.** | userUpdatePassword(password: String!, passwordConfirmation: String!, currentPassword: String): UserUpdatePasswordPayload |
583-
584-
#### Queries
585-
Operation | Description | Example
586-
:--- | :--- | :------------------:
587-
confirmAccount **(Deprecated)** | Performs a redirect using the `redirectUrl` param | userConfirmAccount(confirmationToken: String!, redirectUrl: String!): User
588-
checkPasswordToken **(Deprecated)** | Performs a redirect using the `redirectUrl` param | userCheckPasswordToken(resetPasswordToken: String!, redirectUrl: String): User
589-
590-
The reason for having 2 queries is that these 2 are going to be accessed when clicking on
591-
the confirmation and reset password email urls. There is no limitation for making mutation
592-
requests using the `GET` method on the Rails side, but looks like there might be a limitation
593-
on the [Apollo Client](https://www.apollographql.com/docs/apollo-server/v1/requests/#get-requests).
594-
595-
We will continue to build better docs for the gem after this first release, but in the mean time
596-
you can use [our specs](spec/requests) to better understand how to use the gem.
597-
Also, the [dummy app](spec/dummy) used in our specs will give you
598-
a clear idea on how to configure the gem on your Rails application.
599461

600462
### Reset Password Flow
601463
This gem supports two password recovery flows. The most recently implemented is preferred and
@@ -661,6 +523,11 @@ We will continue to improve the gem and add better docs.
661523
1. Add support for unlockable and other Devise modules.
662524
1. Add feature specs for confirm account and reset password flows.
663525

526+
We will continue to build better docs for the gem after this first release, but in the mean time
527+
you can use [our specs](spec/requests) to better understand how to use the gem.
528+
Also, the [dummy app](spec/dummy) used in our specs will give you
529+
a clear idea on how to configure the gem on your Rails application.
530+
664531
## Contributing
665532

666533
Bug reports and pull requests are welcome on GitHub at https://github.com/graphql-devise/graphql_devise.

app/controllers/graphql_devise/concerns/additional_controller_methods.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ def resource_class(resource = nil)
3232
super
3333
end
3434

35-
def full_url_without_params
36-
request.base_url + request.path
37-
end
38-
3935
def set_resource_by_token(resource)
4036
set_user_by_token(resource)
4137
end

lib/graphql_devise/concerns/controller_methods.rb

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ def remove_resource
2727
controller.token = nil
2828
end
2929

30-
def request
31-
controller.request
32-
end
33-
3430
def response
3531
controller.response
3632
end
@@ -78,23 +74,6 @@ def set_auth_headers(resource)
7874
auth_headers
7975
end
8076

81-
def client_and_token(token)
82-
if Gem::Version.new(DeviseTokenAuth::VERSION) <= Gem::Version.new('1.1.0')
83-
{ client_id: token.first, token: token.last }
84-
else
85-
{ client_id: token.client, token: token.token }
86-
end
87-
end
88-
89-
def redirect_headers(token_info, redirect_header_options)
90-
controller.send(
91-
:build_redirect_headers,
92-
token_info.fetch(:token),
93-
token_info.fetch(:client_id),
94-
redirect_header_options
95-
)
96-
end
97-
9877
def find_resource(field, value)
9978
if resource_class.connection.adapter_name.downcase.include?('mysql')
10079
# fix for mysql default case insensitivity

lib/graphql_devise/model/with_email_updater.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def call
1515
@resource.assign_attributes(resource_attributes)
1616

1717
if @resource.email == email_in_database
18-
return @resource.save
18+
@resource.save
1919
elsif required_reconfirm_attributes?
2020
return false unless @resource.valid?
2121

lib/graphql_devise/mount_method/operation_sanitizer.rb

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,6 @@ def call
2525
else
2626
@default
2727
end
28-
29-
operations.each do |operation, values|
30-
next if values[:deprecation_reason].blank?
31-
32-
ActiveSupport::Deprecation.warn(<<-DEPRECATION.strip_heredoc, caller)
33-
`#{operation}` is deprecated and will be removed in a future version of this gem.
34-
#{values[:deprecation_reason]}
35-
36-
You can supress this message by skipping `#{operation}` on your ResourceLoader or the
37-
mount_graphql_devise_for method on your routes file.
38-
DEPRECATION
39-
end
4028
end
4129
end
4230
end

spec/graphql_devise/model/with_email_updater_spec.rb

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,40 @@
8989
end
9090

9191
context 'when attributes contain email' do
92-
context 'when confirm_url is used' do
92+
context 'when confirmation_url is used' do
9393
it_behaves_like 'all required arguments are provided', confirmation_url: 'https://google.com'
9494

9595
context 'when arguments hash has strings as keys' do
9696
it_behaves_like 'all required arguments are provided', 'confirmation_url' => 'https://google.com'
9797
end
98+
99+
context 'when confirmation_url is missing and no default is set' do
100+
let(:attributes) { { email: 'new@gmail.com', name: 'Updated Name' } }
101+
102+
before { allow(DeviseTokenAuth).to receive(:default_confirm_success_url).and_return(nil) }
103+
104+
it 'raises an error' do
105+
expect { updater }.to raise_error(
106+
GraphqlDevise::Error,
107+
'Method `update_with_email` requires attribute `confirmation_url` for email reconfirmation to work'
108+
)
109+
end
110+
111+
context 'when email will not change' do
112+
let(:attributes) { { email: resource.email, name: 'changed' } }
113+
114+
it 'updates name and does not raise an error' do
115+
expect do
116+
updater
117+
resource.reload
118+
end.to change(resource, :name).from(resource.name).to('changed').and(
119+
not_change(resource, :email).from(resource.email)
120+
).and(
121+
not_change(ActionMailer::Base.deliveries, :count).from(0)
122+
)
123+
end
124+
end
125+
end
98126
end
99127

100128
context 'when no confirmation url is provided is provided' do

spec/services/resource_loader_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@
3030
expect(returned).to be_a(Struct)
3131
end
3232

33+
context 'when resource is not class' do
34+
let(:resource) { 'User' }
35+
36+
it 'raises an error' do
37+
expect { loader }.to raise_error(
38+
GraphqlDevise::Error,
39+
'A class must be provided when mounting a model. String values are no longer supported.'
40+
)
41+
end
42+
end
43+
3344
context 'when mutation is nil' do
3445
let(:mutation) { nil }
3546

0 commit comments

Comments
 (0)