mirror of
https://github.com/retailcrm/graphql-php.git
synced 2024-11-25 22:36:02 +03:00
f661f38215
This factors out the enum value validation from scalar value validation and ensures the same try/catch is used in isValidLiteralValue as isValidPHPValue and protecting from errors in valueFromAST. ref: graphql/graphql-js#1126
68 lines
1.6 KiB
PHP
68 lines
1.6 KiB
PHP
<?php
|
|
namespace GraphQL\Tests\Validator;
|
|
|
|
use GraphQL\Error\FormattedError;
|
|
use GraphQL\Validator\DocumentValidator;
|
|
use GraphQL\Validator\Rules\QueryComplexity;
|
|
|
|
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' => "Argument \"arg\" has invalid value \"bad value\".
|
|
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".',
|
|
'locations' => [ ['line' => 1, 'column' => 2] ]
|
|
];
|
|
$this->expectFailsCompleteValidation($query, [$expectedError]);
|
|
$this->expectValid($this->getTestSchema(), [], $query);
|
|
}
|
|
}
|