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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GraphqlDevise
2
4
  module Mutations
3
5
  class SignUp < Base
@@ -6,6 +8,11 @@ module GraphqlDevise
6
8
  argument :password_confirmation, String, required: true
7
9
  argument :confirm_success_url, String, required: false
8
10
 
11
+ field :credentials,
12
+ GraphqlDevise::Types::CredentialType,
13
+ null: true,
14
+ description: 'Authentication credentials. Null if after signUp resource is not active for authentication (e.g. Email confirmation required).'
15
+
9
16
  def resolve(confirm_success_url: nil, **attrs)
10
17
  resource = build_resource(attrs.merge(provider: provider))
11
18
  raise_user_error(I18n.t('graphql_devise.resource_build_failed')) if resource.blank?
@@ -27,13 +34,16 @@ module GraphqlDevise
27
34
  unless resource.confirmed?
28
35
  resource.send_confirmation_instructions(
29
36
  redirect_url: confirm_success_url,
30
- template_path: ['graphql_devise/mailer']
37
+ template_path: ['graphql_devise/mailer'],
38
+ schema_url: controller.full_url_without_params
31
39
  )
32
40
  end
33
41
 
34
- set_auth_headers(resource) if resource.active_for_authentication?
42
+ response_payload = { authenticatable: resource }
43
+
44
+ response_payload[:credentials] = set_auth_headers(resource) if resource.active_for_authentication?
35
45
 
36
- { authenticatable: resource }
46
+ response_payload
37
47
  else
38
48
  resource.try(:clean_up_passwords)
39
49
  raise_user_error_list(
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GraphqlDevise
2
4
  module Mutations
3
5
  class UpdatePassword < Base
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActionDispatch::Routing
2
4
  class Mapper
3
5
  def mount_graphql_devise_for(resource, options = {})
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'devise_token_auth/version'
2
4
 
3
5
  module GraphqlDevise
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GraphqlDevise
2
4
  module Resolvers
3
5
  class CheckPasswordToken < Base
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GraphqlDevise
2
4
  module Resolvers
3
5
  class ConfirmAccount < Base
@@ -13,13 +15,16 @@ module GraphqlDevise
13
15
  redirect_header_options = { account_confirmation_success: true }
14
16
 
15
17
  redirect_to_link = if controller.signed_in?(resource_name)
16
- signed_in_resource.build_auth_url(
18
+ url = resource.build_auth_url(
17
19
  redirect_url,
18
20
  redirect_headers(
19
- client_and_token(controller.signed_in_resource.create_token),
21
+ client_and_token(resource.create_token),
20
22
  redirect_header_options
21
23
  )
22
24
  )
25
+ resource.save!
26
+
27
+ url
23
28
  else
24
29
  DeviseTokenAuth::Url.generate(redirect_url, redirect_header_options)
25
30
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GraphqlDevise
2
4
  module Resolvers
3
5
  class Dummy < Base
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GraphqlDevise
2
4
  class ResourceLoader
3
5
  def initialize(resource, options = {}, routing = false)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GraphqlDevise
2
4
  class Schema < GraphQL::Schema
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GraphqlDevise
2
4
  class SchemaPlugin
3
5
  DEFAULT_NOT_AUTHENTICATED = ->(field) { raise GraphqlDevise::AuthenticationError, "#{field} field requires authentication" }
@@ -11,6 +13,7 @@ module GraphqlDevise
11
13
 
12
14
  # Must happen on initialize so operations are loaded before the types are added to the schema on GQL < 1.10
13
15
  load_fields
16
+ reconfigure_warden!
14
17
  end
15
18
 
16
19
  def use(schema_definition)
@@ -23,11 +26,12 @@ module GraphqlDevise
23
26
 
24
27
  field = traced_field(trace_data)
25
28
  provided_value = authenticate_option(field, trace_data)
29
+ context = set_current_resource(context_from_data(trace_data))
26
30
 
27
31
  if !provided_value.nil?
28
- raise_on_missing_resource(context(trace_data), field) if provided_value
32
+ raise_on_missing_resource(context, field) if provided_value
29
33
  elsif @authenticate_default
30
- raise_on_missing_resource(context(trace_data), field)
34
+ raise_on_missing_resource(context, field)
31
35
  end
32
36
 
33
37
  yield
@@ -35,11 +39,29 @@ module GraphqlDevise
35
39
 
36
40
  private
37
41
 
42
+ def set_current_resource(context)
43
+ controller = context[:controller]
44
+ resource_names = Array(context[:resource_name])
45
+ context[:current_resource] = resource_names.find do |resource_name|
46
+ unless Devise.mappings.key?(resource_name)
47
+ raise(
48
+ GraphqlDevise::Error,
49
+ "Invalid resource_name `#{resource_name}` provided to `graphql_context`. Possible values are: #{Devise.mappings.keys}."
50
+ )
51
+ end
52
+
53
+ found = controller.set_resource_by_token(resource_name)
54
+ break found if found
55
+ end
56
+
57
+ context
58
+ end
59
+
38
60
  def raise_on_missing_resource(context, field)
39
61
  @unauthenticated_proc.call(field.name) if context[:current_resource].blank?
40
62
  end
41
63
 
42
- def context(trace_data)
64
+ def context_from_data(trace_data)
43
65
  query = if trace_data[:context]
44
66
  trace_data[:context].query
45
67
  else
@@ -73,6 +95,11 @@ module GraphqlDevise
73
95
  end
74
96
  end
75
97
 
98
+ def reconfigure_warden!
99
+ Devise.class_variable_set(:@@warden_configured, nil)
100
+ Devise.configure_warden!
101
+ end
102
+
76
103
  def load_fields
77
104
  @resource_loaders.each do |resource_loader|
78
105
  raise Error, 'Invalid resource loader instance' unless resource_loader.instance_of?(GraphqlDevise::ResourceLoader)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GraphqlDevise
2
4
  module Types
3
5
  class AuthenticatableType < GraphQL::Schema::Object
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GraphqlDevise
2
4
  module Types
3
5
  class CredentialType < GraphQL::Schema::Object
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GraphqlDevise
2
4
  module Types
3
5
  class MutationType < GraphQL::Schema::Object
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GraphqlDevise
2
4
  module Types
3
5
  class QueryType < GraphQL::Schema::Object
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GraphqlDevise
2
- VERSION = '0.12.1'.freeze
4
+ VERSION = '0.13.2'.freeze
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Add your own tasks in files placed in lib/tasks ending in .rake,
2
4
  # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
5
 
@@ -1,20 +1,51 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Api
2
4
  module V1
3
5
  class GraphqlController < ApplicationController
4
6
  include GraphqlDevise::Concerns::SetUserByToken
5
7
 
6
- before_action -> { set_resource_by_token(:user) }
7
-
8
8
  def graphql
9
- render json: DummySchema.execute(params[:query], context: graphql_context)
9
+ result = DummySchema.execute(params[:query], execute_params(params))
10
+
11
+ render json: result unless performed?
10
12
  end
11
13
 
12
14
  def interpreter
13
- render json: InterpreterSchema.execute(params[:query], context: graphql_context)
15
+ render json: InterpreterSchema.execute(params[:query], execute_params(params))
16
+ end
17
+
18
+ def failing_resource_name
19
+ render json: DummySchema.execute(params[:query], context: graphql_context([:user, :fail]))
14
20
  end
15
21
 
16
22
  private
17
23
 
24
+ def execute_params(item)
25
+ {
26
+ operation_name: item[:operationName],
27
+ variables: ensure_hash(item[:variables]),
28
+ context: graphql_context([:user, :schema_user])
29
+ }
30
+ end
31
+
32
+ def ensure_hash(ambiguous_param)
33
+ case ambiguous_param
34
+ when String
35
+ if ambiguous_param.present?
36
+ ensure_hash(JSON.parse(ambiguous_param))
37
+ else
38
+ {}
39
+ end
40
+ when Hash, ActionController::Parameters
41
+ ambiguous_param
42
+ when nil
43
+ {}
44
+ else
45
+ raise ArgumentError, "Unexpected parameter: #{ambiguous_param}"
46
+ end
47
+ end
48
+
18
49
  def verify_authenticity_token
19
50
  end
20
51
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class ApplicationController < ActionController::Base
2
4
  protect_from_forgery with: :exception
3
5
  end
@@ -1,10 +1,22 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class DummySchema < GraphQL::Schema
2
4
  use GraphqlDevise::SchemaPlugin.new(
3
5
  query: Types::QueryType,
4
6
  mutation: Types::MutationType,
5
7
  resource_loaders: [
6
- GraphqlDevise::ResourceLoader.new('User', only: [:login, :confirm_account]),
7
- GraphqlDevise::ResourceLoader.new('Guest', only: [:logout])
8
+ GraphqlDevise::ResourceLoader.new(
9
+ 'User',
10
+ only: [
11
+ :login,
12
+ :confirm_account,
13
+ :send_password_reset,
14
+ :resend_confirmation,
15
+ :check_password_token
16
+ ]
17
+ ),
18
+ GraphqlDevise::ResourceLoader.new('Guest', only: [:logout]),
19
+ GraphqlDevise::ResourceLoader.new('SchemaUser')
8
20
  ]
9
21
  )
10
22
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class InterpreterSchema < GraphQL::Schema
2
4
  use GraphQL::Execution::Interpreter if Gem::Version.new(GraphQL::VERSION) >= Gem::Version.new('1.9.0')
3
5
  use GraphQL::Analysis::AST if Gem::Version.new(GraphQL::VERSION) >= Gem::Version.new('1.10.0')
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Mutations
2
4
  class Login < GraphqlDevise::Mutations::Login
3
5
  field :user, Types::UserType, null: true
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Mutations
2
4
  class RegisterConfirmedUser < GraphqlDevise::Mutations::Base
3
5
  argument :email, String, required: true
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Mutations
2
4
  class SignUp < GraphqlDevise::Mutations::SignUp
3
5
  argument :name, String, required: false
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mutations
4
+ class UpdateUser < GraphQL::Schema::Mutation
5
+ field :user, Types::UserType, null: false
6
+
7
+ argument :email, String, required: false
8
+ argument :name, String, required: false
9
+
10
+ def resolve(**attrs)
11
+ user = context[:current_resource]
12
+
13
+ schema_url = context[:controller].full_url_without_params
14
+
15
+ user.update_with_email(
16
+ attrs.merge(schema_url: schema_url, confirmation_success_url: 'https://google.com')
17
+ )
18
+
19
+ { user: user }
20
+ end
21
+ end
22
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Resolvers
2
4
  class PublicUser < GraphQL::Schema::Resolver
3
5
  type Types::UserType, null: false
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Resolvers
2
4
  class UserShow < GraphQL::Schema::Resolver
3
5
  type Types::UserType, null: false
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Types
2
4
  class BaseObject < GraphQL::Schema::Object
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Types
2
4
  class CustomAdminType < GraphQL::Schema::Object
3
5
  field :email, String, null: false
@@ -1,6 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Types
2
4
  class MutationType < Types::BaseObject
3
5
  field :dummy_mutation, String, null: false, authenticate: true
6
+ field :update_user, mutation: Mutations::UpdateUser
4
7
 
5
8
  def dummy_mutation
6
9
  'Necessary so GraphQL gem does not complain about empty mutation type'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Types
2
4
  class QueryType < Types::BaseObject
3
5
  field :user, resolver: Resolvers::UserShow
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Types
2
4
  class UserType < GraphQL::Schema::Object
3
5
  field :id, Int, null: false
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class ApplicationJob < ActiveJob::Base
2
4
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class ApplicationMailer < ActionMailer::Base
2
4
  default from: 'from@example.com'
3
5
  layout 'mailer'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Admin < ApplicationRecord
2
4
  devise :database_authenticatable,
3
5
  :registerable,
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class ApplicationRecord < ActiveRecord::Base
2
4
  self.abstract_class = true
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Guest < ApplicationRecord
2
4
  devise :database_authenticatable,
3
5
  :registerable,