Description
According to the spec (https://facebook.github.io/graphql/#sec-Scalars):
Since some common serializations (ex. JSON) do not discriminate between integer and floating‐point values, they are interpreted as an integer input value if they have an empty fractional part (ex. 1.0) and otherwise as floating‐point input value.
Based on this description, when I define a value in JSON for a variable of an Int
type:
-
123.0
must be considered a valid value and coerce to123
-
123.456
must be considered an invalid value and should result in error based onInt
input value coercion rules (https://facebook.github.io/graphql/#sec-Int):When expected as an input type, only integer input values are accepted. All other input values, including strings with numeric content, must raise a query error indicating an incorrect type.
Do I understand it correctly?
I discovered that reference implementation allows 123.456
value for a variable of Int
type which does not comply to the mentioned parts of the spec. Here is the line that successfully drops fraction digits:
https://github.com/graphql/graphql-js/blob/master/src/type/scalars.js#L30