Skip to content

Commit 033c1c9

Browse files
Forbid using null default for Non-nullable args
Specification [1] states that Nullable variable can be used for NonNullable argument if it has Non-null default. See more in [2] issue. 1. http://spec.graphql.org/October2021/#sec-All-Variable-Usages-are-Allowed 2. graphql/graphql-js#3715
1 parent 5a31f85 commit 033c1c9

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

graphql/rules.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -507,12 +507,13 @@ local function isVariableTypesValid(argument, argumentType, context,
507507
error('Unknown variable "' .. variableName .. '"')
508508
end
509509

510-
local hasDefault = variableDefinition.defaultValue ~= nil
510+
local hasNonNullDefault = (variableDefinition.defaultValue ~= nil) and
511+
(variableDefinition.defaultValue.kind ~= 'null')
511512

512513
local variableType = query_util.typeFromAST(variableDefinition.type,
513514
context.schema)
514515

515-
if hasDefault and variableType.__type ~= 'NonNull' then
516+
if hasNonNullDefault and variableType.__type ~= 'NonNull' then
516517
variableType = types.nonNull(variableType)
517518
end
518519

0 commit comments

Comments
 (0)