mirror of
https://github.com/retailcrm/graphql-php.git
synced 2024-11-22 12:56:05 +03:00
TASK: Code style #2
This commit is contained in:
parent
a3d050ff6b
commit
5a1caf0549
@ -13,19 +13,17 @@ use GraphQL\Language\AST\NodeKind;
|
|||||||
use GraphQL\Language\AST\NodeList;
|
use GraphQL\Language\AST\NodeList;
|
||||||
use GraphQL\Language\DirectiveLocation;
|
use GraphQL\Language\DirectiveLocation;
|
||||||
use GraphQL\Validator\ValidationContext;
|
use GraphQL\Validator\ValidationContext;
|
||||||
|
use function array_map;
|
||||||
use function count;
|
use function count;
|
||||||
use function in_array;
|
use function in_array;
|
||||||
use function sprintf;
|
use function sprintf;
|
||||||
use function array_map;
|
|
||||||
|
|
||||||
class KnownDirectives extends ValidationRule
|
class KnownDirectives extends ValidationRule
|
||||||
{
|
{
|
||||||
|
|
||||||
public function getVisitor(ValidationContext $context)
|
public function getVisitor(ValidationContext $context)
|
||||||
{
|
{
|
||||||
$locationsMap = [];
|
$locationsMap = [];
|
||||||
$schema = $context->getSchema();
|
$schema = $context->getSchema();
|
||||||
|
|
||||||
$definedDirectives = $schema->getDirectives();
|
$definedDirectives = $schema->getDirectives();
|
||||||
|
|
||||||
foreach ($definedDirectives as $directive) {
|
foreach ($definedDirectives as $directive) {
|
||||||
@ -35,12 +33,14 @@ class KnownDirectives extends ValidationRule
|
|||||||
$astDefinition = $context->getDocument()->definitions;
|
$astDefinition = $context->getDocument()->definitions;
|
||||||
|
|
||||||
foreach ($astDefinition as $def) {
|
foreach ($astDefinition as $def) {
|
||||||
if ($def instanceof DirectiveDefinitionNode) {
|
if (! ($def instanceof DirectiveDefinitionNode)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$locationsMap[$def->name->value] = array_map(function ($name) {
|
$locationsMap[$def->name->value] = array_map(function ($name) {
|
||||||
return $name->value;
|
return $name->value;
|
||||||
}, $def->locations);
|
}, $def->locations);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return [
|
return [
|
||||||
NodeKind::DIRECTIVE => function (DirectiveNode $node, $key, $parent, $path, $ancestors) use ($context, $locationsMap) {
|
NodeKind::DIRECTIVE => function (DirectiveNode $node, $key, $parent, $path, $ancestors) use ($context, $locationsMap) {
|
||||||
$name = $node->name->value;
|
$name = $node->name->value;
|
||||||
@ -56,15 +56,17 @@ class KnownDirectives extends ValidationRule
|
|||||||
|
|
||||||
$candidateLocation = $this->getDirectiveLocationForASTPath($ancestors);
|
$candidateLocation = $this->getDirectiveLocationForASTPath($ancestors);
|
||||||
|
|
||||||
if ($candidateLocation && ! in_array($candidateLocation, $locations)) {
|
if (! $candidateLocation || in_array($candidateLocation, $locations)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$context->reportError(
|
$context->reportError(
|
||||||
new Error(
|
new Error(
|
||||||
self::misplacedDirectiveMessage($name, $candidateLocation),
|
self::misplacedDirectiveMessage($name, $candidateLocation),
|
||||||
[$node]
|
[$node]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
},
|
||||||
}
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user