graphql_devise 0.12.1 → 0.13.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (168) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +7 -0
  3. data/Appraisals +14 -0
  4. data/CHANGELOG.md +60 -0
  5. data/Gemfile +2 -0
  6. data/README.md +125 -82
  7. data/Rakefile +2 -0
  8. data/app/controllers/graphql_devise/application_controller.rb +2 -0
  9. data/app/controllers/graphql_devise/concerns/set_user_by_token.rb +12 -4
  10. data/app/controllers/graphql_devise/graphql_controller.rb +2 -0
  11. data/app/helpers/graphql_devise/application_helper.rb +2 -0
  12. data/app/helpers/graphql_devise/mailer_helper.rb +2 -0
  13. data/app/models/graphql_devise/concerns/model.rb +10 -0
  14. data/app/views/graphql_devise/mailer/confirmation_instructions.html.erb +1 -1
  15. data/app/views/graphql_devise/mailer/reset_password_instructions.html.erb +1 -1
  16. data/config/routes.rb +2 -0
  17. data/graphql_devise.gemspec +1 -1
  18. data/lib/generators/graphql_devise/install_generator.rb +3 -1
  19. data/lib/graphql_devise.rb +2 -0
  20. data/lib/graphql_devise/concerns/controller_methods.rb +2 -0
  21. data/lib/graphql_devise/default_operations/mutations.rb +2 -0
  22. data/lib/graphql_devise/default_operations/resolvers.rb +2 -0
  23. data/lib/graphql_devise/engine.rb +2 -0
  24. data/lib/graphql_devise/errors/authentication_error.rb +2 -0
  25. data/lib/graphql_devise/errors/detailed_user_error.rb +2 -0
  26. data/lib/graphql_devise/errors/error_codes.rb +2 -0
  27. data/lib/graphql_devise/errors/execution_error.rb +2 -0
  28. data/lib/graphql_devise/errors/user_error.rb +2 -0
  29. data/lib/graphql_devise/model/with_email_updater.rb +74 -0
  30. data/lib/graphql_devise/mount_method/operation_preparer.rb +2 -0
  31. data/lib/graphql_devise/mount_method/operation_preparers/custom_operation_preparer.rb +2 -0
  32. data/lib/graphql_devise/mount_method/operation_preparers/default_operation_preparer.rb +2 -0
  33. data/lib/graphql_devise/mount_method/operation_preparers/gql_name_setter.rb +2 -0
  34. data/lib/graphql_devise/mount_method/operation_preparers/mutation_field_setter.rb +2 -0
  35. data/lib/graphql_devise/mount_method/operation_preparers/resolver_type_setter.rb +2 -0
  36. data/lib/graphql_devise/mount_method/operation_preparers/resource_name_setter.rb +2 -0
  37. data/lib/graphql_devise/mount_method/operation_sanitizer.rb +2 -0
  38. data/lib/graphql_devise/mount_method/option_sanitizer.rb +2 -0
  39. data/lib/graphql_devise/mount_method/option_sanitizers/array_checker.rb +2 -0
  40. data/lib/graphql_devise/mount_method/option_sanitizers/class_checker.rb +2 -0
  41. data/lib/graphql_devise/mount_method/option_sanitizers/hash_checker.rb +2 -0
  42. data/lib/graphql_devise/mount_method/option_sanitizers/string_checker.rb +2 -0
  43. data/lib/graphql_devise/mount_method/option_validators/provided_operations_validator.rb +2 -0
  44. data/lib/graphql_devise/mount_method/option_validators/skip_only_validator.rb +2 -0
  45. data/lib/graphql_devise/mount_method/option_validators/supported_operations_validator.rb +2 -0
  46. data/lib/graphql_devise/mount_method/options_validator.rb +2 -0
  47. data/lib/graphql_devise/mount_method/supported_options.rb +2 -0
  48. data/lib/graphql_devise/mutations/base.rb +2 -0
  49. data/lib/graphql_devise/mutations/login.rb +2 -0
  50. data/lib/graphql_devise/mutations/logout.rb +2 -0
  51. data/lib/graphql_devise/mutations/resend_confirmation.rb +4 -1
  52. data/lib/graphql_devise/mutations/send_password_reset.rb +4 -1
  53. data/lib/graphql_devise/mutations/sign_up.rb +13 -3
  54. data/lib/graphql_devise/mutations/update_password.rb +2 -0
  55. data/lib/graphql_devise/rails/routes.rb +2 -0
  56. data/lib/graphql_devise/resolvers/base.rb +2 -0
  57. data/lib/graphql_devise/resolvers/check_password_token.rb +2 -0
  58. data/lib/graphql_devise/resolvers/confirm_account.rb +7 -2
  59. data/lib/graphql_devise/resolvers/dummy.rb +2 -0
  60. data/lib/graphql_devise/resource_loader.rb +2 -0
  61. data/lib/graphql_devise/schema.rb +2 -0
  62. data/lib/graphql_devise/schema_plugin.rb +30 -3
  63. data/lib/graphql_devise/types/authenticatable_type.rb +2 -0
  64. data/lib/graphql_devise/types/credential_type.rb +2 -0
  65. data/lib/graphql_devise/types/mutation_type.rb +2 -0
  66. data/lib/graphql_devise/types/query_type.rb +2 -0
  67. data/lib/graphql_devise/version.rb +3 -1
  68. data/spec/dummy/Rakefile +2 -0
  69. data/spec/dummy/app/controllers/api/v1/graphql_controller.rb +35 -4
  70. data/spec/dummy/app/controllers/application_controller.rb +2 -0
  71. data/spec/dummy/app/graphql/dummy_schema.rb +14 -2
  72. data/spec/dummy/app/graphql/interpreter_schema.rb +2 -0
  73. data/spec/dummy/app/graphql/mutations/login.rb +2 -0
  74. data/spec/dummy/app/graphql/mutations/register_confirmed_user.rb +2 -0
  75. data/spec/dummy/app/graphql/mutations/sign_up.rb +2 -0
  76. data/spec/dummy/app/graphql/mutations/update_user.rb +22 -0
  77. data/spec/dummy/app/graphql/resolvers/public_user.rb +2 -0
  78. data/spec/dummy/app/graphql/resolvers/user_show.rb +2 -0
  79. data/spec/dummy/app/graphql/types/base_object.rb +2 -0
  80. data/spec/dummy/app/graphql/types/custom_admin_type.rb +2 -0
  81. data/spec/dummy/app/graphql/types/mutation_type.rb +3 -0
  82. data/spec/dummy/app/graphql/types/query_type.rb +2 -0
  83. data/spec/dummy/app/graphql/types/user_type.rb +2 -0
  84. data/spec/dummy/app/jobs/application_job.rb +2 -0
  85. data/spec/dummy/app/mailers/application_mailer.rb +2 -0
  86. data/spec/dummy/app/models/admin.rb +2 -0
  87. data/spec/dummy/app/models/application_record.rb +2 -0
  88. data/spec/dummy/app/models/guest.rb +2 -0
  89. data/spec/dummy/app/models/schema_user.rb +13 -0
  90. data/spec/dummy/app/models/user.rb +2 -0
  91. data/spec/dummy/app/models/users.rb +2 -0
  92. data/spec/dummy/app/models/users/customer.rb +2 -0
  93. data/spec/dummy/config.ru +2 -0
  94. data/spec/dummy/config/application.rb +2 -0
  95. data/spec/dummy/config/environment.rb +2 -0
  96. data/spec/dummy/config/environments/development.rb +2 -0
  97. data/spec/dummy/config/environments/production.rb +2 -0
  98. data/spec/dummy/config/environments/test.rb +2 -0
  99. data/spec/dummy/config/initializers/application_controller_renderer.rb +2 -0
  100. data/spec/dummy/config/initializers/backtrace_silencers.rb +2 -0
  101. data/spec/dummy/config/initializers/cors.rb +2 -0
  102. data/spec/dummy/config/initializers/devise_token_auth.rb +2 -0
  103. data/spec/dummy/config/initializers/filter_parameter_logging.rb +2 -0
  104. data/spec/dummy/config/initializers/i18n.rb +2 -0
  105. data/spec/dummy/config/initializers/inflections.rb +2 -0
  106. data/spec/dummy/config/initializers/mime_types.rb +2 -0
  107. data/spec/dummy/config/initializers/wrap_parameters.rb +2 -0
  108. data/spec/dummy/config/puma.rb +2 -0
  109. data/spec/dummy/config/routes.rb +4 -0
  110. data/spec/dummy/config/spring.rb +2 -0
  111. data/spec/dummy/db/migrate/20190815114303_create_users.rb +2 -0
  112. data/spec/dummy/db/migrate/20190824215150_add_auth_available_to_users.rb +2 -0
  113. data/spec/dummy/db/migrate/20190916012505_create_admins.rb +2 -0
  114. data/spec/dummy/db/migrate/20191013213045_create_guests.rb +2 -0
  115. data/spec/dummy/db/migrate/20200321121807_create_users_customers.rb +2 -0
  116. data/spec/dummy/db/migrate/20200621182414_remove_uncofirmed_email_from_admins.rb +7 -0
  117. data/spec/dummy/db/migrate/20200623003142_create_schema_users.rb +46 -0
  118. data/spec/dummy/db/schema.rb +30 -2
  119. data/spec/dummy/db/seeds.rb +2 -0
  120. data/spec/factories/admins.rb +2 -0
  121. data/spec/factories/guests.rb +2 -0
  122. data/spec/factories/schema_users.rb +13 -0
  123. data/spec/factories/users.rb +2 -0
  124. data/spec/factories/users_customers.rb +2 -0
  125. data/spec/generators/graphql_devise/install_generator_spec.rb +3 -1
  126. data/spec/graphql_devise/model/with_email_updater_spec.rb +131 -0
  127. data/spec/graphql_devise_spec.rb +2 -0
  128. data/spec/models/user_spec.rb +2 -0
  129. data/spec/rails_helper.rb +3 -0
  130. data/spec/requests/graphql_controller_spec.rb +2 -0
  131. data/spec/requests/mutations/additional_mutations_spec.rb +2 -0
  132. data/spec/requests/mutations/additional_queries_spec.rb +2 -0
  133. data/spec/requests/mutations/login_spec.rb +2 -0
  134. data/spec/requests/mutations/logout_spec.rb +2 -0
  135. data/spec/requests/mutations/resend_confirmation_spec.rb +45 -16
  136. data/spec/requests/mutations/send_password_reset_spec.rb +37 -12
  137. data/spec/requests/mutations/sign_up_spec.rb +15 -2
  138. data/spec/requests/mutations/update_password_spec.rb +2 -0
  139. data/spec/requests/queries/check_password_token_spec.rb +2 -0
  140. data/spec/requests/queries/confirm_account_spec.rb +9 -1
  141. data/spec/requests/user_controller_spec.rb +65 -7
  142. data/spec/services/mount_method/operation_preparer_spec.rb +2 -0
  143. data/spec/services/mount_method/operation_preparers/custom_operation_preparer_spec.rb +2 -0
  144. data/spec/services/mount_method/operation_preparers/default_operation_preparer_spec.rb +2 -0
  145. data/spec/services/mount_method/operation_preparers/gql_name_setter_spec.rb +2 -0
  146. data/spec/services/mount_method/operation_preparers/mutation_field_setter_spec.rb +2 -0
  147. data/spec/services/mount_method/operation_preparers/resolver_type_setter_spec.rb +2 -0
  148. data/spec/services/mount_method/operation_preparers/resource_name_setter_spec.rb +2 -0
  149. data/spec/services/mount_method/operation_sanitizer_spec.rb +2 -0
  150. data/spec/services/mount_method/option_sanitizer_spec.rb +2 -0
  151. data/spec/services/mount_method/option_sanitizers/array_checker_spec.rb +2 -0
  152. data/spec/services/mount_method/option_sanitizers/class_checker_spec.rb +2 -0
  153. data/spec/services/mount_method/option_sanitizers/hash_checker_spec.rb +2 -0
  154. data/spec/services/mount_method/option_sanitizers/string_checker_spec.rb +2 -0
  155. data/spec/services/mount_method/option_validators/provided_operations_validator_spec.rb +2 -0
  156. data/spec/services/mount_method/option_validators/skip_only_validator_spec.rb +2 -0
  157. data/spec/services/mount_method/option_validators/supported_operations_validator_spec.rb +2 -0
  158. data/spec/services/mount_method/options_validator_spec.rb +2 -0
  159. data/spec/services/resource_loader_spec.rb +2 -0
  160. data/spec/services/schema_plugin_spec.rb +2 -0
  161. data/spec/spec_helper.rb +2 -0
  162. data/spec/support/contexts/graphql_request.rb +2 -0
  163. data/spec/support/factory_bot.rb +2 -0
  164. data/spec/support/matchers/auth_headers_matcher.rb +2 -0
  165. data/spec/support/matchers/not_change_matcher.rb +2 -0
  166. data/spec/support/requests/auth_helpers.rb +2 -0
  167. data/spec/support/requests/json_helpers.rb +2 -0
  168. metadata +17 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 64f2bd00ac9c5edc119bb83326ffa996ab57a5551474887281857ef10ee7abb9
4
- data.tar.gz: a8e1b662d697f4e8f94faf41b3ccbfec9b4ae6eb295ee4ee004c80d0c2b723bb
3
+ metadata.gz: f3d25f0672c378bfd003351aa997e61fdfce123ed3b391ed5bddce60c86c4f28
4
+ data.tar.gz: 0052cc77751cf44d704cfc8c7f462c5ee1aed58c91ad7ba1e80068b085149f88
5
5
  SHA512:
6
- metadata.gz: c6be77b7524f9a3cbf17b047fc5fbedc5d2cc0158ee343bdb470fe468774d3c3c7b1b0e80f2d529d623e3e74f32bf6d61f1dd220ebc2e66d7863346cedafde25
7
- data.tar.gz: c6264ad438bfbec20b53c77bf9997e0a2a6d4ef184488f0a4830e5cad7c7f8f01112e163ec1fb0b5ed86718e488899373706245f22fc6c754280c74daec8a510
6
+ metadata.gz: 3ee604289ff30fe95a1947ee63a58c05b2a05a659657253e29ed526213bea1558d6162597daf08be56a131a0c3c3100dc2affe1b821674f493d03939ad1540ee
7
+ data.tar.gz: cd6b4af9fda08c2310e6a47d3d9db8b451031bbbf05b0f214ca71a230d248d64c65cc18a92711b46676d20f047f669d5cdcb1fe6df3a42748109ff3bfae7d709
@@ -24,6 +24,7 @@ gemfile:
24
24
  - gemfiles/rails5.2_graphql1.8.gemfile
25
25
  - gemfiles/rails5.2_graphql1.9.gemfile
26
26
  - gemfiles/rails5.2_graphql1.10.gemfile
27
+ - gemfiles/rails5.2_graphql1.11.gemfile
27
28
 
28
29
  jobs:
29
30
  include:
@@ -45,6 +46,12 @@ jobs:
45
46
  rvm: 2.6.6
46
47
  - gemfile: gemfiles/rails6.0_graphql1.10.gemfile
47
48
  rvm: 2.7.1
49
+ - gemfile: gemfiles/rails6.0_graphql1.11.gemfile
50
+ rvm: 2.5.8
51
+ - gemfile: gemfiles/rails6.0_graphql1.11.gemfile
52
+ rvm: 2.6.6
53
+ - gemfile: gemfiles/rails6.0_graphql1.11.gemfile
54
+ rvm: 2.7.1
48
55
  - gemfile: gemfiles/rails6.0_graphql_edge.gemfile
49
56
  rvm: 2.6.6
50
57
  env:
data/Appraisals CHANGED
@@ -61,6 +61,13 @@ appraise 'rails5.2-graphql1.10' do
61
61
  gem 'rspec-rails', '< 4.0'
62
62
  end
63
63
 
64
+ appraise 'rails5.2-graphql1.11' do
65
+ gem 'sqlite3', '~> 1.3.6'
66
+ gem 'rails', github: 'rails/rails', branch: '5-2-stable'
67
+ gem 'graphql', '~> 1.11.0'
68
+ gem 'rspec-rails', '< 4.0'
69
+ end
70
+
64
71
  appraise 'rails6.0-graphql1.8' do
65
72
  gem 'sqlite3', '~> 1.4'
66
73
  gem 'devise', '>= 4.7'
@@ -82,6 +89,13 @@ appraise 'rails6.0-graphql1.10' do
82
89
  gem 'graphql', '~> 1.10.0'
83
90
  end
84
91
 
92
+ appraise 'rails6.0-graphql1.11' do
93
+ gem 'sqlite3', '~> 1.4'
94
+ gem 'devise', '>= 4.7'
95
+ gem 'rails', github: 'rails/rails', branch: '6-0-stable'
96
+ gem 'graphql', '~> 1.11.0'
97
+ end
98
+
85
99
  appraise 'rails6.0-graphql_edge' do
86
100
  gem 'sqlite3', '~> 1.4'
87
101
  gem 'devise_token_auth', github: 'lynndylanhurley/devise_token_auth', branch: 'master'
@@ -1,5 +1,65 @@
1
1
  # Changelog
2
2
 
3
+ ## [v0.13.2](https://github.com/graphql-devise/graphql_devise/tree/v0.13.2) (2020-08-12)
4
+
5
+ [Full Changelog](https://github.com/graphql-devise/graphql_devise/compare/v0.13.1...v0.13.2)
6
+
7
+ **Fixed bugs:**
8
+
9
+ - Save resource after generating credentials in resource confirmation [\#125](https://github.com/graphql-devise/graphql_devise/pull/125) ([mcelicalderon](https://github.com/mcelicalderon))
10
+
11
+ ## [v0.13.1](https://github.com/graphql-devise/graphql_devise/tree/v0.13.1) (2020-07-29)
12
+
13
+ [Full Changelog](https://github.com/graphql-devise/graphql_devise/compare/v0.13.0...v0.13.1)
14
+
15
+ **Implemented enhancements:**
16
+
17
+ - Add credentials field on signUp mutation [\#122](https://github.com/graphql-devise/graphql_devise/pull/122) ([mcelicalderon](https://github.com/mcelicalderon))
18
+
19
+ **Closed issues:**
20
+
21
+ - Checking for `performed?` when mounting into your graphql schema. [\#110](https://github.com/graphql-devise/graphql_devise/issues/110)
22
+ - no query string for email reset [\#104](https://github.com/graphql-devise/graphql_devise/issues/104)
23
+
24
+ ## [v0.13.0](https://github.com/graphql-devise/graphql_devise/tree/v0.13.0) (2020-06-22)
25
+
26
+ [Full Changelog](https://github.com/graphql-devise/graphql_devise/compare/v0.12.3...v0.13.0)
27
+
28
+ **Breaking changes:**
29
+
30
+ - Fix email reconfirmation feature [\#111](https://github.com/graphql-devise/graphql_devise/pull/111) ([mcelicalderon](https://github.com/mcelicalderon))
31
+
32
+ **Implemented enhancements:**
33
+
34
+ - Add frozen string literal to all relevant files [\#114](https://github.com/graphql-devise/graphql_devise/pull/114) ([mcelicalderon](https://github.com/mcelicalderon))
35
+
36
+ **Fixed bugs:**
37
+
38
+ - CookieOverflow for Own Schema Mount [\#112](https://github.com/graphql-devise/graphql_devise/issues/112)
39
+ - Reconfirmable not setting unconfirmed\_email [\#102](https://github.com/graphql-devise/graphql_devise/issues/102)
40
+
41
+ ## [v0.12.3](https://github.com/graphql-devise/graphql_devise/tree/v0.12.3) (2020-06-19)
42
+
43
+ [Full Changelog](https://github.com/graphql-devise/graphql_devise/compare/v0.12.2...v0.12.3)
44
+
45
+ **Implemented enhancements:**
46
+
47
+ - Add support for graphql 1.11 [\#108](https://github.com/graphql-devise/graphql_devise/pull/108) ([mcelicalderon](https://github.com/mcelicalderon))
48
+
49
+ ## [v0.12.2](https://github.com/graphql-devise/graphql_devise/tree/v0.12.2) (2020-06-17)
50
+
51
+ [Full Changelog](https://github.com/graphql-devise/graphql_devise/compare/v0.12.1...v0.12.2)
52
+
53
+ **Breaking changes:**
54
+
55
+ - Fix set\_resource\_by\_token no mapping error in no eager load envs [\#107](https://github.com/graphql-devise/graphql_devise/pull/107) ([mcelicalderon](https://github.com/mcelicalderon))
56
+
57
+ **Fixed bugs:**
58
+
59
+ - Separate endpoint url for mailers even if mounting the gem in your own schema [\#105](https://github.com/graphql-devise/graphql_devise/issues/105)
60
+ - Devise mapping error [\#103](https://github.com/graphql-devise/graphql_devise/issues/103)
61
+ - Use the url where the schema is mounted in emails links [\#106](https://github.com/graphql-devise/graphql_devise/pull/106) ([00dav00](https://github.com/00dav00))
62
+
3
63
  ## [v0.12.1](https://github.com/graphql-devise/graphql_devise/tree/v0.12.1) (2020-06-12)
4
64
 
5
65
  [Full Changelog](https://github.com/graphql-devise/graphql_devise/compare/v0.12.0...v0.12.1)
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  gemspec
data/README.md CHANGED
@@ -14,19 +14,22 @@ GraphQL interface on top of the [Devise Token Auth](https://github.com/lynndylan
14
14
  * [Installation](#installation)
15
15
  * [Running the Generator](#running-the-generator)
16
16
  * [Mounting the Schema in a Separate Route](#mounting-the-schema-in-a-separate-route)
17
- * [Mounting Operations in Your Own Schema](#mounting-operations-in-your-own-schema)
18
- * [Important](#important)
17
+ * [Important](#important)
18
+ * [Mounting Operations in Your Own Schema (&gt; v0.12.0)](#mounting-operations-in-your-own-schema--v0120)
19
+ * [Important](#important-1)
19
20
  * [Usage](#usage)
20
21
  * [Mounting Auth Schema on a Separate Route](#mounting-auth-schema-on-a-separate-route)
21
22
  * [Mounting Operations Into Your Own Schema](#mounting-operations-into-your-own-schema)
22
23
  * [Available Mount Options](#available-mount-options)
23
24
  * [Available Operations](#available-operations)
24
25
  * [Configuring Model](#configuring-model)
26
+ * [Email Reconfirmation](#email-reconfirmation)
25
27
  * [Customizing Email Templates](#customizing-email-templates)
26
28
  * [I18n](#i18n)
27
29
  * [Authenticating Controller Actions](#authenticating-controller-actions)
28
30
  * [Authenticate Before Reaching Your GQL Schema](#authenticate-before-reaching-your-gql-schema)
29
31
  * [Authenticate in Your GQL Schema](#authenticate-in-your-gql-schema)
32
+ * [Important](#important-2)
30
33
  * [Making Requests](#making-requests)
31
34
  * [Mutations](#mutations)
32
35
  * [Queries](#queries)
@@ -39,20 +42,19 @@ GraphQL interface on top of the [Devise Token Auth](https://github.com/lynndylan
39
42
  * [Contributing](#contributing)
40
43
  * [License](#license)
41
44
 
42
- <!-- Added by: mcelicalderon, at: Wed Jun 10 22:10:26 -05 2020 -->
45
+ <!-- Added by: david, at: mar jul 14 08:08:02 -05 2020 -->
43
46
 
44
47
  <!--te-->
45
48
 
46
49
  ## Introduction
47
- This gem heavily relies on two gems, [Devise Token Auth](https://github.com/lynndylanhurley/devise_token_auth) (DTA)
48
- and [Devise](https://github.com/heartcombo/devise) which is a dependency of DTA.
49
- It provides a GraphQL interface on top of DTA which is designed to work with REST APIs. That's why
50
- things like token management, token expiration and everything up until using the actual GraphQL schema is
51
- still controlled by DTA. For that reason you will find that our generator runs these two gems generator and two
52
- initializer files are included. We'll provide more configuration details in the
53
- [configuration section](#more-configuration-options),
54
- but **we recommend you get familiar with [DTA and their docs](https://github.com/lynndylanhurley/devise_token_auth)
55
- in order to use this gem to its full potential**.
50
+ Graphql-Devise heavily relies on two gems:
51
+ - [Devise Token Auth](https://github.com/lynndylanhurley/devise_token_auth) (DTA)
52
+ - [Devise](https://github.com/heartcombo/devise) (which is a DTA dependency)
53
+
54
+ This gem provides a GraphQL interface on top of DTA which is designed for REST APIs. Features like token management, token expiration and everything up until using the actual GraphQL schema is still controlled by DTA. For that reason the gem's generator invokes DTA and Devise generators and creates initializer files for each one of them.
55
+
56
+ **We strongly recommend getting familiar with [DTA documentation](https://github.com/lynndylanhurley/devise_token_auth) to use this gem to its full potential**.
57
+ More configuration details available in [configuration section](#more-configuration-options)
56
58
 
57
59
  ## Installation
58
60
 
@@ -68,20 +70,21 @@ $ bundle
68
70
  ```
69
71
 
70
72
  ### Running the Generator
71
- Graphql Devise generator will execute `Devise` and `Devise Token Auth`
72
- generators for you. These will make the required changes for the gems to
73
- work correctly. All configurations for [Devise](https://github.com/plataformatec/devise) and
74
- [Devise Token Auth](https://github.com/lynndylanhurley/devise_token_auth) are available,
75
- so you can read the docs there to customize your options.
76
- Configurations are done via initializer files as usual, one per gem.
73
+ Graphql Devise generator will execute `Devise` and `Devise Token Auth` generators to setup the gems in your project. You can customize them to your needs using their initializer files(one per gem) as usual.
77
74
 
78
- #### Mounting the Schema in a Separate Route
79
75
  ```bash
80
76
  $ bundle exec rails generate graphql_devise:install
81
77
  ```
78
+ The generator accepts 2 params:
79
+ - `user_class`: Model name in which `Devise` modules will be included. This uses a `find or create` strategy. Defaults to `User`.
80
+ - `mount_path`: Path in which the dedicated graphql schema for devise will be mounted. Defaults to `/graphql_auth`.
82
81
 
83
- The generator accepts 2 params: `user_class` and `mount_path`. The params
84
- will be used to mount the route in `config/routes.rb`. For instance the executing:
82
+ The option `mount` is available starting from `v0.12.0`. This option will allow you to mount the operations in your own schema instead of a dedicated one. When this option is provided `mount_path` param is not used.
83
+
84
+ #### Mounting the Schema in a Separate Route
85
+
86
+ To configure the gem to use a separate schema, the generator will use `user_class` and `mount_path` params.
87
+ The route will be mounted in `config/routes.rb`. For instance the executing:
85
88
 
86
89
  ```bash
87
90
  $ bundle exec rails g graphql_devise:install Admin api/auth
@@ -99,32 +102,43 @@ Will do the following:
99
102
  `Admin` could be any model name you are going to be using for authentication,
100
103
  and `api/auth` could be any mount path you would like to use for auth.
101
104
 
102
- #### Mounting Operations in Your Own Schema
103
- Now you can provide to the generator an option specifying
104
- the name of your GQL schema. Doing this will skip the insertion of the mount method in the
105
- routes file and will also add our `SchemaPlugin` to the specified schema. `user_class` param is still optional (`Admin`) in the following example.
105
+ ##### Important
106
+ - Remember that by default this gem mounts a completely separate GraphQL schema on a separate controller in the route provided by the `at` option in the `mount_graphql_devise_for` method in the `config/routes.rb` file. If no `at` option is provided, the route will be `/graphql_auth`.
107
+ - Avoid passing the `--mount` option or the gem will try to use an existing schema.
108
+
109
+ #### Mounting Operations in Your Own Schema (> v0.12.0)
110
+ To configure the gem to use your own GQL schema use the `--mount` option.
111
+ For instance the executing:
106
112
 
107
113
  ```bash
108
114
  $ bundle exec rails g graphql_devise:install Admin --mount MySchema
109
115
  ```
110
116
 
111
- ### Important
112
- Remember that by default this gem mounts a completely separate GraphQL schema on a separate controller in the route
113
- provided by the `at` option in the `mount_graphql_devise_for` method in the `config/routes.rb` file. If no `at`
114
- option is provided, the route will be `/graphql_auth`.
117
+ Will do the following:
118
+ - Execute `Devise` install generator
119
+ - Execute `Devise Token Auth` install generator with `Admin` and `api/auth` as params
120
+ - Find or create `Admin` model
121
+ - Add `devise` modules to `Admin` model
122
+ - Other changes that you can find [here](https://devise-token-auth.gitbook.io/devise-token-auth/config)
123
+ - Add `SchemaPlugin` to the specified schema.
124
+
115
125
 
116
- **Starting with `v0.12.0`** you can opt-in to load this gem's queries and mutations into your
117
- own application's schema. You can actually mount a resource's auth schema in a separate route
118
- and in your app's schema at the same time, but that's probably not a common scenario. More on
119
- this in the next section.
126
+ ##### Important
127
+ - When using the `--mount` option the `mount_path` params is ignored.
128
+ - The generator will look for your schema under `app/graphql/` directory. We are expecting the name of the file is the same as the as the one passed in the mount option transformed with `underscore`. In the example, passing `MySchema`, will try to find the file `app/graphql/my_schema.rb`.
129
+ - You can actually mount a resource's auth schema in a separate route and in your app's schema at the same time, but that's probably not a common scenario.
120
130
 
121
131
  ## Usage
122
- ### Mounting Auth Schema on a Separate Route
123
- The generator can do this step for you by default. Remember now you can mount this gem's
124
- auth operations into your own schema as described in [this section](#mounting-operations-into-your-own-schema).
125
132
 
133
+ GraphqlDevise operations can be used in two ways:
134
+ - Using a [separate schema](#mounting-auth-schema-on-a-separate-route) via `mount_graphql_devise_for` helper in the routes file.
135
+ - Using [your own schema](#mounting-operations-into-your-own-schema) by adding a plugin in the class.
136
+
137
+
138
+ Creating a separate schema is the default option, the generator will do that by default.
139
+
140
+ ### Mounting Auth Schema on a Separate Route
126
141
 
127
- Routes can be added using the generator or manually.
128
142
  You can mount this gem's GraphQL auth schema in your routes file like this:
129
143
 
130
144
  ```ruby
@@ -150,11 +164,13 @@ Rails.application.routes.draw do
150
164
  )
151
165
  end
152
166
  ```
167
+ This can be done using the generator or manually.
153
168
  The second argument of the `mount_graphql_devise` method is a hash of options where you can
154
169
  customize how the queries and mutations are mounted into the schema. For a list of available
155
170
  options go [here](#available-mount-options)
156
171
 
157
172
  ### Mounting Operations Into Your Own Schema
173
+
158
174
  Starting with `v0.12.0` you can now mount the GQL operations provided by this gem into your
159
175
  app's main schema.
160
176
 
@@ -301,6 +317,44 @@ end
301
317
  The install generator can do this for you if you specify the `user_class` option.
302
318
  See [Installation](#installation) for details.
303
319
 
320
+ ### Email Reconfirmation
321
+ DTA and Devise support email reconfirmation. When the `confirmable` module is added to your
322
+ resource, an email is sent to the provided email address when the `signUp` mutation is used.
323
+ You can also use this gem so every time a user updates the `email` field, a new email gets sent
324
+ for the user to confirm the new email address. Only after clicking on the confirmation link,
325
+ the email will be updated on the database to use the new value.
326
+
327
+ In order to use this feature there are a couple of things to setup first:
328
+ 1. Make user your model includes the `:confirmable` module.
329
+ 1. Add an `unconfirmed_email` String column to your resource's table.
330
+
331
+ After that is done, you simply need to call a different update method on your resource,
332
+ `update_with_email`. This method behaves exactly the same as ActiveRecord's `update` method
333
+ if the previous steps are not performed, or if you are not updating the `email` attribute.
334
+ It is also mandatory to provide two additional attributes when email will change or an error
335
+ will be raised:
336
+
337
+ 1. `schema_url`: The full url where your GQL schema is mounted. You can get this value from the
338
+ controller available in the context of your mutations and queries like this:
339
+ ```ruby
340
+ context[:controller].full_url_without_params
341
+ ```
342
+ 1. `confirmation_success_url`: This the full url where you want users to be redirected after
343
+ the email has changed successfully (usually a front-end url). This value is mandatory
344
+ unless you have set `default_confirm_success_url` in your devise_token_auth initializer.
345
+
346
+ So, it's up to you where you require confirmation of changing emails.
347
+ [Here's an example](https://github.com/graphql-devise/graphql_devise/blob/c4dcb17e98f8d84cc5ac002c66ed98a797d3bc82/spec/dummy/app/graphql/mutations/update_user.rb#L13)
348
+ on how you might do this. And also a demonstration on the method usage:
349
+ ```ruby
350
+ user.update_with_email(
351
+ name: 'New Name',
352
+ email: 'new@domain.com',
353
+ schema_url: 'http://localhost:3000/graphql',
354
+ confirmation_success_url: 'https://google.com'
355
+ )
356
+ ```
357
+
304
358
  ### Customizing Email Templates
305
359
  The approach of this gem is a bit different from DeviseTokenAuth. We have placed our templates in `app/views/graphql_devise/mailer`,
306
360
  so if you want to change them, place yours on the same dir structure on your Rails project. You can customize these two templates:
@@ -316,11 +370,10 @@ GraphQL Devise supports locales. For example, the `graphql_devise.confirmations.
316
370
  Keep in mind that if your app uses multiple locales, you should set the `I18n.locale` accordingly. You can learn how to do this [here](https://guides.rubyonrails.org/i18n.html).
317
371
 
318
372
  ### Authenticating Controller Actions
319
- Just like with Devise or DTA, you will need to authenticate users in your controllers.
320
- For this you have two alternatives.
373
+ When mounting the operation is in you own schema instead of a dedicated one, you will need to authenticate users in your controllers, just like in DTA. There are 2 alternatives to accomplish this.
321
374
 
322
375
  #### Authenticate Before Reaching Your GQL Schema
323
- For this you need to call `authenticate_<model>!` in a before_action hook of your controller.
376
+ For this you will need to call `authenticate_<model>!` in a `before_action` controller hook.
324
377
  In our example our model is `User`, so it would look like this:
325
378
  ```ruby
326
379
  # app/controllers/my_controller.rb
@@ -331,20 +384,18 @@ class MyController < ApplicationController
331
384
  before_action :authenticate_user!
332
385
 
333
386
  def my_action
334
- render json: { current_user: current_user }
387
+ result = DummySchema.execute(params[:query], context: current_user: current_user)
388
+ render json: result unless performed?
335
389
  end
336
390
  end
337
391
  ```
338
392
 
339
- The install generator can do this for you because it executes DTA installer.
340
- See [Installation](#Installation) for details.
341
- If authentication fails for the request for whatever reason, execution of the request is halted
342
- and an error is returned in a REST format as the request never reaches your GQL schema.
393
+ The install generator can include the concern in you application controller.
394
+ If authentication fails for a request, execution will halt and a REST error will be returned since the request never reaches your GQL schema.
343
395
 
344
396
  #### Authenticate in Your GQL Schema
345
397
  For this you will need to add the `GraphqlDevise::SchemaPlugin` to your schema as described
346
- [here](#mounting-operations-into-your-own-schema) and also set the authenticated resource
347
- in a `before_action` hook.
398
+ [here](#mounting-operations-into-your-own-schema).
348
399
 
349
400
  ```ruby
350
401
  # app/controllers/my_controller.rb
@@ -352,29 +403,25 @@ in a `before_action` hook.
352
403
  class MyController < ApplicationController
353
404
  include GraphqlDevise::Concerns::SetUserByToken
354
405
 
355
- before_action -> { set_resource_by_token(:user) }
356
-
357
406
  def my_action
358
- render json: DummySchema.execute(params[:query], context: graphql_context)
407
+ result = DummySchema.execute(params[:query], context: graphql_context(:user))
408
+ render json: result unless performed?
359
409
  end
360
410
  end
361
-
362
- # @resource.to_s.underscore.tr('/', '_').to_sym
363
411
  ```
364
- The `set_resource_by_token` method receives a symbol identifying the resource you are trying
412
+ The `graphql_context` method receives a symbol identifying the resource you are trying
365
413
  to authenticate. So if you mounted the `'User'` resource, the symbol is `:user`. You can use
366
414
  this snippet to find the symbol for more complex scenarios
367
- `resource_klass.to_s.underscore.tr('/', '_').to_sym`.
415
+ `resource_klass.to_s.underscore.tr('/', '_').to_sym`. `graphql_context` can also take an
416
+ array of resources if you mounted more than one into your schema. The gem will try to
417
+ authenticate a resource for each element on the array until it finds one.
368
418
 
369
- The `graphql_context` method is simply a helper method that returns a hash like this
370
- ```ruby
371
- { current_resource: @resource, controller: self }
372
- ```
373
- These are the two values the gem needs to check if a user is authenticated and to perform
374
- other auth operations. All `set_resource_by_token` does is set the `@resource` variable if
375
- the provided authentication headers are valid. If authentication fails, resource will be `nil`
376
- and this is how `GraphqlDevise::SchemaPlugin` knows if a user is authenticated or not in
377
- each query.
419
+ Internally in your own mutations and queries a key `current_resource` will be available in
420
+ the context if a resource was successfully authenticated or `nil` otherwise.
421
+
422
+ Keep in mind that sending multiple values to the `graphql_context` method means that depending
423
+ on who makes the request, the context value `current_resource` might contain instances of the
424
+ different models you might have mounted into the schema.
378
425
 
379
426
  Please note that by using this mechanism your GQL schema will be in control of what queries are
380
427
  restricted to authenticated users and you can only do this at the root level fields of your GQL
@@ -395,32 +442,28 @@ module Types
395
442
  end
396
443
  ```
397
444
 
445
+ #### Important
446
+ 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`.
447
+
398
448
  ### Making Requests
399
449
  Here is a list of the available mutations and queries assuming your mounted model is `User`.
400
450
 
401
451
  #### Mutations
402
- 1. `userLogin(email: String!, password: String!): UserLoginPayload`
403
-
404
- This mutation has a second field by default. `credentials` can be fetched directly on the mutation return type.
405
- Credentials are still returned in the headers of the response.
406
-
407
- 1. `userLogout: UserLogoutPayload`
408
- 1. `userSignUp(email: String!, password: String!, passwordConfirmation: String!, confirmSuccessUrl: String): UserSignUpPayload`
409
-
410
- 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`.
411
- 1. `userSendResetPassword(email: String!, redirectUrl: String!): UserSendReserPasswordPayload`
412
- 1. `userUpdatePassword(password: String!, passwordConfirmation: String!, currentPassword: String): UserUpdatePasswordPayload`
413
-
414
- The parameter `currentPassword` is optional if you have `config.check_current_password_before_update` set to
415
- false (disabled by default) on your generated `config/initializers/devise_token_aut.rb` or if the `resource`
416
- 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).
417
- 1. `userResendConfirmation(email: String!, redirectUrl: String!): UserResendConfirmationPayload`
418
452
 
419
- 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
453
+ Operation | Description | Example
454
+ :--- | :--- | :------------------:
455
+ 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
456
+ logout | | userLogout: UserLogoutPayload
457
+ signUp | 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
458
+ sendResetPassword | | userSendResetPassword(email: String!, redirectUrl: String!): UserSendReserPasswordPayload
459
+ updatePassword | 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). | userUpdatePassword(password: String!, passwordConfirmation: String!, currentPassword: String): UserUpdatePasswordPayload
460
+ resendConfirmation | 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 | userResendConfirmation(email: String!, redirectUrl: String!): UserResendConfirmationPayload
420
461
 
421
462
  #### Queries
422
- 1. `userConfirmAccount(confirmationToken: String!, redirectUrl: String!): User`
423
- 1. `userCheckPasswordToken(resetPasswordToken: String!, redirectUrl: String): User`
463
+ Operation | Description | Example
464
+ :--- | :--- | :------------------:
465
+ confirmAccount | Performs a redirect using the `redirectUrl` param | userConfirmAccount(confirmationToken: String!, redirectUrl: String!): User
466
+ checkPasswordToken | Performs a redirect using the `redirectUrl` param | userCheckPasswordToken(resetPasswordToken: String!, redirectUrl: String): User
424
467
 
425
468
  The reason for having 2 queries is that these 2 are going to be accessed when clicking on
426
469
  the confirmation and reset password email urls. There is no limitation for making mutation