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
type.coerce_result(value)
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
|