Skip to content

Commit 2e5f29c

Browse files
Fix variable validation for type as table
Before this patch, describing argument type in schema with a table resulted in "unsupported Lua type 'function'" error on variable type validation. Based on PR #22 by @no1seman
1 parent 6b15568 commit 2e5f29c

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

graphql/rules.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,7 @@ local function isVariableTypesValid(argument, argumentType, context,
516516
if hasDefault and variableType.__type ~= 'NonNull' then
517517
variableType = types.nonNull(variableType)
518518
end
519+
if argumentType.kind ~= nil then argumentType = argumentType.kind end
519520

520521
if not isTypeSubTypeOf(variableType, argumentType, context) then
521522
return false, ('Variable "%s" type mismatch: the variable type "%s" ' ..

test/integration/graphql_test.lua

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,3 +1535,28 @@ function g.test_schema_input_arg_described_with_kind()
15351535
t.assert_equals(errors, nil)
15361536
end
15371537

1538+
function g.test_schema_input_arg_described_with_kind_variable_pass()
1539+
local function callback(_, args)
1540+
return args[1].value
1541+
end
1542+
1543+
local query_schema = {
1544+
['test'] = {
1545+
kind = types.string.nonNull,
1546+
arguments = {
1547+
arg = {
1548+
kind = types.string.nonNull,
1549+
},
1550+
},
1551+
resolve = callback,
1552+
}
1553+
}
1554+
1555+
local query = [[
1556+
query ($arg: String!) { test(arg: $arg) }
1557+
]]
1558+
local variables = { arg = 'B' }
1559+
1560+
local _, errors = check_request(query, query_schema, nil, nil, { variables = variables })
1561+
t.assert_equals(errors, nil)
1562+
end

0 commit comments

Comments
 (0)