haskell-graphql / graphql-api

Write type-safe GraphQL services in Haskell
BSD 3-Clause "New" or "Revised" License
406 stars 35 forks source link

Support for integers bigger than Int32 #153

Closed Leonti closed 6 years ago

Leonti commented 6 years ago

Hi! I'm trying to create a handler where one of the fields is Int32: type DatePrice = Object "DatePrice" '[] '[Field "price" Int32 , Field "timestamp" Int64]

It fails because there is no Tovalue instance for Int64

maxBound for Int32 is 2147483647 so I can't use it for a timestamp. Are there some limitations not allowing to have Int64 instance? Should I use Double in this case?

P.S. Great library, by the way, really enjoying using it :)

teh commented 6 years ago

Thanks: )

While GraphQL doesn't specify a serialization format (quote):

JSON is the preferred serialization format for GraphQL, though as noted above, GraphQL does not require a specific serialization format.

JSON seems to be the most common, and JSON/JS doesn't support 64 bit ints. That's why we don't have them ATM. If you have your own serialization format would it be possible to implement ToValue for Int64 as an orphan instance? Genuine question, I can't remember whether we're exporting enough to allow that...

Leonti commented 6 years ago

Hi! Didn't know that about JSON, thanks for the info! 👍

I will try to implement my own instance later and let you know if I was able to (not sure my Haskell knowledge is good enough) :)

At the moment I'll stick with Double Thanks!