diff --git a/client/src/main/scala/caliban/client/ArgEncoder.scala b/client/src/main/scala/caliban/client/ArgEncoder.scala index 09819060f..6cf0a25d8 100644 --- a/client/src/main/scala/caliban/client/ArgEncoder.scala +++ b/client/src/main/scala/caliban/client/ArgEncoder.scala @@ -11,7 +11,7 @@ import scala.annotation.implicitNotFound */ @implicitNotFound( """Cannot find an ArgEncoder for type ${A}. - + Caliban needs it to know how to encode arguments of type ${A}. """ ) @@ -23,6 +23,9 @@ trait ArgEncoder[-A] { self => object ArgEncoder { + // In Scala3 there does not appear to be a short2bigDecimal implicit conversion. + implicit val short: ArgEncoder[Short] = (value: Short) => __NumberValue(value.toInt) + implicit val int: ArgEncoder[Int] = (value: Int) => __NumberValue(value) implicit val long: ArgEncoder[Long] = (value: Long) => __NumberValue(value) diff --git a/client/src/main/scala/caliban/client/ScalarDecoder.scala b/client/src/main/scala/caliban/client/ScalarDecoder.scala index 77971422f..7d2c4895d 100644 --- a/client/src/main/scala/caliban/client/ScalarDecoder.scala +++ b/client/src/main/scala/caliban/client/ScalarDecoder.scala @@ -14,7 +14,7 @@ import scala.annotation.implicitNotFound */ @implicitNotFound( """Cannot find a ScalarDecoder for type ${A}. - + Caliban needs it to know how to decode a scalar of type ${A}. """ ) @@ -23,6 +23,10 @@ trait ScalarDecoder[+A] { } object ScalarDecoder { + implicit val short: ScalarDecoder[Short] = { + case __NumberValue(value) => Right(value.toShort) + case other => Left(DecodingError(s"Can't build a Short from input $other")) + } implicit val int: ScalarDecoder[Int] = { case __NumberValue(value) => Try(value.toIntExact).toEither.left.map(ex => DecodingError(s"Can't build an Int from input $value", Some(ex))) diff --git a/core/src/main/scala/caliban/schema/Schema.scala b/core/src/main/scala/caliban/schema/Schema.scala index 8aa9f0f46..74c661063 100644 --- a/core/src/main/scala/caliban/schema/Schema.scala +++ b/core/src/main/scala/caliban/schema/Schema.scala @@ -243,6 +243,7 @@ trait GenericSchema[R] extends SchemaDerivation[R] with TemporalSchema { implicit val booleanSchema: Schema[Any, Boolean] = scalarSchema("Boolean", None, BooleanValue.apply) implicit val stringSchema: Schema[Any, String] = scalarSchema("String", None, StringValue.apply) implicit val uuidSchema: Schema[Any, UUID] = scalarSchema("ID", None, uuid => StringValue(uuid.toString)) + implicit val shortSchema: Schema[Any, Short] = scalarSchema("Short", None, IntValue(_)) 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(_))