Skip to content

Commit 009b3a2

Browse files
Fix describing type with table in schema
Before this patch, describing argument type in schema with a table resulted in "No value provided" error on query execution. Based on PR #22 by @no1seman
1 parent e9590db commit 009b3a2

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

graphql/execute.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,13 @@ local function getFieldEntry(objectType, object, fields, context)
260260

261261
local arguments = util.map(fieldType.arguments or {}, function(argument, name)
262262
local supplied = argumentMap[name] and argumentMap[name].value
263+
264+
-- This line of code provides support to using
265+
-- `arg = { kind = type, description = desc }`
266+
-- type declaration in query input arguments
267+
-- instead of `arg = type` one.
268+
if argument.kind then argument = argument.kind end
269+
263270
return util.coerceValue(supplied, argument, context.variables, {
264271
strict_non_null = true,
265272
defaultValues = defaultValues,

test/integration/graphql_test.lua

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1588,3 +1588,28 @@ function g.test_descriptions()
15881588
local input_object_arg_described = util.find_by_name(test_input_object.inputFields, 'input_object_arg_described')
15891589
t.assert_equals(input_object_arg_described.description, 'input object argument')
15901590
end
1591+
1592+
function g.test_schema_input_arg_described_with_kind()
1593+
local function callback(_, args)
1594+
return args[1].value
1595+
end
1596+
1597+
local query_schema = {
1598+
['test'] = {
1599+
kind = types.string.nonNull,
1600+
arguments = {
1601+
arg = {
1602+
kind = types.string.nonNull,
1603+
},
1604+
},
1605+
resolve = callback,
1606+
}
1607+
}
1608+
1609+
local query = [[
1610+
{ test(arg: "A") }
1611+
]]
1612+
1613+
local _, errors = check_request(query, query_schema, {})
1614+
t.assert_equals(errors, nil)
1615+
end

0 commit comments

Comments
 (0)