Description
Describe the bug
The vendor/nuwave/lighthouse/src/Validation/Validator.php
validator has the public setArgs
method that can be used to add an ArgumentSet
to the args pre validation.
Making it possible to retrieve a model and validate its content in certain cases.
There is no way to set the Type
property on the Argument
that is used in the ArgumentSet
which is required by the RulesGatherer
class.
This causes the following error to occur:
"debugMessage": "Typed property Nuwave\\Lighthouse\\Execution\\Arguments\\Argument::$type must not be accessed before initialization",
Expected behavior/Solution
Either to be able to set the types manually set it or some sort of parser that resolvers it automatically.
The above(Expected behavior/Solution) answers this question.
Steps to reproduce
- Have an input with the
@validator
directive - Inside the Validator make use of the
prepareForValidation
method. - Store
$args = $this->args
in a local variable and set a value, using the$this->args->addValue()
method. - Call
$this->setArgs($args);
this should raise the error.
Output/Logs
"extensions": { "debugMessage": "Typed property Nuwave\\Lighthouse\\Execution\\Arguments\\Argument::$type must not be accessed before initialization", "file": "/var/www/test/vendor/nuwave/lighthouse/src/Validation/RulesGatherer.php", "line": 63, "trace": [ { "file": "/var/www/test/vendor/nuwave/lighthouse/src/Validation/RulesGatherer.php", "line": 43, "call": "Nuwave\\Lighthouse\\Validation\\RulesGatherer::gatherRulesRecursively(instance of Nuwave\\Lighthouse\\Execution\\Arguments\\ArgumentSet, array(0))" }, { "file": "/var/www/test/vendor/nuwave/lighthouse/src/Validation/ValidateDirective.php", "line": 29, "call": "Nuwave\\Lighthouse\\Validation\\RulesGatherer::__construct(instance of Nuwave\\Lighthouse\\Execution\\Arguments\\ArgumentSet)" }, { "file": "/var/www/test/vendor/nuwave/lighthouse/src/Schema/Values/FieldValue.php", "line": 175, "call": "Nuwave\\Lighthouse\\Validation\\ValidateDirective::Nuwave\\Lighthouse\\Validation\\{closure}(instance of Nuwave\\Lighthouse\\Execution\\Arguments\\ArgumentSet, instance of GraphQL\\Type\\Definition\\ResolveInfo)" }, { "file": "/var/www/test/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php", "line": 714, "call": "Nuwave\\Lighthouse\\Schema\\Values\\FieldValue::Nuwave\\Lighthouse\\Schema\\Values\\{closure}(null, array(1), instance of Nuwave\\Lighthouse\\Execution\\HttpGraphQLContext, instance of GraphQL\\Type\\Definition\\ResolveInfo)"
Click to expand
# Add in log output/error messages here
Lighthouse Version
6.36.0, tried with version 6.56.0 but that didn't make a difference.