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

feat!: make json object a scalar #56

Closed
Closed
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
13 changes: 10 additions & 3 deletions src/main/scala/sangria/marshalling/circe.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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(
Expand Down
5 changes: 0 additions & 5 deletions src/test/scala/sangria/marshalling/CirceSupportSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down