youshido-php/GraphQLBundle

DateTime/Enum types doesn't show invalid input data

MGDSoft opened this issue · 1 comments

Hi,

If I have a param with DateTime and write a bad input, It doesnt show an error. And in resolver I get a null value...

Example

class PepField extends AbstractFieldMutation
{
    public function buildParent(FieldConfig $config)
    {
        $config
            ->setDescription('Deactivates a user')
            ->addArguments([
                'date'  => new DateTimeTzType(),
            ])
        ;
    }

    public function resolve($value, $args, ResolveInfo $info)
    {

        return true;
    }

    /**
     * @return AbstractObjectType|AbstractType
     */
    public function getType()
    {
        return new BooleanType();
    }
}

Execute with this query

mutation{
  pep(date: "asdasd")
}

and result is

{
  "data": {
    "pep": true
  }
}

Looking for this "error" I found the class ResolveValidator, lines 54 - 60

if (!$argument->getType()->isValidValue($argumentType->parseValue($astArgument->getValue()))) {
     $error = $argument->getType()->getLastError();
     throw new ResolveException($error ? $error : sprintf('Not valid type for argument "%s" in query "%s"', $astArgument->getName(), $field->getName()), $astArgument->getLocation());
 }

The problem here is the function parseValue return a null value and isValidValue verify input NULL instead of original value.

SOLUTION
I think inside the function "isValidValue" (AbstractType) should be call inside to "parseValue", to know the original value and if It get a NULL it will throw an error.

if (!$argument->getType()->isValidValue($astArgument->getValue())) {
    $error = $argument->getType()->getLastError();
    throw new ResolveException($error ? $error : sprintf('Not valid type for argument "%s" in query "%s"', $astArgument->getName(), $field->getName()), $astArgument->getLocation());
}

and each Validator call to parseValue if it's necessary