Class: GraphitiGraphQL::GraphitiSchema::Sideload
- Inherits:
-
Object
- Object
- GraphitiGraphQL::GraphitiSchema::Sideload
- Defined in:
- lib/graphiti_graphql/graphiti_schema/sideload.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#name ⇒ Object
Returns the value of attribute name.
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
Instance Method Summary collapse
- #child_resources ⇒ Object
- #child_resources? ⇒ Boolean
- #graphql_class_name ⇒ Object
-
#initialize(schema, config) ⇒ Sideload
constructor
A new instance of Sideload.
- #parent_resource ⇒ Object
- #remote? ⇒ Boolean
- #resource ⇒ Object
- #resource_name ⇒ Object
- #to_many? ⇒ Boolean
- #type ⇒ Object
Constructor Details
#initialize(schema, config) ⇒ Sideload
Returns a new instance of Sideload.
7 8 9 10 |
# File 'lib/graphiti_graphql/graphiti_schema/sideload.rb', line 7 def initialize(schema, config) @config = config @schema = schema end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
4 5 6 |
# File 'lib/graphiti_graphql/graphiti_schema/sideload.rb', line 4 def config @config end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/graphiti_graphql/graphiti_schema/sideload.rb', line 5 def name @name end |
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
4 5 6 |
# File 'lib/graphiti_graphql/graphiti_schema/sideload.rb', line 4 def schema @schema end |
Instance Method Details
#child_resources ⇒ Object
49 50 51 52 53 |
# File 'lib/graphiti_graphql/graphiti_schema/sideload.rb', line 49 def child_resources config[:resources].map do |name| schema.get_resource(name) end end |
#child_resources? ⇒ Boolean
45 46 47 |
# File 'lib/graphiti_graphql/graphiti_schema/sideload.rb', line 45 def child_resources? !!config[:resources] end |
#graphql_class_name ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/graphiti_graphql/graphiti_schema/sideload.rb', line 12 def graphql_class_name if type == :polymorphic_belongs_to parent_resource.graphql_class_name else resource.graphql_class_name end end |
#parent_resource ⇒ Object
41 42 43 |
# File 'lib/graphiti_graphql/graphiti_schema/sideload.rb', line 41 def parent_resource schema.get_resource(config[:parent_resource]) end |
#remote? ⇒ Boolean
36 37 38 39 |
# File 'lib/graphiti_graphql/graphiti_schema/sideload.rb', line 36 def remote? resources = child_resources? ? child_resources : [resource] resources.any?(&:remote?) end |
#resource ⇒ Object
32 33 34 |
# File 'lib/graphiti_graphql/graphiti_schema/sideload.rb', line 32 def resource schema.get_resource(resource_name) end |
#resource_name ⇒ Object
28 29 30 |
# File 'lib/graphiti_graphql/graphiti_schema/sideload.rb', line 28 def resource_name config[:resource] end |
#to_many? ⇒ Boolean
20 21 22 |
# File 'lib/graphiti_graphql/graphiti_schema/sideload.rb', line 20 def to_many? [:has_many, :many_to_many].include?(type) end |
#type ⇒ Object
24 25 26 |
# File 'lib/graphiti_graphql/graphiti_schema/sideload.rb', line 24 def type config[:type].to_sym end |