diff --git a/src/Validator/DocumentValidator.php b/src/Validator/DocumentValidator.php index f00dfb9..b70cdc8 100644 --- a/src/Validator/DocumentValidator.php +++ b/src/Validator/DocumentValidator.php @@ -118,8 +118,11 @@ class DocumentValidator public static function validate(Schema $schema, DocumentNode $ast, array $rules = null, TypeInfo $typeInfo = null) { + if (null === $rules) { + $rules = static::allRules(); + } $typeInfo = $typeInfo ?: new TypeInfo($schema); - $errors = static::visitUsingRules($schema, $typeInfo, $ast, $rules ?: static::allRules()); + $errors = static::visitUsingRules($schema, $typeInfo, $ast, $rules); return $errors; } diff --git a/tests/Validator/ValidationTest.php b/tests/Validator/ValidationTest.php index 018ee33..55f1059 100644 --- a/tests/Validator/ValidationTest.php +++ b/tests/Validator/ValidationTest.php @@ -23,4 +23,16 @@ class ValidationTest extends TestCase } '); } + + public function testPassesValidationWithEmptyRules() + { + $query = '{invalid}'; + + $expectedError = [ + 'message' => 'Cannot query field "invalid" on type "QueryRoot".', + 'locations' => [ ['line' => 1, 'column' => 2] ] + ]; + $this->expectFailsCompleteValidation($query, [$expectedError]); + $this->expectValid($this->getDefaultSchema(), [], $query); + } }