Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DateTime/Enum types doesn't show invalid input data #36

Closed
MGDSoft opened this issue May 11, 2017 · 1 comment
Closed

DateTime/Enum types doesn't show invalid input data #36

MGDSoft opened this issue May 11, 2017 · 1 comment

Comments

@MGDSoft
Copy link
Contributor

MGDSoft commented May 11, 2017

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

@MGDSoft MGDSoft changed the title DateTime types doesnt show invalid input data DateTime types doesn't show invalid input data May 11, 2017
@MGDSoft MGDSoft changed the title DateTime types doesn't show invalid input data DateTime/Enum types doesn't show invalid input data May 11, 2017
@MGDSoft
Copy link
Contributor Author

MGDSoft commented May 17, 2017

moved to youshido-php/GraphQL#147

@MGDSoft MGDSoft closed this as completed May 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant