Module: GraphQL::Schema::Printer::TypeKindPrinters::ArgsPrinter
- Included in:
- DirectivePrinter, FieldPrinter
- Defined in:
- lib/graphql/schema/printer.rb
Instance Method Summary collapse
Instance Method Details
#print_args(field) ⇒ Object
88 89 90 91 |
# File 'lib/graphql/schema/printer.rb', line 88 def print_args(field) return if field.arguments.empty? "(#{field.arguments.values.map{ |arg| print_input_value(arg) }.join(", ")})" end |
#print_input_value(arg) ⇒ Object
93 94 95 96 97 98 99 100 101 |
# File 'lib/graphql/schema/printer.rb', line 93 def print_input_value(arg) if arg.default_value.nil? default_string = nil else default_string = " = #{print_value(arg.default_value, arg.type)}" end "#{arg.name}: #{arg.type.to_s}#{default_string}" end |
#print_value(value, type) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/graphql/schema/printer.rb', line 103 def print_value(value, type) case type when FLOAT_TYPE value.to_f.inspect when INT_TYPE value.to_i.inspect when BOOLEAN_TYPE (!!value).inspect when ScalarType, ID_TYPE, STRING_TYPE value.to_s.inspect when EnumType value.to_s when InputObjectType fields = value.to_h.map{ |field_name, field_value| field_type = type.input_fields.fetch(field_name.to_s).type "#{field_name}: #{print_value(field_value, field_type)}" }.join(", ") "{#{fields}}" when NonNullType print_value(value, type.of_type) when ListType "[#{value.to_a.map{ |v| print_value(v, type.of_type) }.join(", ")}]" else raise NotImplementedError, "Unexpected value type #{type.inspect}" end end |