Skip to content

Incorrect nullability arguments validation #16

@olegrok

Description

@olegrok

On top of a2fc502. The main part is a test. Change in validation rule should be discussed and reviewed.

diff --git a/graphql/rules.lua b/graphql/rules.lua
index 184a80d..274ed69 100644
--- a/graphql/rules.lua
+++ b/graphql/rules.lua
@@ -199,13 +199,19 @@ function rules.uniqueArgumentNames(node, _)
   end
 end
 
+local function is_scalar_argument(kind)
+  return kind ~= 'variable' and kind ~= 'list' and kind ~= 'inputObject'
+end
+
 function rules.argumentsOfCorrectType(node, context)
   if node.arguments then
     local parentField = getParentField(context, node.name.value)
     for _, argument in pairs(node.arguments) do
       local name = argument.name.value
+      local kind = argument.value.kind
       local argumentType = parentField.arguments[name]
-      util.coerceValue(argument.value, argumentType.kind or argumentType)
+      local options = {strict_non_null = is_scalar_argument(kind)}
+      util.coerceValue(argument.value, argumentType.kind or argumentType, nil, options)
     end
   end
 end
diff --git a/test/unit/graphql_test.lua b/test/unit/graphql_test.lua
index 1e10a9a..9ec5fc9 100644
--- a/test/unit/graphql_test.lua
+++ b/test/unit/graphql_test.lua
@@ -1056,4 +1056,6 @@ function g.test_boolean_coerce()
             validate, test_schema, parse([[ { test_boolean(value: 123) } ]]))
     t.assert_error_msg_contains('Could not coerce value "value" with type "string" to type boolean',
             validate, test_schema, parse([[ { test_boolean(value: "value") } ]]))
+    t.assert_error_msg_contains('Expected non-null for "NonNull(Boolean)", got null',
+            validate, test_schema, parse([[ { test_boolean(value: null, non_null_value: null) } ]]))
 end

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions