Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include custom scalars in GraphQL#render #108

Merged
merged 1 commit into from
Dec 4, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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