Stylianos Gakis
03/14/2023, 10:48 AMtype Money {
amount: Float!
"Currency of the money (ISO 4217)."
currencyCode: CurrencyCode!
}
If this were a scalar, I would know how to make an adapter so that in code I can always use some more apt money type (if you have suggestions here for a good Money library, only to represent it, not to do maths on the client, open to hear about it)
Since it’s just a type, it will by default generate a Kotlin object which is gonna represent amount
as a Float
. Is there a way for me to change that so I never see the amount
as a float in the first place?mbonnin
03/14/2023, 10:50 AMschema.writeText(schema.readText().replace("Money", "CustomMoney"))
and then
#extra.graphqls
scalar CustomMoney
Stylianos Gakis
03/14/2023, 10:55 AMmbonnin
03/14/2023, 10:56 AM__typename
anymoreCustomMoney
would be embedded in their parent recordStylianos Gakis
03/14/2023, 11:00 AMmbonnin
03/14/2023, 11:01 AMFloat
Float
is Kotlin Double
for some reason so it's 64 bitsStylianos Gakis
03/14/2023, 11:04 AMmbonnin
03/14/2023, 11:04 AMon the backend it is BigSomething, but then only when handed off to the clients it’s translated to Float, supposedly since the web clients had an easier time with it this way. That’s what I understood.Sounds like a reasonable approach 👍
bod
03/14/2023, 11:16 AMmbonnin
03/14/2023, 11:23 AMbod
03/14/2023, 11:24 AMmbonnin
03/14/2023, 11:25 AMbod
03/14/2023, 11:27 AMStylianos Gakis
03/14/2023, 11:30 AMBut some clients might still want to tune the displayed precision in which case Float is betterShouldn’t a client anyway be taking this Float, turning it into [Insert favorite Money type here, let’s call it CustomMoney] and use the formatter that it provides anyway, so that it will be respecting current locale etc. to know how to represent this in the UI. So whether the input to [CustomMoney] is a Float, or a String doesn’t matter for the client, since it should be able to handle both (As I understand, BigDecimal can handle both for the JVM for example) and the only thing one is doing by sending a Float over the wire is potentially losing some precision?
mbonnin
03/14/2023, 11:35 AMStylianos Gakis
03/14/2023, 11:44 AMLosing precision and also losing network bytes
So are you team String now too? 😂
mbonnin
03/14/2023, 11:45 AMStylianos Gakis
03/14/2023, 11:46 AMmbonnin
03/14/2023, 11:46 AMStylianos Gakis
03/14/2023, 11:58 AM