Class: GraphQL::Hive::Printer

Inherits:
Language::Printer
  • Object
show all
Defined in:
lib/graphql-hive/printer.rb

Overview

  • removes literals

  • removes aliases

  • sort nodes and directives (files, arguments, variables)

Instance Method Summary collapse

Instance Method Details



39
40
41
42
43
44
45
46
47
# File 'lib/graphql-hive/printer.rb', line 39

def print_directive(directive)
  out = "@#{directive.name}".dup

  if directive.arguments.any?
    out << "(#{directive.arguments.sort_by(&:name).map { |a| print_argument(a) }.join(', ')})"
  end

  out
end

rubocop:enable Style/RedundantInterpolation



31
32
33
# File 'lib/graphql-hive/printer.rb', line 31

def print_directives(directives)
  super(directives.sort_by(&:name))
end

rubocop:disable Style/RedundantInterpolation



21
22
23
24
25
26
27
28
# File 'lib/graphql-hive/printer.rb', line 21

def print_field(field, indent: '')
  out = "#{indent}".dup
  out << "#{field.name}"
  out << "(#{field.arguments.sort_by(&:name).map { |a| print_argument(a) }.join(', ')})" if field.arguments.any?
  out << print_directives(field.directives)
  out << print_selections(field.selections, indent: indent)
  out
end


9
10
11
12
13
14
15
16
17
18
# File 'lib/graphql-hive/printer.rb', line 9

def print_node(node, indent: '')
  case node
  when Float, Integer
    '0'
  when String
    ''
  else
    super(node, indent: indent)
  end
end


49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/graphql-hive/printer.rb', line 49

def print_operation_definition(operation_definition, indent: '')
  out = "#{indent}#{operation_definition.operation_type}".dup
  out << " #{operation_definition.name}" if operation_definition.name

  # rubocop:disable Layout/LineLength
  if operation_definition.variables.any?
    out << "(#{operation_definition.variables.sort_by(&:name).map { |v| print_variable_definition(v) }.join(', ')})"
  end
  # rubocop:enable Layout/LineLength

  out << print_directives(operation_definition.directives)
  out << print_selections(operation_definition.selections, indent: indent)
  out
end


35
36
37
# File 'lib/graphql-hive/printer.rb', line 35

def print_selections(selections, indent: '')
  super(selections.sort_by(&:name), indent: indent)
end