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

Map java.util.UUID to ID instead of String #126

Merged
merged 3 commits into from
Dec 17, 2019
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion core/src/main/scala/caliban/schema/Schema.scala
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ trait GenericSchema[R] extends DerivationSchema[R] {
implicit val unitSchema: Schema[Any, Unit] = scalarSchema("Unit", None, _ => ObjectValue(Nil))
implicit val booleanSchema: Schema[Any, Boolean] = scalarSchema("Boolean", None, BooleanValue)
implicit val stringSchema: Schema[Any, String] = scalarSchema("String", None, StringValue)
implicit val uuidSchema: Schema[Any, UUID] = stringSchema.contramap(_.toString)
implicit val uuidSchema: Schema[Any, UUID] = scalarSchema("ID", None, uuid => StringValue(uuid.toString))
implicit val intSchema: Schema[Any, Int] = scalarSchema("Int", None, IntValue(_))
implicit val longSchema: Schema[Any, Long] = scalarSchema("Long", None, IntValue(_))
implicit val bigIntSchema: Schema[Any, BigInt] = scalarSchema("BigInt", None, IntValue(_))
Expand Down
9 changes: 9 additions & 0 deletions core/src/test/scala/caliban/schema/SchemaSpec.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package caliban.schema

import java.util.UUID

import scala.concurrent.Future
import caliban.introspection.adt.{ __DeprecatedArgs, __Type, __TypeKind }
import caliban.schema.SchemaSpecUtils._
Expand Down Expand Up @@ -37,6 +39,12 @@ object SchemaSpec
Types.collectTypes(introspect[Queries]).keys,
contains("BInput") && contains("CInput")
)
},
test("UUID field should be converted to ID") {
assert(
introspect[IDSchema].fields(__DeprecatedArgs()).toList.flatten.headOption.map(_.`type`()),
isSome(hasField[__Type, String]("id", _.ofType.flatMap(_.name).get, equalTo("ID")))
)
}
)
)
Expand All @@ -45,6 +53,7 @@ object SchemaSpecUtils {
case class EffectfulFieldSchema(q: Task[Int])
case class InfallibleFieldSchema(q: UIO[Int])
case class FutureFieldSchema(q: Future[Int])
case class IDSchema(id: UUID)

def introspect[Q](implicit schema: Schema[Any, Q]): __Type = schema.toType()
}
2 changes: 1 addition & 1 deletion vuepress/docs/docs/schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The table below shows how common Scala types are converted to GraphQL types.
| Float | Float |
| Double | Float |
| String | String |
| java.util.UUID | String |
| java.util.UUID | ID |
| Unit | Unit (custom scalar) |
| Long | Long (custom scalar) |
| BigInt | BigInt (custom scalar) |
Expand Down