mirror of
https://github.com/retailcrm/graphql-php.git
synced 2024-11-22 04:46:04 +03:00
TASK: Code style
This commit is contained in:
parent
0262f59a3f
commit
a3d050ff6b
@ -1476,7 +1476,7 @@ class Parser
|
||||
$start = $this->lexer->token;
|
||||
$this->expectKeyword('extend');
|
||||
$this->expectKeyword('schema');
|
||||
$directives = $this->parseDirectives(true);
|
||||
$directives = $this->parseDirectives(true);
|
||||
$operationTypes = $this->peek(Token::BRACE_L)
|
||||
? $this->many(
|
||||
Token::BRACE_L,
|
||||
@ -1490,7 +1490,7 @@ class Parser
|
||||
return new SchemaTypeExtensionNode([
|
||||
'directives' => $directives,
|
||||
'operationTypes' => $operationTypes,
|
||||
'loc' => $this->loc($start)
|
||||
'loc' => $this->loc($start),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -341,7 +341,7 @@ class Printer
|
||||
[
|
||||
'extend schema',
|
||||
$this->join($def->directives, ' '),
|
||||
$this->block($def->operationTypes)
|
||||
$this->block($def->operationTypes),
|
||||
],
|
||||
' '
|
||||
);
|
||||
|
@ -166,7 +166,7 @@ class Visitor
|
||||
|
||||
NodeKind::DIRECTIVE_DEFINITION => ['description', 'name', 'arguments', 'locations'],
|
||||
|
||||
NodeKind::SCHEMA_EXTENSION => ['directives', 'operationTypes']
|
||||
NodeKind::SCHEMA_EXTENSION => ['directives', 'operationTypes'],
|
||||
];
|
||||
|
||||
/**
|
||||
|
@ -114,7 +114,7 @@ class Schema
|
||||
);
|
||||
}
|
||||
|
||||
$this->config = $config;
|
||||
$this->config = $config;
|
||||
$this->extensionASTNodes = $config->extensionASTNodes;
|
||||
|
||||
if ($config->query) {
|
||||
|
@ -278,7 +278,7 @@ class SchemaConfig
|
||||
/**
|
||||
* @return SchemaTypeExtensionNode[]
|
||||
*/
|
||||
public function getExtensionASTNodes(): array
|
||||
public function getExtensionASTNodes()
|
||||
{
|
||||
return $this->extensionASTNodes;
|
||||
}
|
||||
@ -286,7 +286,7 @@ class SchemaConfig
|
||||
/**
|
||||
* @param SchemaTypeExtensionNode[] $extensionASTNodes
|
||||
*/
|
||||
public function setExtensionASTNodes(array $extensionASTNodes): void
|
||||
public function setExtensionASTNodes(array $extensionASTNodes)
|
||||
{
|
||||
$this->extensionASTNodes = $extensionASTNodes;
|
||||
}
|
||||
|
@ -5,38 +5,37 @@ declare(strict_types=1);
|
||||
namespace GraphQL\Validator\Rules;
|
||||
|
||||
use GraphQL\Error\Error;
|
||||
use GraphQL\Language\AST\DirectiveDefinitionNode;
|
||||
use GraphQL\Language\AST\DirectiveNode;
|
||||
use GraphQL\Language\AST\InputObjectTypeDefinitionNode;
|
||||
use GraphQL\Language\AST\Node;
|
||||
use GraphQL\Language\AST\NodeKind;
|
||||
use GraphQL\Language\AST\NodeList;
|
||||
use GraphQL\Language\DirectiveLocation;
|
||||
use GraphQL\Type\Definition\Directive;
|
||||
use GraphQL\Validator\ValidationContext;
|
||||
use function count;
|
||||
use function in_array;
|
||||
use function sprintf;
|
||||
use function array_map;
|
||||
|
||||
class KnownDirectives extends ValidationRule
|
||||
{
|
||||
/**
|
||||
* @param ValidationContext $context
|
||||
* @return array
|
||||
*/
|
||||
|
||||
public function getVisitor(ValidationContext $context)
|
||||
{
|
||||
$locationsMap = [];
|
||||
$schema = $context->getSchema();
|
||||
|
||||
$definedDirectives = $schema ? $schema->getDirectives() : Directive::getInternalDirectives();
|
||||
$definedDirectives = $schema->getDirectives();
|
||||
|
||||
foreach ($definedDirectives as $directive) {
|
||||
$locationsMap[$directive->name] = $directive->locations;
|
||||
}
|
||||
|
||||
$astDefinition = $context->getDocument()->definitions;
|
||||
|
||||
foreach ($astDefinition as $def) {
|
||||
if ($def->kind === NodeKind::DIRECTIVE_DEFINITION) {
|
||||
if ($def instanceof DirectiveDefinitionNode) {
|
||||
$locationsMap[$def->name->value] = array_map(function ($name) {
|
||||
return $name->value;
|
||||
}, $def->locations);
|
||||
@ -47,7 +46,7 @@ class KnownDirectives extends ValidationRule
|
||||
$name = $node->name->value;
|
||||
$locations = $locationsMap[$name] ?? null;
|
||||
|
||||
if (!$locations) {
|
||||
if (! $locations) {
|
||||
$context->reportError(new Error(
|
||||
self::unknownDirectiveMessage($name),
|
||||
[$node]
|
||||
@ -57,11 +56,13 @@ class KnownDirectives extends ValidationRule
|
||||
|
||||
$candidateLocation = $this->getDirectiveLocationForASTPath($ancestors);
|
||||
|
||||
if ($candidateLocation && !in_array($candidateLocation, $locations)) {
|
||||
$context->reportError(new Error(
|
||||
self::misplacedDirectiveMessage($name, $candidateLocation),
|
||||
[$node]
|
||||
));
|
||||
if ($candidateLocation && ! in_array($candidateLocation, $locations)) {
|
||||
$context->reportError(
|
||||
new Error(
|
||||
self::misplacedDirectiveMessage($name, $candidateLocation),
|
||||
[$node]
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
];
|
||||
|
Loading…
Reference in New Issue
Block a user