-
Notifications
You must be signed in to change notification settings - Fork 3
GraphQL silently cast huge cdata numbers to null #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Could you provide a more detailed description, please? Is it still relevant, by the way? |
@olegrok Friendly reminder. I don't understand the issue and have no idea how to reproduce it. I made some attempts, but can't deduce anything useful from them. diff --git a/test/integration/graphql_test.lua b/test/integration/graphql_test.lua
index 6462450..a79f17d 100644
--- a/test/integration/graphql_test.lua
+++ b/test/integration/graphql_test.lua
@@ -2147,3 +2147,60 @@ function g.test_non_finite_float()
query_schema, nil, nil, {variables = variables})
end
end
+
+function g.test_huge_cdata_number()
+ local query = [[
+ query ($x: Long!) { test(arg: $x) }
+ ]]
+
+ local function callback(_, args)
+ return args[1].value
+ end
+
+ local query_schema = {
+ ['test'] = {
+ kind = types.long.nonNull,
+ arguments = {
+ arg = types.long.nonNull,
+ },
+ resolve = callback,
+ }
+ }
+
+ -- 2^64-1
+ --[[
+ local variables = {x = 18446744073709551615ULL}
+ local res = check_request(query, query_schema, nil, nil, {variables = variables})
+ -- Raises:
+ -- > Wrong variable "x" for the Scalar "Long"
+ t.assert_type(res, 'table')
+ t.assert_equals(res.test, 18446744073709551615ULL)
+ --]]
+
+ -- 2^52-1: maximum allowed by the specification of Long.
+ --
+ -- https://github.com/tarantool/graphql/wiki/Long
+ local variables = {x = 4503599627370495ULL}
+ local res = check_request(query, query_schema, nil, nil, {variables = variables})
+ t.assert_type(res, 'table')
+ t.assert_equals(res.test, 4503599627370495ULL)
+ -- Succeeds.
+
+ -- 2^63-1: de-facto maximum.
+ --
+ -- I don't know why something out of the specification is
+ -- accepted.
+ --
+ -- OTOH, I don't know why the specification shrinks the range
+ -- to [-2^52; 2^52 - 1]. I mean, well, `number` Lua type
+ -- represents integral numbers precisely only in this
+ -- range[^1], but larger values are representable with cdata
+ -- numbers.
+ --
+ -- [^1]: [-2^53; 2^53] in fact.
+ local variables = {x = 9223372036854775807ULL}
+ local res = check_request(query, query_schema, nil, nil, {variables = variables})
+ t.assert_type(res, 'table')
+ t.assert_equals(res.test, 9223372036854775807ULL)
+ -- Succeeds.
+end (My version of the module is 0.1.4.) |
seems that the problem is in tonumber64() because for unknown reason -1ULL becomes 'uint64_t' instead of 'int64_t' also may be related to: tarantool/tarantool#4738 |
in code:
in query such field silently return
null
.The text was updated successfully, but these errors were encountered: