Skip to content

Commit

Permalink
Minor improvements after merge
Browse files Browse the repository at this point in the history
  • Loading branch information
OlegIlyenko committed Mar 17, 2018
1 parent 27238c8 commit 29f110c
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 22 deletions.
13 changes: 5 additions & 8 deletions src/main/scala/sangria/schema/Schema.scala
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,6 @@ case class Schema[Ctx, Val](
def renderCompact(filter: SchemaFilter): String = toAst(filter).renderCompact

lazy val types: Map[String, (Int, Type with Named)] = {

def sameType(t1: Type, t2: Type): Boolean = {
val sameSangriaType = t1.getClass.getName == t2.getClass.getName

Expand All @@ -753,19 +752,17 @@ case class Schema[Ctx, Val](
}
}

def typeConflict(name: String, t1: Type, t2: Type, parentInfo: String) = {

def typeConflict(name: String, t1: Type, t2: Type, parentInfo: String) =
(t1, t2) match {
case (ot1: ObjectType[_, _], ot2: ObjectType[_, _]) {
case (ot1: ObjectType[_, _], ot2: ObjectType[_, _])
throw SchemaValidationException(Vector(ConflictingObjectTypeCaseClassViolation(name, parentInfo)))
}
case _ => {

case _
val conflictingTypes = List(t1, t2).map(_.getClass.getSimpleName)

throw SchemaValidationException(Vector(ConflictingTypeDefinitionViolation(
name, conflictingTypes, parentInfo)))
}
}
}

def updated(priority: Int, name: String, tpe: Type with Named, result: Map[String, (Int, Type with Named)], parentInfo: String) =
result get name match {
Expand Down
18 changes: 8 additions & 10 deletions src/test/scala/sangria/schema/SchemaConstraintsSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,12 @@ class SchemaConstraintsSpec extends WordSpec with Matchers {
}

"Not allow ObjectTypes with same name to be based on different case classes" in {

implicit val fooBazType = deriveObjectType[Unit, foo.Baz]()
implicit val barBazType = deriveObjectType[Unit, bar.Baz]()
implicit val fooBazType = deriveObjectType[Unit, test.foo.Baz]()
implicit val barBazType = deriveObjectType[Unit, test.bar.Baz]()

val queryType = ObjectType("Query", fields[Unit, Unit](
Field("fooBaz", OptionType(fooBazType), resolve = _ => Some(foo.Baz(1))),
Field("barBaz", barBazType, resolve = _ => bar.Baz("2", 3.0))
Field("fooBaz", OptionType(fooBazType), resolve = _ Some(test.foo.Baz(1))),
Field("barBaz", barBazType, resolve = _ test.bar.Baz("2", 3.0))
))

val error = intercept [SchemaValidationException] (Schema(queryType))
Expand All @@ -161,13 +160,12 @@ class SchemaConstraintsSpec extends WordSpec with Matchers {
}

"Allow ObjectTypes based on different case classes but with different names" in {

implicit val fooBazType = deriveObjectType[Unit, foo.Baz]()
implicit val barBazType = deriveObjectType[Unit, bar.Baz](ObjectTypeName("BazWithNewName"))
implicit val fooBazType = deriveObjectType[Unit, test.foo.Baz]()
implicit val barBazType = deriveObjectType[Unit, test.bar.Baz](ObjectTypeName("BazWithNewName"))

val queryType = ObjectType("Query", fields[Unit, Unit](
Field("fooBaz", OptionType(fooBazType), resolve = _ => Some(foo.Baz(1))),
Field("barBaz", barBazType, resolve = _ => bar.Baz("2", 3.0))
Field("fooBaz", OptionType(fooBazType), resolve = _ Some(test.foo.Baz(1))),
Field("barBaz", barBazType, resolve = _ test.bar.Baz("2", 3.0))
))

Schema(queryType) // Should not throw any SchemaValidationExceptions
Expand Down
3 changes: 0 additions & 3 deletions src/test/scala/sangria/schema/foo/Baz.scala

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package sangria.schema.bar
package test.bar

case class Baz(y: String, z: Double)
3 changes: 3 additions & 0 deletions src/test/scala/test/foo/Baz.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package test.foo

case class Baz(x: Int)

0 comments on commit 29f110c

Please sign in to comment.