Class: GraphitiGraphQL::GraphitiSchema::Sideload

Inherits:
Object
  • Object
show all
Defined in:
lib/graphiti_graphql/graphiti_schema/sideload.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#configObject (readonly)

Returns the value of attribute config.



4
5
6
# File 'lib/graphiti_graphql/graphiti_schema/sideload.rb', line 4

def config
  @config
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/graphiti_graphql/graphiti_schema/sideload.rb', line 5

def name
  @name
end

#schemaObject (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_resourcesObject



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

Returns:

  • (Boolean)


45
46
47
# File 'lib/graphiti_graphql/graphiti_schema/sideload.rb', line 45

def child_resources?
  !!config[:resources]
end

#graphql_class_nameObject



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_resourceObject



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

Returns:

  • (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

#resourceObject



32
33
34
# File 'lib/graphiti_graphql/graphiti_schema/sideload.rb', line 32

def resource
  schema.get_resource(resource_name)
end

#resource_nameObject



28
29
30
# File 'lib/graphiti_graphql/graphiti_schema/sideload.rb', line 28

def resource_name
  config[:resource]
end

#to_many?Boolean

Returns:

  • (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

#typeObject



24
25
26
# File 'lib/graphiti_graphql/graphiti_schema/sideload.rb', line 24

def type
  config[:type].to_sym
end