Skip to content

Commit

Permalink
fix NaturalNumber user input parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
jancajthaml authored Nov 24, 2021
1 parent e74fdc6 commit 3c579f5
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@ import com.openbank.dwh.persistence._
import sangria.execution.deferred._
import sangria.ast.{BigIntValue, IntValue, StringValue}
import spray.json.{JsObject, JsValue}
import scala.math.BigInt

sealed trait Types {

protected implicit val NaturalNumberType: ScalarType[Long] = ScalarType[Long](
"NaturalNumber",
Some("Positive integer including zero"),
coerceUserInput = {
case s: Int if s >= 0 => Right(s.toLong)
case s: Long if s >= 0 => Right(s)
case _ => Left(NaturalNumberCoerceViolation)
case s: Int if s >= 0 => Right(s.toLong)
case s: Long if s >= 0 => Right(s)
case s: BigInt if s.signum >= 0 && s.isValidLong => Right(s.longValue)
case _ => Left(NaturalNumberCoerceViolation)
},
coerceOutput = (s, _) => s,
coerceInput = {
Expand Down

0 comments on commit 3c579f5

Please sign in to comment.