Skip to content

Commit cd77c34

Browse files
committed
Fix review comments
1 parent adefad3 commit cd77c34

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

graphql/execute.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ end
313313

314314
evaluateSelections = function(objectType, object, selections, context)
315315
local result = {}
316-
local errors = {}
316+
local errors
317317
local err
318318
local fields = collectFields(objectType, selections, {}, {}, context)
319319
for _, field in ipairs(fields) do
@@ -322,6 +322,7 @@ evaluateSelections = function(objectType, object, selections, context)
322322
result[field.name], err = getFieldEntry(objectType, object, {field.selection},
323323
context)
324324
if err ~= nil then
325+
errors = errors or {}
325326
table.insert(errors, err)
326327
end
327328
if result[field.name] == nil then

test/integration/graphql_test.lua

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,3 +1129,29 @@ function g.test_validation_non_null_argument_error()
11291129
end
11301130
)
11311131
end
1132+
1133+
function g.test_both_data_and_error_result()
1134+
local query = [[
1135+
{ test(arg: "A") }
1136+
]]
1137+
1138+
local function callback(_, args)
1139+
return args[1].value, {message = 'Simple error'}
1140+
end
1141+
1142+
local query_schema = {
1143+
['test'] = {
1144+
kind = types.string.nonNull,
1145+
arguments = {
1146+
arg = types.string.nonNull,
1147+
arg2 = types.string,
1148+
arg3 = types.int,
1149+
arg4 = types.long,
1150+
},
1151+
resolve = callback,
1152+
}
1153+
}
1154+
local data, errors = check_request(query, query_schema)
1155+
t.assert_equals(data, {test = 'A'})
1156+
t.assert_equals(errors, {{message = 'Simple error'}})
1157+
end

0 commit comments

Comments
 (0)