graphql-builder icon indicating copy to clipboard operation
graphql-builder copied to clipboard

Enforcing data types

Open dsbw opened this issue 4 years ago • 2 comments

Howdy,

I've been using this (very helpful, thank you!) library for a project where I take data from a database via graphql and then put it into a JavaFX table control, which has raised an interesting issue that I'm wondering how other people handle.

Let's say I have a database field which is some kind of floating point (double or money or whatever). It's specified as Float on the GraphQL side, but when it's a round number, like 1.0, the JSON comes in as "1" and ends up as a Long. Most of the time, this isn't a problem, but using a Long in the JavaFX table column set for Double causes a type exception.

I think my handling for this is going to be on the table side, so that it detects longs and coerces to doubles accordingly, which will work for the table but not for any other circumstance where the Long/Double discrepancy might arise.

The real issue is, I think, json/read-str, which doesn't take into account the GraphQL type (and why would it?), so I was wondering if anyone else had the problem and how they'd handled it.

dsbw avatar Feb 18 '22 18:02 dsbw

We usually wrap the request fn with additional processing if it’s needed, there’s nothing automatic unfortunately

retro avatar Feb 21 '22 22:02 retro

Oh, so it's like "I know that this field is double so I'll convert it?"

I was thinking there might be a way to query the library to say "Hey, what type is this supposed to be?"

dsbw avatar Feb 21 '22 22:02 dsbw