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

Is there a reason graphql floats do not support Infinity and NaN?

Open dopry opened this issue 1 year ago • 3 comments

Is there a reason graphql floats do not support Infinity and NaN? Would a proposal to add infinity and/or NaN be seriously considered?

dopry avatar Dec 14 '23 22:12 dopry

Those values are hard to serialise, e.g. they don’t serialise in JSON. GraphQL aims for maximal compatibility and this excludes these kinds of things. However you could create your own custom scalar e.g. IEEE754Float which maybe encodes these special values as a string?

benjie avatar Dec 15 '23 08:12 benjie

So if JSON supported serializing +/-Infinity and NaN then this would be something that could be considered?

dopry avatar Dec 19 '23 19:12 dopry

https://stackoverflow.com/questions/1423081/json-left-out-infinity-and-nan-json-status-in-ecmascript has some insight into Infinity and NaN in JSON.

dopry avatar Dec 19 '23 19:12 dopry