Class: GraphQL::AssociationBatchResolver::AssociationResolver
- Inherits:
-
Schema::Resolver
- Object
- Schema::Resolver
- GraphQL::AssociationBatchResolver::AssociationResolver
- Extended by:
- Forwardable
- Defined in:
- lib/graphql/association_batch_resolver/association_resolver.rb
Class Attribute Summary collapse
-
.association ⇒ Object
Returns the value of attribute association.
-
.model ⇒ Object
Returns the value of attribute model.
-
.options ⇒ Object
Returns the value of attribute options.
Instance Attribute Summary collapse
-
#loader ⇒ Object
Returns the value of attribute loader.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(*args, loader_class: GraphQL::AssociationBatchResolver.configuration.loader, **keywargs, &block) ⇒ AssociationResolver
constructor
A new instance of AssociationResolver.
- #resolve(*args) ⇒ Object
Constructor Details
#initialize(*args, loader_class: GraphQL::AssociationBatchResolver.configuration.loader, **keywargs, &block) ⇒ AssociationResolver
Returns a new instance of AssociationResolver.
34 35 36 37 38 39 40 41 |
# File 'lib/graphql/association_batch_resolver/association_resolver.rb', line 34 def initialize(*args, loader_class: GraphQL::AssociationBatchResolver.configuration.loader, **keywargs, &block) super(*args, **keywargs, &block) initialization_arguments = [model, association] initialization_arguments << if @loader = loader_class.for(*initialization_arguments) @loader.context = context if @loader.respond_to?(:context=) end |
Class Attribute Details
.association ⇒ Object
Returns the value of attribute association.
9 10 11 |
# File 'lib/graphql/association_batch_resolver/association_resolver.rb', line 9 def association @association end |
.model ⇒ Object
Returns the value of attribute model.
9 10 11 |
# File 'lib/graphql/association_batch_resolver/association_resolver.rb', line 9 def model @model end |
.options ⇒ Object
Returns the value of attribute options.
9 10 11 |
# File 'lib/graphql/association_batch_resolver/association_resolver.rb', line 9 def @options end |
Instance Attribute Details
#loader ⇒ Object
Returns the value of attribute loader.
32 33 34 |
# File 'lib/graphql/association_batch_resolver/association_resolver.rb', line 32 def loader @loader end |
Class Method Details
.validate! ⇒ Object
11 12 13 14 |
# File 'lib/graphql/association_batch_resolver/association_resolver.rb', line 11 def validate! validate_model! validate_association! end |
.validate_association! ⇒ Object
22 23 24 25 26 |
# File 'lib/graphql/association_batch_resolver/association_resolver.rb', line 22 def validate_association! is_association = !model.reflect_on_association(association).nil? raise InvalidAssociation, "Association :#{association} does not exist on #{model}" unless is_association end |
.validate_model! ⇒ Object
16 17 18 19 20 |
# File 'lib/graphql/association_batch_resolver/association_resolver.rb', line 16 def validate_model! is_active_record_model = model < ActiveRecord::Base raise InvalidModel, "Model (#{model}) must be an ActiveRecord::Base descendant" unless is_active_record_model end |
Instance Method Details
#resolve(*args) ⇒ Object
43 44 45 46 |
# File 'lib/graphql/association_batch_resolver/association_resolver.rb', line 43 def resolve(*args) loader.args = *args loader.load(object) end |