Skip to content

Commit 49d2f1b

Browse files
Merge pull request #84 from graphql-devise/improve-readme-file
Improve readme file
2 parents b8382ab + 615e0f8 commit 49d2f1b

2 files changed

Lines changed: 96 additions & 14 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
/spec/reports/
88
/tmp/
99

10+
README.md.*
11+
1012
# rspec failure tracking
1113
.rspec_status
1214
/spec/dummy/log/

README.md

Lines changed: 94 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,46 @@
55

66
GraphQL interface on top of the [Devise Token Auth](https://github.com/lynndylanhurley/devise_token_auth) (DTA) gem.
77

8+
## Table of Contents
9+
10+
<!--ts-->
11+
* [GraphqlDevise](#graphqldevise)
12+
* [Table of Contents](#table-of-contents)
13+
* [Introduction](#introduction)
14+
* [Installation](#installation)
15+
* [Usage](#usage)
16+
* [Mounting Routes manually](#mounting-routes-manually)
17+
* [Available Operations](#available-operations)
18+
* [Configuring Model](#configuring-model)
19+
* [Customizing Email Templates](#customizing-email-templates)
20+
* [I18n](#i18n)
21+
* [Authenticating Controller Actions](#authenticating-controller-actions)
22+
* [Making Requests](#making-requests)
23+
* [Mutations](#mutations)
24+
* [Queries](#queries)
25+
* [More Configuration Options](#more-configuration-options)
26+
* [Devise Token Auth Initializer](#devise-token-auth-initializer)
27+
* [Devise Initializer](#devise-initializer)
28+
* [Using Alongside Standard Devise](#using-alongside-standard-devise)
29+
* [Future Work](#future-work)
30+
* [Contributing](#contributing)
31+
* [License](#license)
32+
33+
<!-- Added by: mcelicalderon, at: Tue Apr 28 21:43:30 -05 2020 -->
34+
35+
<!--te-->
36+
37+
## Introduction
38+
This gem heavily relies on two gems, [Devise Token Auth](https://github.com/lynndylanhurley/devise_token_auth) (DTA)
39+
and [Devise](https://github.com/heartcombo/devise) which is a dependency of DTA.
40+
It provides a GraphQL interface on top of DTA which is designed to work with REST APIs. That's why
41+
things like token management, token expiration and everything up until using the actual GraphQL schema is
42+
still controlled by DTA. For that reason you will find that our generator runs these two gems generator and two
43+
initializer files are included. We'll provide more configuration details in the
44+
[configuration section](#more-configuration-options),
45+
but **we recommend you get familiar with [DTA and their docs](https://github.com/lynndylanhurley/devise_token_auth)
46+
in order to use this gem to its full potential**.
47+
848
## Installation
949

1050
Add this line to your application's Gemfile:
@@ -17,13 +57,9 @@ And then execute:
1757

1858
$ bundle
1959

20-
Or install it yourself as:
21-
22-
$ gem install graphql_devise
23-
2460
Next, you need to run the generator:
2561

26-
$ rails generate graphql_devise:install
62+
$ bundle exec rails generate graphql_devise:install
2763

2864
Graphql Devise generator will execute `Devise` and `Devise Token Auth`
2965
generators for you. These will make the required changes for the gems to
@@ -36,7 +72,7 @@ The generator accepts 2 params: `user_class` and `mount_path`. The params
3672
will be used to mount the route in `config/routes.rb`. For instance the executing:
3773

3874
```bash
39-
$ rails g graphql_devise:install Admin api/auth
75+
$ bundle exec rails g graphql_devise:install Admin api/auth
4076
```
4177

4278
Will do the following:
@@ -51,9 +87,15 @@ Will do the following:
5187
`Admin` could be any model name you are going to be using for authentication,
5288
and `api/auth` could be any mount path you would like to use for auth.
5389

90+
**Important:** Remember this gem mounts a completely separate GraphQL schema on a separate controller in the route
91+
provided by the `at` option in the `mount_graphql_devise_for` method in the `config/routes.rb` file. If no `at`
92+
option is provided, the route will be `/graphql_auth`. This has no effect on your own application schema.
93+
More on this in the next section.
94+
95+
## Usage
5496
### Mounting Routes manually
5597
Routes can be added using the initializer or manually.
56-
You can add a route like this:
98+
You can mount this gem's GraphQL auth schema in your routes file like this:
5799

58100
```ruby
59101
# config/routes.rb
@@ -157,7 +199,7 @@ end
157199
```
158200

159201
The install generator can do this for you if you specify the `user_class` option.
160-
See [Installation](#Installation) for details.
202+
See [Installation](#installation) for details.
161203
The generator will include a different module in your model, `DeviseTokenAuth::Concerns::User` which is also correct,
162204
we just made an alias on our namespace for consistency and possible extension.
163205
Generators have to be updated to generate our module.
@@ -214,10 +256,12 @@ Here is a list of the available mutations and queries assuming your mounted mode
214256
1. `userSignUp(email: String!, password: String!, passwordConfirmation: String!, confirmSuccessUrl: String): UserSignUpPayload`
215257

216258
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`.
259+
1. `userSendResetPassword(email: String!, redirectUrl: String!): UserSendReserPasswordPayload`
217260
1. `userUpdatePassword(password: String!, passwordConfirmation: String!, currentPassword: String): UserUpdatePasswordPayload`
218261

219-
The parameter `currentPassword` is optional if you have `config.check_current_password_before_update` set to false (disabled by default) or the `resource` model supports the `recoverable` Devise plugin and the `resource`'s `allow_password_change` attribute is set to true.
220-
1. `userSendResetPassword(email: String!, redirectUrl: String!): UserSendReserPasswordPayload`
262+
The parameter `currentPassword` is optional if you have `config.check_current_password_before_update` set to
263+
false (disabled by default) on your generated `config/initializers/devise_token_aut.rb` or if the `resource`
264+
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).
221265
1. `userResendConfirmation(email: String!, redirectUrl: String!): UserResendConfirmationPayload`
222266

223267
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
@@ -232,16 +276,52 @@ requests using the `GET` method on the Rails side, but looks like there might be
232276
on the [Apollo Client](https://www.apollographql.com/docs/apollo-server/v1/requests/#get-requests).
233277

234278
We will continue to build better docs for the gem after this first release, but in the mean time
235-
you can use [our specs](https://github.com/graphql-devise/graphql_devise/tree/b5985036e01ea064e43e457b4f0c8516f172471c/spec/requests) to better understand how to use the gem.
236-
Also, the [dummy app](https://github.com/graphql-devise/graphql_devise/tree/b5985036e01ea064e43e457b4f0c8516f172471c/spec/dummy) used in our specs will give you
279+
you can use [our specs](spec/requests) to better understand how to use the gem.
280+
Also, the [dummy app](spec/dummy) used in our specs will give you
237281
a clear idea on how to configure the gem on your Rails application.
238282

283+
### More Configuration Options
284+
As mentioned in the introduction there are many configurations that will change how this gem behaves. You can change
285+
this values on the initializer files generated by the installer.
286+
287+
#### Devise Token Auth Initializer
288+
The generated initializer file `config/initializers/devise_token_auth.rb` has all the available options documented
289+
as comments. You can also use
290+
**[DTA's docs](https://devise-token-auth.gitbook.io/devise-token-auth/config/initialization)** as a reference.
291+
In this section the most important configurations will be highlighted.
292+
293+
- **change_headers_on_each_request:** This configurations defaults to `true`. This means that tokens will change on
294+
each request you make, and the new values will be returned in the headers. So your client needs to handle this.
295+
Setting this to `false` will allow you to store the credentials for as long as the token life_span permits. And
296+
you can send the same credentials in each request.
297+
- **batch_request_buffer_throttle:** When change_headers_on_each_request is set to true, you might still want your
298+
credentials to be valid more than once as you might send parallel request. The duration you set here will
299+
determine how long the same credentials work after the first request is received.
300+
- **token_lifespan:** This configuration takes a duration and you can set it to a value like
301+
`1.month`, `2.weeks`, `1.hour`, etc.
302+
303+
**Note:** Remember this gem adds a layer on top of DTA, so some configurations might not apply.
304+
305+
#### Devise Initializer
306+
The generated initializer file `config/initializers/devise_token_auth.rb` has all the available options documented
307+
as comments. You can also use
308+
**[Devise's docs](https://github.com/heartcombo/devise)** as a reference.
309+
In this section the most important configurations will be highlighted.
310+
311+
- **password_length:** You can change this value to validate password length on sign up and password update
312+
(must enable the validatable module).
313+
- **mailer_sender:** Set it to a string with the sender's email address like `'support@example.com'`.
314+
- **case_insensitive_keys:** Setting a value like `[:email]` will make email field case insensitive on login, sign up, etc.
315+
- **email_regexp:** You can customize the regex that will validate the format of email addresses (must enable the validatable module).
316+
317+
**Note:** Remember this gem adds a layer on top of Devise, so some configurations might not apply.
318+
239319
### Using Alongside Standard Devise
240320
The DeviseTokenAuth gem allows experimental use of the standard Devise gem to be configured at the same time, for more
241321
information you can check [this answer here](https://github.com/lynndylanhurley/devise_token_auth/blob/2a32f18ccce15638a74e72f6cfde5cf15a808d3f/docs/faq.md#can-i-use-this-gem-alongside-standard-devise).
242322

243-
This gem supports the same and should be easier to handle email templates due to the fact we don't override standard Devise
244-
templates.
323+
This gem supports the same and should be easier to handle email templates due to the fact we don't override
324+
standard Devise templates.
245325

246326
## Future Work
247327
We will continue to improve the gem and add better docs.

0 commit comments

Comments
 (0)