Accept cdata number as float and forbid NaN/Inf #49
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request contains two changes related to processing of variables of the
Float
type.Accept a cdata number as value of a Float variable
It is quite usual that a floating point number is encoded using JSON, goes over HTTP, received on tarantool server, decoded from JSON and passed as a variable into the GraphQL executor.
A number out of the [-10^14+1; 10^14-1] range is decoded into Lua as cdata number1 to don't loss the precision. A JSON decoder don't know that we intend to use this value as the floating point one and chooses the conservative option: decode the value into cdata number to don't loss the precision.
In GraphQL we know that it is actually the floating point value (disregarding its representation in Lua). So it looks correct to accept a cdata number as value of a Float variable.
The similar idea was expressed in tarantool/tarantool#5933 against tarantool itself: let it accept a number without fractional part as a value suitable for the
float
field type.Forbid NaN and Infinity as a value Float type
The GraphQL specification explicitly forbids it:
http://spec.graphql.org/October2021/#sec-Float
Fixes #47
Supersedes PR #48
Footnotes
cdata<int64_t>
orcdata<uint64_t>
↩