Skip to content

Commit

Permalink
Include custom scalars in GraphQL#render (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
ghostdogpr authored Dec 4, 2019
1 parent 6232937 commit c60af3b
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions core/src/main/scala/caliban/Rendering.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ object Rendering {
types.flatMap {
case (_, t) =>
t.kind match {
case __TypeKind.SCALAR => None
case __TypeKind.SCALAR => t.name.flatMap(name => if (isBuiltinScalar(name)) None else Some(s"scalar $name"))
case __TypeKind.NON_NULL => None
case __TypeKind.LIST => None
case __TypeKind.UNION =>
Expand All @@ -20,8 +20,7 @@ object Rendering {
.flatMap(_.name)
.mkString(" | ")}""")
case _ =>
Some(s"""
|${renderDescription(t.description)}${renderKind(t.kind)} ${renderTypeName(t)} {
Some(s"""${renderDescription(t.description)}${renderKind(t.kind)} ${renderTypeName(t)} {
| ${t.fields(__DeprecatedArgs()).getOrElse(Nil).map(renderField).mkString("\n ")}${t.inputFields
.getOrElse(Nil)
.map(renderInputValue)
Expand All @@ -32,7 +31,7 @@ object Rendering {
.mkString("\n ")}
|}""".stripMargin)
}
}.mkString("\n")
}.mkString("\n\n")

private def renderKind(kind: __TypeKind): String =
kind match {
Expand Down Expand Up @@ -66,6 +65,9 @@ object Rendering {
case list => s"(${list.map(a => s"${a.name}: ${renderTypeName(a.`type`())}").mkString(", ")})"
}

private def isBuiltinScalar(name: String): Boolean =
name == "Int" || name == "Float" || name == "String" || name == "Boolean" || name == "ID"

private[caliban] def renderTypeName(fieldType: __Type): String =
fieldType.kind match {
case __TypeKind.NON_NULL => s"${fieldType.ofType.map(renderTypeName).getOrElse("null")}!"
Expand Down

0 comments on commit c60af3b

Please sign in to comment.