class JsonToGraphql::Parser
Constants
- SPACES_PER_TAB
Attributes
input_hash[RW]
root[RW]
Public Class Methods
new(input_hash)
click to toggle source
# File lib/json_to_graphql/parser.rb, line 6 def initialize(input_hash) self.input_hash = input_hash self.root = Node.new(name: :root, args: {}, attrs: []) build_nodes(self.input_hash, self.root) end
Public Instance Methods
build_nodes(hash, parent_node)
click to toggle source
# File lib/json_to_graphql/parser.rb, line 12 def build_nodes(hash, parent_node) hash.each do |key, value| node = Node.new(name: key, args: value.delete('_args') || {}, attrs: value.delete('_attrs') || []) node.variables = (value.delete("_variables") || {}) if parent_node.name == :root parent_node.children << node build_nodes(value || {}, node) end end
print()
click to toggle source
# File lib/json_to_graphql/parser.rb, line 24 def print root.children.each_with_object("{\n") do |child, query| query.concat("#{child.print("", 1)}") end.concat("}") end