Class: Graphiti::HashRenderer

Inherits:
Object
  • Object
show all
Defined in:
lib/graphiti/hash_renderer.rb

Instance Method Summary collapse

Constructor Details

#initialize(resource, graphql: false) ⇒ HashRenderer

Returns a new instance of HashRenderer.



134
135
136
137
# File 'lib/graphiti/hash_renderer.rb', line 134

def initialize(resource, graphql: false)
  @resource = resource
  @graphql = graphql
end

Instance Method Details

#render(options) ⇒ Object



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/graphiti/hash_renderer.rb', line 139

def render(options)
  serializers = options[:data]
  opts = options.slice(:fields, :include)
  opts[:graphql] = @graphql
  top_level_key = get_top_level_key(@resource, serializers.is_a?(Array))

  hash = {top_level_key => {}}
  nodes = get_nodes(serializers, opts)
  add_nodes(hash, top_level_key, options, nodes, @graphql)
  add_stats(hash, top_level_key, options, @graphql)
  if @graphql
    add_page_info(hash, serializers, top_level_key, options)
  end

  hash
end