2018-02-11 15:27:26 +03:00
|
|
|
<?php
|
|
|
|
namespace GraphQL\Tests\Validator;
|
|
|
|
|
|
|
|
use GraphQL\Error\FormattedError;
|
|
|
|
use GraphQL\Language\SourceLocation;
|
|
|
|
use GraphQL\Validator\Rules\ExecutableDefinitions;
|
|
|
|
use GraphQL\Validator\Rules\KnownDirectives;
|
|
|
|
|
2018-07-29 18:43:10 +03:00
|
|
|
class ExecutableDefinitionsTest extends ValidatorTestCase
|
2018-02-11 15:27:26 +03:00
|
|
|
{
|
|
|
|
// Validate: Executable definitions
|
|
|
|
|
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('with only operation')
|
2018-02-11 15:27:26 +03:00
|
|
|
*/
|
|
|
|
public function testWithOnlyOperation()
|
|
|
|
{
|
|
|
|
$this->expectPassesRule(new ExecutableDefinitions, '
|
|
|
|
query Foo {
|
|
|
|
dog {
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('with operation and fragment')
|
2018-02-11 15:27:26 +03:00
|
|
|
*/
|
|
|
|
public function testWithOperationAndFragment()
|
|
|
|
{
|
|
|
|
$this->expectPassesRule(new ExecutableDefinitions, '
|
|
|
|
query Foo {
|
|
|
|
dog {
|
|
|
|
name
|
|
|
|
...Frag
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fragment Frag on Dog {
|
|
|
|
name
|
|
|
|
}
|
|
|
|
');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('with typeDefinition')
|
2018-02-11 15:27:26 +03:00
|
|
|
*/
|
|
|
|
public function testWithTypeDefinition()
|
|
|
|
{
|
|
|
|
$this->expectFailsRule(new ExecutableDefinitions, '
|
|
|
|
query Foo {
|
|
|
|
dog {
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type Cow {
|
|
|
|
name: String
|
|
|
|
}
|
|
|
|
|
|
|
|
extend type Dog {
|
|
|
|
color: String
|
|
|
|
}
|
|
|
|
',
|
|
|
|
[
|
|
|
|
$this->nonExecutableDefinition('Cow', 8, 12),
|
|
|
|
$this->nonExecutableDefinition('Dog', 12, 19),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function nonExecutableDefinition($defName, $line, $column)
|
|
|
|
{
|
|
|
|
return FormattedError::create(
|
|
|
|
ExecutableDefinitions::nonExecutableDefinitionMessage($defName),
|
|
|
|
[ new SourceLocation($line, $column) ]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|