Skip to content

Commit 37a42ed

Browse files
committed
Query validation should pass if empty array of rules is provided
1 parent 65d9472 commit 37a42ed

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/Validator/DocumentValidator.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,11 @@ public static function addRule($name, callable $rule)
118118

119119
public static function validate(Schema $schema, DocumentNode $ast, array $rules = null, TypeInfo $typeInfo = null)
120120
{
121+
if (null === $rules) {
122+
$rules = static::allRules();
123+
}
121124
$typeInfo = $typeInfo ?: new TypeInfo($schema);
122-
$errors = static::visitUsingRules($schema, $typeInfo, $ast, $rules ?: static::allRules());
125+
$errors = static::visitUsingRules($schema, $typeInfo, $ast, $rules);
123126
return $errors;
124127
}
125128

tests/Validator/ValidationTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,16 @@ public function testValidatesQueries()
2323
}
2424
');
2525
}
26+
27+
public function testPassesValidationWithEmptyRules()
28+
{
29+
$query = '{invalid}';
30+
31+
$expectedError = [
32+
'message' => 'Cannot query field "invalid" on type "QueryRoot".',
33+
'locations' => [ ['line' => 1, 'column' => 2] ]
34+
];
35+
$this->expectFailsCompleteValidation($query, [$expectedError]);
36+
$this->expectValid($this->getDefaultSchema(), [], $query);
37+
}
2638
}

0 commit comments

Comments
 (0)