Skip to content

Commit b92feeb

Browse files
committed
Fix coerse scalar list variables
1 parent 58b64a6 commit b92feeb

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

graphql/util.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ local function coerceValue(node, schemaType, variables, opts)
115115
node.name.value, variables[node.name.value], schemaType.name
116116
))
117117
end
118+
elseif type(value) == 'table' and schemaType.__type == 'List' and
119+
type(schemaType.ofType) == 'table' and schemaType.ofType.parseValue ~= nil then
120+
for k, v in ipairs(value) do
121+
value[k] = schemaType.ofType.parseValue(v)
122+
end
118123
end
119124
return value
120125
end

test/integration/graphql_test.lua

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,8 +562,8 @@ function g.test_custom_type_scalar_variables()
562562
if args.field == nil then
563563
return nil
564564
end
565-
assert(type(args.field) == 'table', "Field is not a table! ")
566-
assert(args.field.test ~= nil, "No field 'test' in object!")
565+
t.assert_type(args.field, 'table', "Field is not a table! ")
566+
t.assert_not_equals(args.field.test, nil, "No field 'test' in object!")
567567
return args.field
568568
end
569569
},
@@ -576,6 +576,20 @@ function g.test_custom_type_scalar_variables()
576576
return args.fields[1]
577577
end
578578
},
579+
['test_json_type_list'] = {
580+
arguments = {
581+
array = types.list(json_type),
582+
},
583+
kind = types.list(json_type),
584+
resolve = function(_, args)
585+
if args.array == nil then
586+
return nil
587+
end
588+
t.assert_type(args.array[1], 'table', "Array element is not a table! ")
589+
t.assert_not_equals(args.array[1].test, nil, "No field 'test' in array element!")
590+
return args.array
591+
end
592+
},
579593
['test_custom_type_scalar_inputObject'] = {
580594
kind = types.string,
581595
arguments = {
@@ -617,6 +631,16 @@ function g.test_custom_type_scalar_variables()
617631
variables = {field = box.NULL},
618632
}), {test_json_type = 'null'})
619633

634+
t.assert_equals(check_request([[
635+
query($array: [Json]) {
636+
test_json_type_list(
637+
array: $array
638+
)
639+
}
640+
]], query_schema, nil, nil, {
641+
variables = {array = {json.encode({test = 123})}},
642+
}), {test_json_type_list = {'{"test":123}'}})
643+
620644
t.assert_equals(check_request([[
621645
query {
622646
test_json_type(

0 commit comments

Comments
 (0)