spec/graphql/schema/printer_spec.rb in graphql-1.8.0.pre7 vs spec/graphql/schema/printer_spec.rb in graphql-1.8.0.pre8
- old
+ new
@@ -627,9 +627,43 @@
title: String!
}
SCHEMA
assert_equal expected.chomp, GraphQL::Schema::Printer.new(schema).print_type(schema.types['Post'])
end
+
+ it "can print arguments that use non-standard Ruby objects as default values" do
+ backing_object = Struct.new(:value)
+
+ scalar_type = GraphQL::ScalarType.define do
+ name "SomeType"
+ coerce_input ->(value, ctx) { backing_object.new(value) }
+ coerce_result ->(obj, ctx) { obj.value }
+ end
+
+ query_root = GraphQL::ObjectType.define do
+ name "Query"
+ description "The query root of this schema"
+
+ field :example do
+ type scalar_type
+ argument :input, scalar_type, default_value: backing_object.new("Howdy")
+ resolve ->(obj, args, ctx) { args[:input] }
+ end
+ end
+
+ schema = GraphQL::Schema.define do
+ query query_root
+ end
+
+ expected = <<SCHEMA
+# The query root of this schema
+type Query {
+ example(input: SomeType = "Howdy"): SomeType
+}
+SCHEMA
+
+ assert_equal expected.chomp, GraphQL::Schema::Printer.new(schema).print_type(query_root)
+ end
end
describe "#print_directive" do
it "prints the deprecation reason in a single line escaped string including line breaks" do
expected = <<SCHEMA