mirror of
https://github.com/retailcrm/graphql-php.git
synced 2024-11-25 22:36:02 +03:00
58e0c7a178
This generalizes the "arguments of correct type" and "default values of correct type" to a single rule "values of correct type" which has been re-written to rely on a traversal rather than the utility function `isValidLiteralValue`. To reduce breaking scope, this does not remove that utility even though it's no longer used directly within the library. Since the default values rule included another validation rule that rule was renamed to a more apt "variable default value allowed". This also includes the original errors from custom scalars in the validation error output, solving the remainder of graphql/graphql-js#821. ref: graphql/graphql-js#1144
63 lines
1.5 KiB
PHP
63 lines
1.5 KiB
PHP
<?php
|
|
namespace GraphQL\Tests\Validator;
|
|
|
|
class ValidationTest extends TestCase
|
|
{
|
|
// Validate: Supports full validation
|
|
|
|
/**
|
|
* @it validates queries
|
|
*/
|
|
public function testValidatesQueries()
|
|
{
|
|
$this->expectPassesCompleteValidation('
|
|
query {
|
|
catOrDog {
|
|
... on Cat {
|
|
furColor
|
|
}
|
|
... on Dog {
|
|
isHousetrained
|
|
}
|
|
}
|
|
}
|
|
');
|
|
}
|
|
|
|
/**
|
|
* @it detects bad scalar parse
|
|
*/
|
|
public function testDetectsBadScalarParse()
|
|
{
|
|
$doc = '
|
|
query {
|
|
invalidArg(arg: "bad value")
|
|
}
|
|
';
|
|
|
|
$expectedError = [
|
|
'message' => "Expected type Invalid, found \"bad value\"; Invalid scalar is always invalid: bad value",
|
|
'locations' => [ ['line' => 3, 'column' => 25] ]
|
|
];
|
|
|
|
$this->expectInvalid(
|
|
$this->getTestSchema(),
|
|
null,
|
|
$doc,
|
|
[$expectedError]
|
|
);
|
|
}
|
|
|
|
public function testPassesValidationWithEmptyRules()
|
|
{
|
|
$query = '{invalid}';
|
|
|
|
$expectedError = [
|
|
'message' => 'Cannot query field "invalid" on type "QueryRoot". Did you mean "invalidArg"?',
|
|
'locations' => [ ['line' => 1, 'column' => 2] ]
|
|
];
|
|
$this->expectFailsCompleteValidation($query, [$expectedError]);
|
|
$this->expectValid($this->getTestSchema(), [], $query);
|
|
}
|
|
}
|