class GraphQL::Autotest::Field
Constants
- TYPE_NAME
Public Instance Methods
to_query(root: true)
click to toggle source
# File lib/graphql/autotest/field.rb, line 6 def to_query(root: true) q = _to_query if root q = <<~GRAPHQL { #{indent(q, 2)} } GRAPHQL end q end
Protected Instance Methods
sort_key()
click to toggle source
# File lib/graphql/autotest/field.rb, line 58 def sort_key [ # '__typename' is at the last name == '__typename' ? 1 : 0, # no-children field is at the first children ? 1 : 0, # alphabetical order name, ] end
Private Instance Methods
_to_query()
click to toggle source
# File lib/graphql/autotest/field.rb, line 18 def _to_query return name unless children <<~GRAPHQL #{name}#{arguments_to_query} { #{indent(children_to_query, 2)} } GRAPHQL end
arguments_to_query()
click to toggle source
# File lib/graphql/autotest/field.rb, line 34 def arguments_to_query return unless arguments return if arguments.empty? inner = arguments.map do |k, v| "#{k}: #{v}" end.join(', ') "(#{inner})" end
children_to_query()
click to toggle source
# File lib/graphql/autotest/field.rb, line 28 def children_to_query sorted_children.map do |child| child.to_query(root: false) end.join("\n") end
indent(str, n)
click to toggle source
# File lib/graphql/autotest/field.rb, line 44 def indent(str, n) str.lines(chomp: true).map do |line| if line.empty? "" else " " * n + line end end.join("\n") end
sorted_children()
click to toggle source
# File lib/graphql/autotest/field.rb, line 54 def sorted_children children.sort_by { |child| child.sort_key } end