Skip to content

Commit 2c250e9

Browse files
committed
fix validation for non-nullable arguments
The problem was introduced in e37651d (support "null" arguments) here we add redundant check that started to throw error "graphql/util.lua:72: attempt to index local 'node' (a nil value)" This patch removes this check and adds test (with small difference copied from TDG) that catches a problem.
1 parent a995138 commit 2c250e9

File tree

2 files changed

+38
-8
lines changed

2 files changed

+38
-8
lines changed

graphql/util.lua

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,22 +68,18 @@ local function coerceValue(node, schemaType, variables, opts)
6868
local strict_non_null = opts.strict_non_null or false
6969
local defaultValues = opts.defaultValues or {}
7070

71-
if not node then
72-
return nil
73-
end
74-
7571
if schemaType.__type == 'NonNull' then
76-
if node.kind == 'null' then
77-
error(('Expected non-null for "%s", got null'):format(getTypeName(schemaType)))
78-
end
79-
8072
local res = coerceValue(node, schemaType.ofType, variables, opts)
8173
if strict_non_null and res == nil then
8274
error(('Expected non-null for "%s", got null'):format(getTypeName(schemaType)))
8375
end
8476
return res
8577
end
8678

79+
if not node then
80+
return nil
81+
end
82+
8783
-- handle precompiled values
8884
if node.compiled ~= nil then
8985
return node.compiled

test/integration/graphql_test.lua

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,3 +1086,37 @@ function g.test_null()
10861086
end
10871087
)
10881088
end
1089+
1090+
function g.test_validation_non_null_argument_error()
1091+
local query = [[
1092+
query QueryFail {
1093+
TestEntity(insert: {})
1094+
}
1095+
]]
1096+
1097+
local function callback(_, _)
1098+
return nil
1099+
end
1100+
1101+
local query_schema = {
1102+
['TestEntity'] = {
1103+
kind = types.string,
1104+
arguments = {
1105+
insert = types.inputObject({
1106+
name = 'TestEntityInput',
1107+
fields = {
1108+
non_null = types.string.nonNull,
1109+
}
1110+
}),
1111+
},
1112+
resolve = callback,
1113+
}
1114+
}
1115+
1116+
t.assert_error_msg_contains(
1117+
'Expected non-null',
1118+
function()
1119+
check_request(query, query_schema, {variables = {}})
1120+
end
1121+
)
1122+
end

0 commit comments

Comments
 (0)