Skip to content

Add support of returning gaped arrays for kind=types.list() #57

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

Closed
no1seman opened this issue Apr 19, 2022 · 0 comments · Fixed by #58
Closed

Add support of returning gaped arrays for kind=types.list() #57

no1seman opened this issue Apr 19, 2022 · 0 comments · Fixed by #58
Assignees

Comments

@no1seman
Copy link

no1seman commented Apr 19, 2022

Image user have the following space format:
['string', 'string', 'string', 'string', 'string', 'string', 'string', 'string'], all fields except furst one is nullaple, PK on first field and imagine that the actual tuple in this space is the following: ['1', 'b', 'a', null, null, null, 'c']. From the point of view of the Tarantool, this is fully valid tuple.

An imagine that user needs to return this tuple in kind=types.list(types.string).

In current version user can't do this because:

Here is a little test:

diff --git a/graphql/execute.lua b/graphql/execute.lua
index 8622736..fe1d1bd 100644
--- a/graphql/execute.lua
+++ b/graphql/execute.lua
@@ -208,7 +208,7 @@ local function completeValue(fieldType, result, subSelections, context, opts)
 
     local innerType = fieldType.ofType
     local values = {}
-    for i, value in ipairs(result) do
+    for i, value in pairs(result) do
       values[i] = completeValue(innerType, value, subSelections, context)
     end
 
diff --git a/test/integration/graphql_test.lua b/test/integration/graphql_test.lua
index 6462450..d8e563a 100644
--- a/test/integration/graphql_test.lua
+++ b/test/integration/graphql_test.lua
@@ -2147,3 +2147,39 @@ function g.test_non_finite_float()
             query_schema, nil, nil, {variables = variables})
     end
 end
+
+function g.test_is_array_invalid()
+    local query = [[
+       query ($x: [String]) { test(arg: $x) }
+   ]]
+
+   local function callback(_, args)
+        setmetatable(args.arg, {__serialize='array'})
+        return args.arg
+   end
+
+   local query_schema = {
+       ['test'] = {
+           kind = types.list(types.string),
+           arguments = {
+               arg = types.list(types.string),
+           },
+           resolve = callback,
+       }
+   }
+
+   local test_values = {
+       {[3] = 'a', [1] = 'b', [6] = 'c'},
+       {[3] = 'a', [1] = 'b', [7] = 'c'}, -- got error: Variable "x" for a List must be an array, got map
+   }
+
+   for _, v in ipairs(test_values) do
+       local variables = {x = v}
+       local res = check_request(query, query_schema, nil, nil, {variables = variables})
+       t.assert_type(res, 'table')
+
+       print(json.encode(res.test))
+       print(json.encode(v))
+       t.assert_equals(json.encode(res.test), json.encode(v))
+   end
+end

Seems that this case must be fixed anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants