Skip to content

Commit

Permalink
fixed variable validator + added proper arguments handling
Browse files Browse the repository at this point in the history
fixed variables in nested fields and queries don't work #12
  • Loading branch information
viniychuk committed Jul 13, 2016
1 parent ea66d00 commit a948211
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/Execution/Processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,13 @@ protected function getPreResolvedValue($contextValue, FieldAst $fieldAst, Abstra
if ($resolveFunction = $field->getConfig()->getResolveFunction()) {
$resolveInfo = new ResolveInfo($field, [$fieldAst], $field->getType(), $this->executionContext);

$resolverValue = $resolveFunction($resolved ? $resolverValue : $contextValue, $fieldAst->getKeyValueArguments(), $resolveInfo);
if (!$this->resolveValidator->validateArguments($field, $fieldAst, $this->executionContext->getRequest())) {
throw new \Exception(sprintf('Not valid arguments for the field "%s"', $fieldAst->getName()));

} else {
$resolverValue = $resolveFunction($resolved ? $resolverValue : $contextValue, $fieldAst->getKeyValueArguments(), $resolveInfo);
}

}

if (!$resolverValue && !$resolved) {
Expand Down
2 changes: 1 addition & 1 deletion src/Parser/Ast/ArgumentValue/Variable.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function __construct($name, $type, $required = false, $isArray = false)
public function getValue()
{
if (!$this->value) {
throw new \LogicException('Value not set to variable else');
throw new \LogicException('Value is not set for variable "' . $this->name . '"');
}

return $this->value;
Expand Down
3 changes: 2 additions & 1 deletion src/Validator/ResolveValidator/ResolveValidatorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@

use Youshido\GraphQL\Execution\Request;
use Youshido\GraphQL\Field\AbstractField;
use Youshido\GraphQL\Parser\Ast\Field;
use Youshido\GraphQL\Parser\Ast\Query;

interface ResolveValidatorInterface
{

/**
* @param $field AbstractField
* @param $query Query
* @param $query Query|Field
* @param $request Request
*
* @return bool
Expand Down

0 comments on commit a948211

Please sign in to comment.