Skip to content

Commit

Permalink
Added tests for type extension materializer (#309)
Browse files Browse the repository at this point in the history
  • Loading branch information
OlegIlyenko committed Feb 6, 2018
1 parent 3bc11a3 commit 860c903
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/main/scala/sangria/renderer/QueryRenderer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 "")

Expand Down
10 changes: 5 additions & 5 deletions src/test/scala/sangria/renderer/QueryRendererSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
120 changes: 120 additions & 0 deletions src/test/scala/sangria/schema/AstSchemaMaterializerSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 860c903

Please sign in to comment.