Comments (4)
case d: BigDecimal
does not handle java.math.BigDecimal
?
from sangria.
They are different types. I used the following code to test this:
private case class TimestampCoercionViolation(value: String, typeName: String) extends ValueCoercionViolation(
s"Positive Long value expected, but got $value of type $typeName"
)
implicit val TimestampType: ScalarType[Long] = ScalarType[Long](
"Timestamp",
description = Some(
"The `Timestamp` scalar type represents non-fractional unsigned whole numeric values."
),
coerceOutput = valueOutput,
coerceUserInput = {
case i: Int if i >= 0 => Right(i: Long)
case i: Long if i >= 0L => Right(i)
case i: BigInt if !i.isValidLong => Left(BigLongCoercionViolation)
case i: BigInt if i >= 0 => Right(i.longValue)
case d: Double if d.isWhole && d >= 0.0 => Right(d.toLong)
case d: BigDecimal if d.isValidLong && d >= 0.0 => Right(d.longValue)
case d: java.math.BigDecimal if BigDecimal(d).isValidLong && d.longValue >= 0.0 => Right(d.longValue)
case x => Left(TimestampCoercionViolation(x.toString, x.getClass.toString))
},
coerceInput = {
case ast.IntValue(i, _, _) => Right(i: Long)
case ast.BigIntValue(i, _, _) if !i.isValidLong => Left(BigLongCoercionViolation)
case ast.BigIntValue(i, _, _) => Right(i.longValue)
case x => Left(TimestampCoercionViolation(x.toString, x.getClass.toString))
}
)
Without the java.math.BigDecimal
condition, I get the exception:
Positive Long value expected, but got 1680746052401 of type java.math.BigDecimal
from sangria.
OK. Would you have time/do you want to open a PR for that?
from sangria.
BTW, I found that in Scala 2.11, the class implicit conversion of java.math.BigDecimal
to the Scala BigDecimal
was moved to the object definition in this change replacing it with the following comment:
// There was an implicit to cut down on the wrapper noise for BigDec -> BigDecimal.
// However, this may mask introduction of surprising behavior (e.g. lack of rounding
// where one might expect it). Wrappers should be applied explicitly with an
// eye to correctness.
We are using Scala 2.13.
Yes, I think I can submit a PR to address this.
from sangria.
Related Issues (20)
- It is impossible to override an built-in scalar
- Decoding failure HOT 9
- Unnecessary implicit conversion while using experimental catseffect `AsyncValue` HOT 2
- Change context object
- Support OneOf on Input Objects HOT 1
- Website is down HOT 1
- Looking for help / maintainers
- Main documentation seems to not link to scaladoc / javadoc HOT 1
- Build a Sangria Steward
- Scala 3 Derive Macro Compiler Error HOT 9
- Scala 3: Exception returning Future values from GraphQL Endpoint HOT 1
- [scala3] sangria-relay HOT 1
- Error behavior when `name` argument to ObjectType constructor contains a space HOT 5
- `Context.arg` Wraps Optional Arguments inside another Option HOT 4
- Query/Schema validation for default values on object type field arguments not captured (ValueOfCorrectType rule) HOT 2
- Using `Option` in fields fails in the `None` case HOT 8
- `ListInputType[T]` extending `InputType[Seq[T]]` HOT 5
- support @deprecated on argument and input field HOT 1
- The custom scalars do not parse underlying model HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sangria.