@@ -10,20 +10,20 @@ def initialize(resource, options = {}, routing = false)
1010 end
1111
1212 def call ( query , mutation )
13- mapping_name = GraphqlDevise . to_mapping_name ( @resource ) . to_sym
14-
1513 # clean_options responds to all keys defined in GraphqlDevise::MountMethod::SUPPORTED_OPTIONS
1614 clean_options = GraphqlDevise ::MountMethod ::OptionSanitizer . new ( @options ) . call!
1715
18- return clean_options if GraphqlDevise . resource_mounted? ( mapping_name ) && @routing
16+ model = @resource . is_a? ( String ) ? @resource . constantize : @resource
17+
18+ return clean_options if GraphqlDevise . resource_mounted? ( model ) && @routing
1919
2020 validate_options! ( clean_options )
2121
2222 authenticatable_type = clean_options . authenticatable_type . presence ||
2323 "Types::#{ @resource } Type" . safe_constantize ||
2424 GraphqlDevise ::Types ::AuthenticatableType
2525
26- prepared_mutations = prepare_mutations ( mapping_name , clean_options , authenticatable_type )
26+ prepared_mutations = prepare_mutations ( model , clean_options , authenticatable_type )
2727
2828 if prepared_mutations . any? && mutation . blank?
2929 raise GraphqlDevise ::Error , 'You need to provide a mutation type unless all mutations are skipped'
@@ -33,7 +33,7 @@ def call(query, mutation)
3333 mutation . field ( action , mutation : prepared_mutation , authenticate : false )
3434 end
3535
36- prepared_resolvers = prepare_resolvers ( mapping_name , clean_options , authenticatable_type )
36+ prepared_resolvers = prepare_resolvers ( model , clean_options , authenticatable_type )
3737
3838 if prepared_resolvers . any? && query . blank?
3939 raise GraphqlDevise ::Error , 'You need to provide a query type unless all queries are skipped'
@@ -43,17 +43,18 @@ def call(query, mutation)
4343 query . field ( action , resolver : resolver , authenticate : false )
4444 end
4545
46- GraphqlDevise . add_mapping ( mapping_name , @resource )
47- GraphqlDevise . mount_resource ( mapping_name ) if @routing
46+ GraphqlDevise . configure_warden_serializer_for_model ( model )
47+ GraphqlDevise . add_mapping ( GraphqlDevise . to_mapping_name ( @resource ) . to_sym , @resource )
48+ GraphqlDevise . mount_resource ( model ) if @routing
4849
4950 clean_options
5051 end
5152
5253 private
5354
54- def prepare_resolvers ( mapping_name , clean_options , authenticatable_type )
55+ def prepare_resolvers ( model , clean_options , authenticatable_type )
5556 GraphqlDevise ::MountMethod ::OperationPreparer . new (
56- mapping_name : mapping_name ,
57+ model : model ,
5758 custom : clean_options . operations ,
5859 additional_operations : clean_options . additional_queries ,
5960 preparer : GraphqlDevise ::MountMethod ::OperationPreparers ::ResolverTypeSetter . new ( authenticatable_type ) ,
@@ -63,9 +64,9 @@ def prepare_resolvers(mapping_name, clean_options, authenticatable_type)
6364 ) . call
6465 end
6566
66- def prepare_mutations ( mapping_name , clean_options , authenticatable_type )
67+ def prepare_mutations ( model , clean_options , authenticatable_type )
6768 GraphqlDevise ::MountMethod ::OperationPreparer . new (
68- mapping_name : mapping_name ,
69+ model : model ,
6970 custom : clean_options . operations ,
7071 additional_operations : clean_options . additional_mutations ,
7172 preparer : GraphqlDevise ::MountMethod ::OperationPreparers ::MutationFieldSetter . new ( authenticatable_type ) ,
0 commit comments