Skip to content

Commit a5476e8

Browse files
no1semanTotktonada
authored andcommitted
Fix damaging schema
Remove forcing defaultValue on directiveMap generation because it leads to adding redundant defaultValue field to Scalars itself into typeMap: { "typeMap": { "Int": { "defaultValue": 1, <- ERROR "parseLiteral": "function: 0x415a8fe8", "__type": "Scalar", "nonNull": {}, "serialize": "function: 0x415a8ed8", "isValueOfTheType": "function: 0x415a8e98", "name": "Int", "description": "..." } } }
1 parent b8f86bc commit a5476e8

File tree

2 files changed

+67
-1
lines changed

2 files changed

+67
-1
lines changed

graphql/schema.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ function schema:generateDirectiveMap()
117117
if argumentType == nil then
118118
error('Must supply type for argument "' .. name .. '" on "' .. directive.name .. '"')
119119
end
120-
argumentType.defaultValue = argument.defaultValue
121120
self:generateTypeMap(argumentType)
122121
end
123122
end

test/integration/graphql_test.lua

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1804,3 +1804,70 @@ function g.test_skip_include_directives()
18041804
t.assert_equals(errors, nil)
18051805
t.assert_items_equals(data, {test = {uri = "uri1", uris = {uri = "uri2"}}})
18061806
end
1807+
1808+
-- test simultaneous usage of mutation and directive default values
1809+
function g.test_mutation_and_directive_arguments_default_values()
1810+
local function callback(_, _)
1811+
return nil
1812+
end
1813+
1814+
local mutation_schema = {
1815+
['test_mutation'] = {
1816+
kind = types.string.nonNull,
1817+
arguments = {
1818+
object_arg = {
1819+
kind = types.inputObject({
1820+
name = 'test_input_object',
1821+
fields = {
1822+
nested = {
1823+
kind = types.string,
1824+
defaultValue = 'default Value',
1825+
},
1826+
},
1827+
kind = types.string,
1828+
}),
1829+
},
1830+
mutation_arg = {
1831+
kind = types.int,
1832+
defaultValue = 1,
1833+
},
1834+
1835+
},
1836+
resolve = callback,
1837+
}
1838+
}
1839+
1840+
local directives = {
1841+
types.directive({
1842+
schema = schema,
1843+
name = 'timeout',
1844+
description = 'Request execute timeout',
1845+
arguments = {
1846+
seconds = {
1847+
kind = types.int,
1848+
description = 'Request timeout (in seconds). Default: 1 second',
1849+
defaultValue = 1,
1850+
},
1851+
},
1852+
onField = true,
1853+
})
1854+
}
1855+
1856+
local root = {
1857+
query = types.object({
1858+
name = 'Query',
1859+
fields = {},
1860+
}),
1861+
mutation = types.object({
1862+
name = 'Mutation',
1863+
fields = mutation_schema or {},
1864+
}),
1865+
directives = directives,
1866+
}
1867+
1868+
local compiled_schema = schema.create(root, test_schema_name)
1869+
1870+
-- test that schema.typeMap is not corrupted when both mutation and
1871+
-- directive default values used on the same argument type
1872+
t.assert_equals(compiled_schema.typeMap['Int'].defaultValue, nil)
1873+
end

0 commit comments

Comments
 (0)