Skip to content

Fix describing type with table in schema #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions graphql/execute.lua
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,13 @@ local function getFieldEntry(objectType, object, fields, context)

local arguments = util.map(fieldType.arguments or {}, function(argument, name)
local supplied = argumentMap[name] and argumentMap[name].value

-- This line of code provides support to using
-- `arg = { kind = type, description = desc }`
-- type declaration in query input arguments
-- instead of `arg = type` one.
if argument.kind then argument = argument.kind end

return util.coerceValue(supplied, argument, context.variables, {
strict_non_null = true,
defaultValues = defaultValues,
Expand Down
7 changes: 7 additions & 0 deletions graphql/rules.lua
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,13 @@ local function isVariableTypesValid(argument, argumentType, context,
variableType = types.nonNull(variableType)
end

-- This line of code provides support to using
-- `arg = { kind = type, description = desc }`
-- type declaration in query input arguments
-- instead of `arg = type` one when passing
-- argument with a variable.
if argumentType.kind ~= nil then argumentType = argumentType.kind end

if not isTypeSubTypeOf(variableType, argumentType, context) then
return false, ('Variable "%s" type mismatch: the variable type "%s" ' ..
'is not compatible with the argument type "%s"'):format(variableName,
Expand Down
51 changes: 51 additions & 0 deletions test/integration/graphql_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1588,3 +1588,54 @@ function g.test_descriptions()
local input_object_arg_described = util.find_by_name(test_input_object.inputFields, 'input_object_arg_described')
t.assert_equals(input_object_arg_described.description, 'input object argument')
end

function g.test_schema_input_arg_described_with_kind()
local function callback(_, args)
return args[1].value
end

local query_schema = {
['test'] = {
kind = types.string.nonNull,
arguments = {
arg = {
kind = types.string.nonNull,
},
},
resolve = callback,
}
}

local query = [[
{ test(arg: "A") }
]]

local _, errors = check_request(query, query_schema, {})
t.assert_equals(errors, nil)
end

function g.test_schema_input_arg_described_with_kind_variable_pass()
local function callback(_, args)
return args[1].value
end

local query_schema = {
['test'] = {
kind = types.string.nonNull,
arguments = {
arg = {
kind = types.string.nonNull,
},
},
resolve = callback,
}
}

local query = [[
query ($arg: String!) { test(arg: $arg) }
]]
local variables = { arg = 'B' }

local _, errors = check_request(query, query_schema, nil, nil, { variables = variables })
t.assert_equals(errors, nil)
end