@@ -12,31 +12,25 @@ class Mapper
1212
1313 def mount_graphql_devise_for ( resource , options = { } )
1414 default_operations = GraphqlDevise ::DefaultOperations ::MUTATIONS . merge ( GraphqlDevise ::DefaultOperations ::QUERIES )
15+ clean_options = GraphqlDevise ::MountMethod ::OptionSanitizer . new ( options ) . call!
1516
1617 GraphqlDevise ::MountMethod ::OptionsValidator . new (
1718 [
18- GraphqlDevise ::MountMethod ::OptionValidators ::SkipOnlyValidator . new ( options : options ) ,
19+ GraphqlDevise ::MountMethod ::OptionValidators ::SkipOnlyValidator . new ( options : clean_options ) ,
1920 GraphqlDevise ::MountMethod ::OptionValidators ::ProvidedOperationsValidator . new (
20- options : options , supported_operations : default_operations
21+ options : clean_options , supported_operations : default_operations
2122 )
2223 ]
2324 ) . validate!
2425
25- custom_operations = options . fetch ( :operations , { } )
26- skipped_operations = options . fetch ( :skip , [ ] )
27- only_operations = options . fetch ( :only , [ ] )
28- additional_mutations = options . fetch ( :additional_mutations , { } )
29- additional_queries = options . fetch ( :additional_queries , { } )
30- path = options . fetch ( :at , '/graphql_auth' )
31- mapping_name = resource . underscore . tr ( '/' , '_' ) . to_sym
32- authenticatable_type = options [ :authenticatable_type ] . presence ||
26+ authenticatable_type = clean_options . authenticatable_type . presence ||
3327 "Types::#{ resource } Type" . safe_constantize ||
3428 GraphqlDevise ::Types ::AuthenticatableType
3529
3630 param_operations = {
37- custom : custom_operations ,
38- only : only_operations ,
39- skipped : skipped_operations
31+ custom : clean_options . operations ,
32+ only : clean_options . only ,
33+ skipped : clean_options . skip
4034 }
4135
4236 devise_for (
@@ -62,28 +56,30 @@ def mount_graphql_devise_for(resource, options = {})
6256 authenticatable_type : authenticatable_type
6357 )
6458
65- prepared_mutations . merge ( additional_mutations ) . each do |action , mutation |
59+ all_mutations = prepared_mutations . merge ( clean_options . additional_mutations )
60+ all_mutations . each do |action , mutation |
6661 GraphqlDevise ::Types ::MutationType . field ( action , mutation : mutation )
6762 end
6863
69- if ( prepared_mutations . present? || additional_mutations . present? ) &&
64+ if all_mutations . present? &&
7065 ( Gem ::Version . new ( GraphQL ::VERSION ) < Gem ::Version . new ( '1.10.0' ) || GraphqlDevise ::Schema . mutation . nil? )
7166 GraphqlDevise ::Schema . mutation ( GraphqlDevise ::Types ::MutationType )
7267 end
7368
74- prepared_queries . merge ( additional_queries ) . each do |action , resolver |
69+ all_queries = prepared_queries . merge ( clean_options . additional_queries )
70+ all_queries . each do |action , resolver |
7571 GraphqlDevise ::Types ::QueryType . field ( action , resolver : resolver )
7672 end
7773
78- if ( prepared_queries . blank? || additional_queries . present? ) && GraphqlDevise ::Types ::QueryType . fields . blank?
74+ if all_queries . present? && GraphqlDevise ::Types ::QueryType . fields . blank?
7975 GraphqlDevise ::Types ::QueryType . field ( :dummy , resolver : GraphqlDevise ::Resolvers ::Dummy )
8076 end
8177
8278 Devise . mailer . helper ( GraphqlDevise ::MailerHelper )
8379
84- devise_scope mapping_name do
85- post path , to : 'graphql_devise/graphql#auth'
86- get path , to : 'graphql_devise/graphql#auth'
80+ devise_scope resource . underscore . tr ( '/' , '_' ) . to_sym do
81+ post clean_options . at , to : 'graphql_devise/graphql#auth'
82+ get clean_options . at , to : 'graphql_devise/graphql#auth'
8783 end
8884 end
8985 end
0 commit comments