diff --git a/src/main/scala/sangria/marshalling/circe.scala b/src/main/scala/sangria/marshalling/circe.scala index 1425fdd..15f1ef9 100644 --- a/src/main/scala/sangria/marshalling/circe.scala +++ b/src/main/scala/sangria/marshalling/circe.scala @@ -33,6 +33,7 @@ object circe { case v: Double => Json.fromDoubleOrNull(v) case v: BigInt => Json.fromBigInt(v) case v: BigDecimal => Json.fromBigDecimal(v) + case v: Json if v.isObject => v case v => throw new IllegalArgumentException("Unsupported scalar value: " + v) } @@ -68,16 +69,22 @@ object circe { jsonNumber = num => num.toBigInt.orElse(num.toBigDecimal).getOrElse(invalidScalar), jsonString = identity, jsonArray = _ => invalidScalar, - jsonObject = _ => invalidScalar + jsonObject = jsonObject => Json.fromJsonObject(jsonObject) ) } - def getScalaScalarValue(node: Json): Any = getScalarValue(node) + import sangria.marshalling.MarshallingUtil._ + import sangria.util.tag.@@ + import sangria.marshalling.scalaMarshalling._ + + def getScalaScalarValue(node: Json): Any = + if (node.isObject) convert[Json, Any @@ ScalaInput](node) + else getScalarValue(node) def isEnumNode(node: Json): Boolean = node.isString def isScalarNode(node: Json): Boolean = - node.isBoolean || node.isNumber || node.isString + node.isBoolean || node.isNumber || node.isString || node.isObject def isVariableNode(node: Json) = false def getVariableName(node: Json) = throw new IllegalArgumentException( diff --git a/src/test/scala/sangria/marshalling/CirceSupportSpec.scala b/src/test/scala/sangria/marshalling/CirceSupportSpec.scala index cf103da..b036148 100644 --- a/src/test/scala/sangria/marshalling/CirceSupportSpec.scala +++ b/src/test/scala/sangria/marshalling/CirceSupportSpec.scala @@ -32,11 +32,6 @@ class CirceSupportSpec ) "InputUnmarshaller" should { - "throw an exception on invalid scalar values" in { - an[IllegalStateException] should be thrownBy - CirceInputUnmarshaller.getScalarValue(Json.obj()) - } - "throw an exception on variable names" in { an[IllegalArgumentException] should be thrownBy CirceInputUnmarshaller.getVariableName(Json.fromString("$foo"))