Skip to content

Commit e555789

Browse files
committed
Improve return data and errors
1 parent 914fc8d commit e555789

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

graphql/execute.lua

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,6 @@ end
313313

314314
evaluateSelections = function(objectType, object, selections, context)
315315
local result = {}
316-
local errors
317316
local err
318317
local fields = collectFields(objectType, selections, {}, {}, context)
319318
for _, field in ipairs(fields) do
@@ -322,14 +321,14 @@ evaluateSelections = function(objectType, object, selections, context)
322321
result[field.name], err = getFieldEntry(objectType, object, {field.selection},
323322
context)
324323
if err ~= nil then
325-
errors = errors or {}
326-
table.insert(errors, err)
324+
context.errors = context.errors or {}
325+
table.insert(context.errors, err)
327326
end
328327
if result[field.name] == nil then
329328
result[field.name] = box.NULL
330329
end
331330
end
332-
return result, errors
331+
return result, context.errors
333332
end
334333

335334
local function execute(schema, tree, rootValue, variables, operationName)

test/integration/graphql_test.lua

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,4 +1158,43 @@ function g.test_both_data_and_error_result()
11581158
{message = 'Simple error A'},
11591159
{message = 'Simple error B'},
11601160
})
1161+
1162+
query = [[{
1163+
prefix {
1164+
test_A: test(arg: "A")
1165+
test_B: test(arg: "B")
1166+
}
1167+
}]]
1168+
1169+
query_schema = {
1170+
['prefix'] = {
1171+
kind = {
1172+
__type = 'Object',
1173+
name = 'prefix',
1174+
fields = {
1175+
['test'] = {
1176+
kind = types.string.nonNull,
1177+
arguments = {
1178+
arg = types.string.nonNull,
1179+
arg2 = types.string,
1180+
arg3 = types.int,
1181+
arg4 = types.long,
1182+
},
1183+
resolve = callback,
1184+
}
1185+
},
1186+
},
1187+
arguments = {},
1188+
resolve = function()
1189+
return {}
1190+
end,
1191+
}
1192+
}
1193+
1194+
data, errors = check_request(query, query_schema)
1195+
t.assert_equals(data, {prefix = {test_A = "A", test_B = "B"}})
1196+
t.assert_equals(errors, {
1197+
{message = 'Simple error A'},
1198+
{message = 'Simple error B'},
1199+
})
11611200
end

0 commit comments

Comments
 (0)