Class: GraphQL::Hive::Printer
- Inherits:
-
Language::Printer
- Object
- Language::Printer
- GraphQL::Hive::Printer
- Defined in:
- lib/graphql-hive/printer.rb
Overview
-
removes literals
-
removes aliases
-
sort nodes and directives (files, arguments, variables)
Instance Method Summary collapse
-
#print_directive(directive) ⇒ Object
from GraphQL::Language::Printer with sort_by name.
- #print_directives(directives) ⇒ Object
-
#print_field(field, indent: "") ⇒ Object
from GraphQL::Language::Printer with sort_by name ignores aliases.
- #print_node(node, indent: "") ⇒ Object
-
#print_operation_definition(operation_definition, indent: "") ⇒ Object
from GraphQL::Language::Printer with sort_by name.
-
#print_selections(selections, indent: "") ⇒ Object
from GraphQL::Language::Printer with sort_by name.
- #print_string(str) ⇒ Object
Instance Method Details
#print_directive(directive) ⇒ Object
from GraphQL::Language::Printer with sort_by name
57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/graphql-hive/printer.rb', line 57 def print_directive(directive) print_string("@") print_string(directive.name) return if directive.arguments.blank? print_string("(") directive.arguments.sort_by(&:name).each_with_index do |a, i| print_argument(a) print_string(", ") if i < directive.arguments.size - 1 end print_string(")") end |
#print_directives(directives) ⇒ Object
41 42 43 |
# File 'lib/graphql-hive/printer.rb', line 41 def print_directives(directives) super(directives.sort_by(&:name)) end |
#print_field(field, indent: "") ⇒ Object
from GraphQL::Language::Printer with sort_by name ignores aliases
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/graphql-hive/printer.rb', line 26 def print_field(field, indent: "") print_string(indent) print_string(field.name) if field.arguments.any? print_string("(") field.arguments.sort_by(&:name).each_with_index do |a, i| print_argument(a) print_string(", ") if i < field.arguments.size - 1 end print_string(")") end print_directives(field.directives) print_selections(field.selections, indent: indent) end |
#print_node(node, indent: "") ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/graphql-hive/printer.rb', line 13 def print_node(node, indent: "") case node when Float, Integer print_string "0" when String print_string "" else super end end |
#print_operation_definition(operation_definition, indent: "") ⇒ Object
from GraphQL::Language::Printer with sort_by name
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/graphql-hive/printer.rb', line 72 def print_operation_definition(operation_definition, indent: "") print_string(indent) print_string(operation_definition.operation_type) if operation_definition.name print_string(" ") print_string(operation_definition.name) end if operation_definition.variables.any? print_string("(") operation_definition.variables.sort_by(&:name).each_with_index do |v, i| print_variable_definition(v) print_string(", ") if i < operation_definition.variables.size - 1 end print_string(")") end print_directives(operation_definition.directives) print_selections(operation_definition.selections, indent: indent) end |
#print_selections(selections, indent: "") ⇒ Object
from GraphQL::Language::Printer with sort_by name
46 47 48 49 50 51 52 53 54 |
# File 'lib/graphql-hive/printer.rb', line 46 def print_selections(selections, indent: "") sorted_nodes = selections.sort_by do |s| next s.name if s.respond_to?(:name) next s.type.name if s.respond_to?(:type) raise "don't know how to sort selection node: #{s.inspect}" end super(sorted_nodes, indent: indent) end |
#print_string(str) ⇒ Object
9 10 11 |
# File 'lib/graphql-hive/printer.rb', line 9 def print_string(str) @out.append(str) end |