mirror of
https://github.com/retailcrm/graphql-php.git
synced 2024-11-23 21:36:05 +03:00
21dc3fe664
(cherry picked from commit 33e3c9c338
)
65 lines
1.6 KiB
PHP
65 lines
1.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace GraphQL\Tests\Validator;
|
|
|
|
class ValidationTest extends ValidatorTestCase
|
|
{
|
|
// Validate: Supports full validation
|
|
/**
|
|
* @see it('validates queries')
|
|
*/
|
|
public function testValidatesQueries() : void
|
|
{
|
|
$this->expectPassesCompleteValidation('
|
|
query {
|
|
catOrDog {
|
|
... on Cat {
|
|
furColor
|
|
}
|
|
... on Dog {
|
|
isHousetrained
|
|
}
|
|
}
|
|
}
|
|
');
|
|
}
|
|
|
|
/**
|
|
* @see it('detects bad scalar parse')
|
|
*/
|
|
public function testDetectsBadScalarParse() : void
|
|
{
|
|
$doc = '
|
|
query {
|
|
invalidArg(arg: "bad value")
|
|
}
|
|
';
|
|
|
|
$expectedError = [
|
|
'message' => 'Field "invalidArg" argument "arg" requires type Invalid, found "bad value"; Invalid scalar is always invalid: bad value',
|
|
'locations' => [['line' => 3, 'column' => 25]],
|
|
];
|
|
|
|
$this->expectInvalid(
|
|
self::getTestSchema(),
|
|
null,
|
|
$doc,
|
|
[$expectedError]
|
|
);
|
|
}
|
|
|
|
public function testPassesValidationWithEmptyRules() : void
|
|
{
|
|
$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(self::getTestSchema(), [], $query);
|
|
}
|
|
}
|