Skip to content

Commit

Permalink
Merge pull request #176 from gemini-hlsw/bigdecimal-scalar
Browse files Browse the repository at this point in the history
Big decimal not taken as a scalar
  • Loading branch information
tpolecat authored Sep 30, 2021
2 parents 3c1969d + 2ccc7e1 commit 139c799
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions modules/circe/src/main/scala/circemapping.scala
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ abstract class CirceMapping[F[_]: Monad] extends Mapping[F] {
case e: EnumType if focus.isString =>
if (focus.asString.map(e.hasValue).getOrElse(false)) focus.rightIor
else mkErrorResult(s"Expected Enum ${e.name}, found ${focus.noSpaces}")
case _: ScalarType if !focus.isObject => focus.rightIor // custom Scalar; any non-object type is fine
case _ =>
mkErrorResult(s"Expected Scalar type, found $tpe for focus ${focus.noSpaces}")
}
Expand Down
7 changes: 6 additions & 1 deletion modules/circe/src/test/scala/CirceData.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ object TestCirceMapping extends CirceMapping[Id] {
array: [Int!]
object: A
numChildren: Int
bigDecimal: BigDecimal
children: [Child!]!
}
enum Choice {
Expand All @@ -48,10 +49,12 @@ object TestCirceMapping extends CirceMapping[Id] {
id: ID
bField: String
}
scalar BigDecimal
"""

val QueryType = schema.ref("Query")
val RootType = schema.ref("Root")
val BigDecimalType = schema.ref("BigDecimal")

val data =
json"""
Expand All @@ -60,6 +63,7 @@ object TestCirceMapping extends CirceMapping[Id] {
"int": 23,
"float": 1.3,
"string": "foo",
"bigDecimal": 1.2,
"id": "bar",
"array": [1, 2, 3],
"choice": "ONE",
Expand Down Expand Up @@ -88,7 +92,8 @@ object TestCirceMapping extends CirceMapping[Id] {
List(
CirceRoot("root", data),
)
)
),
LeafMapping[BigDecimal](BigDecimalType)
)

override val selectElaborator = new SelectElaborator(Map(
Expand Down
2 changes: 2 additions & 0 deletions modules/circe/src/test/scala/CirceSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ final class CirceSpec extends CatsSuite {
int
float
string
bigDecimal
id
}
}
Expand All @@ -29,6 +30,7 @@ final class CirceSpec extends CatsSuite {
"int" : 23,
"float": 1.3,
"string": "foo",
"bigDecimal": 1.2,
"id": "bar"
}
}
Expand Down

0 comments on commit 139c799

Please sign in to comment.