diff --git a/src/main/scala/sangria/renderer/QueryRenderer.scala b/src/main/scala/sangria/renderer/QueryRenderer.scala index b6679e6d..6683819d 100644 --- a/src/main/scala/sangria/renderer/QueryRenderer.scala +++ b/src/main/scala/sangria/renderer/QueryRenderer.scala @@ -141,7 +141,7 @@ object QueryRenderer { } else "" def renderDirs(dirs: Vector[Directive], config: QueryRendererConfig, indent: Indent, frontSep: Boolean = false, withSep: Boolean = true) = - (if (dirs.nonEmpty && frontSep && withSep) config.mandatorySeparator else "") + + (if (dirs.nonEmpty && frontSep && withSep) config.separator else "") + (dirs map (renderNode(_, config, indent.zero)) mkString config.separator) + (if (dirs.nonEmpty && !frontSep && withSep) config.separator else "") diff --git a/src/test/scala/sangria/renderer/QueryRendererSpec.scala b/src/test/scala/sangria/renderer/QueryRendererSpec.scala index 6d04bb65..9c32b840 100644 --- a/src/test/scala/sangria/renderer/QueryRendererSpec.scala +++ b/src/test/scala/sangria/renderer/QueryRendererSpec.scala @@ -673,8 +673,8 @@ class QueryRendererSpec extends WordSpec with Matchers with StringMatchers { |scalar AnnotatedScalar@onScalar |enum Site{"description 1" DESKTOP "description 2" MOBILE} |enum AnnotatedEnum@onEnum{ANNOTATED_VALUE@onEnumValue OTHER_VALUE} - |input InputType {key:String! answer:Int=42} - |input AnnotatedInput @onInputObjectType{annotatedField:Type@onField} + |input InputType{key:String! answer:Int=42} + |input AnnotatedInput@onInputObjectType{annotatedField:Type@onField} |extend type Foo {seven(argument:[String]):Type} |extend type Foo @onType |"cool skip" directive@skip(if:Boolean!)on FIELD|FRAGMENT_SPREAD|INLINE_FRAGMENT @@ -816,11 +816,11 @@ class QueryRendererSpec extends WordSpec with Matchers with StringMatchers { |scalar AnnotatedScalar@onScalar |enum Site{DESKTOP MOBILE} |enum AnnotatedEnum@onEnum{ANNOTATED_VALUE@onEnumValue OTHER_VALUE} - |input InputType {key:String! answer:Int=42} - |input AnnotatedInput @onInputObjectType{annotatedField:Type@onField key:String! answer:Int=42@foo(bar:baz)} + |input InputType{key:String! answer:Int=42} + |input AnnotatedInput@onInputObjectType{annotatedField:Type@onField key:String! answer:Int=42@foo(bar:baz)} |extend type Foo {seven(argument:[String]):Type} |directive@skip(if:Boolean!)on FIELD|FRAGMENT_SPREAD|INLINE_FRAGMENT - |schema@myDir(a:b)@another(a:b,c:1234.45){query:QueryType mutation:MutationType}""".stripMargin) (after being strippedOfCarriageReturns) + |schema@myDir(a:b)@another(a:b,c:1234.45){query:QueryType mutation:MutationType}""".stripMargin) (after being strippedOfCarriageReturns) prettyRendered should equal ( """# fdwfsdfsdfsd diff --git a/src/test/scala/sangria/schema/AstSchemaMaterializerSpec.scala b/src/test/scala/sangria/schema/AstSchemaMaterializerSpec.scala index de02778c..5624aef6 100644 --- a/src/test/scala/sangria/schema/AstSchemaMaterializerSpec.scala +++ b/src/test/scala/sangria/schema/AstSchemaMaterializerSpec.scala @@ -1058,6 +1058,126 @@ class AstSchemaMaterializerSpec extends WordSpec with Matchers with FutureResult field.arguments(0).description should be (Some("first arg")) field.arguments(1).description should be (Some("secnd arg\nline 2")) } + + "support type extensions" in { + val schemaDef = + """ + schema { + query: Query + } + + "My super query!" + type Query + + input Complex { + name: String = "test" + } + + enum Color { + Red, Green + } + + interface Cool + + interface Versioned { + id: ID! + } + + union Pet @noTypesHere + + extend type Query implements Cool @coolDir { + # not a description! + field1( + "first arg" + arg1: Int = 101, + arg2: String! + ): String + } + + extend type Query implements Versioned @hello { + id: ID! + version: Long! + field2(a: Complex): Int + } + + extend input Complex @advanced { + color: Color = Blue + } + + extend enum Color @extra(id: 123) { + "forgot" + Blue + } + + extend interface Versioned @test { + version: Long! + } + + extend interface Cool { + field1(arg1: Int = 101, arg2: String!): String + pet: Pet + } + + type Dog {name: String} + type Cat {cute: Boolean, size: PositiveInt!} + + extend union Pet @yay = Dog | Cat + + extend scalar PositiveInt @intConstraint(min: 0) + scalar PositiveInt + """ + + val schema = Schema.buildFromAst(QueryParser.parse(schemaDef)) + + ("\n" + schema.renderPretty + "\n") should equal(""" + |type Cat { + | cute: Boolean + | size: PositiveInt! + |} + | + |enum Color @extra(id: 123) { + | Red + | Green + | + | "forgot" + | Blue + |} + | + |input Complex @advanced { + | name: String = "test" + | color: Color = Blue + |} + | + |interface Cool { + | field1(arg1: Int = 101, arg2: String!): String + | pet: Pet + |} + | + |type Dog { + | name: String + |} + | + |union Pet @noTypesHere @yay = Dog | Cat + | + |scalar PositiveInt @intConstraint(min: 0) + | + |"My super query!" + |type Query implements Cool & Versioned @coolDir @hello { + | field1( + | "first arg" + | arg1: Int = 101, arg2: String!): String + | id: ID! + | version: Long! + | field2(a: Complex): Int + | pet: Pet + |} + | + |interface Versioned @test { + | id: ID! + | version: Long! + |} + |""".stripMargin) (after being strippedOfCarriageReturns) + } } "Execution" should {