Class: GraphqlDevise::ResourceLoader
- Inherits:
-
Object
- Object
- GraphqlDevise::ResourceLoader
- Defined in:
- lib/graphql_devise/resource_loader.rb
Instance Method Summary collapse
- #call(query, mutation) ⇒ Object
-
#initialize(resource, options = {}, routing = false) ⇒ ResourceLoader
constructor
A new instance of ResourceLoader.
Constructor Details
#initialize(resource, options = {}, routing = false) ⇒ ResourceLoader
Returns a new instance of ResourceLoader.
5 6 7 8 9 10 |
# File 'lib/graphql_devise/resource_loader.rb', line 5 def initialize(resource, = {}, routing = false) @resource = resource = @routing = routing @default_operations = GraphqlDevise::DefaultOperations::MUTATIONS.merge(GraphqlDevise::DefaultOperations::QUERIES) end |
Instance Method Details
#call(query, mutation) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/graphql_devise/resource_loader.rb', line 12 def call(query, mutation) mapping_name = @resource.to_s.underscore.tr('/', '_').to_sym # clean_options responds to all keys defined in GraphqlDevise::MountMethod::SUPPORTED_OPTIONS = GraphqlDevise::MountMethod::OptionSanitizer.new().call! return if GraphqlDevise.resource_mounted?(mapping_name) && @routing () authenticatable_type = .authenticatable_type.presence || "Types::#{@resource}Type".safe_constantize || GraphqlDevise::Types::AuthenticatableType prepared_mutations = prepare_mutations(mapping_name, , authenticatable_type) if prepared_mutations.any? && mutation.blank? raise GraphqlDevise::Error, 'You need to provide a mutation type unless all mutations are skipped' end prepared_mutations.each do |action, prepared_mutation| mutation.field(action, mutation: prepared_mutation, authenticate: false) end prepared_resolvers = prepare_resolvers(mapping_name, , authenticatable_type) if prepared_resolvers.any? && query.blank? raise GraphqlDevise::Error, 'You need to provide a query type unless all queries are skipped' end prepared_resolvers.each do |action, resolver| query.field(action, resolver: resolver, authenticate: false) end GraphqlDevise.add_mapping(mapping_name, @resource) GraphqlDevise.mount_resource(mapping_name) if @routing end |