![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/webonyx/graphql-php/src/Validator/Rules/ |
<?php declare(strict_types=1); namespace GraphQL\Validator\Rules; use GraphQL\Error\Error; use GraphQL\Language\AST\FieldNode; use GraphQL\Language\AST\NodeKind; use GraphQL\Language\Visitor; use GraphQL\Language\VisitorOperation; use GraphQL\Validator\QueryValidationContext; class ProvidedRequiredArguments extends ValidationRule { /** @throws \Exception */ public function getVisitor(QueryValidationContext $context): array { $providedRequiredArgumentsOnDirectives = new ProvidedRequiredArgumentsOnDirectives(); return $providedRequiredArgumentsOnDirectives->getVisitor($context) + [ NodeKind::FIELD => [ 'leave' => static function (FieldNode $fieldNode) use ($context): ?VisitorOperation { $fieldDef = $context->getFieldDef(); if ($fieldDef === null) { return Visitor::skipNode(); } $argNodes = $fieldNode->arguments; $argNodeMap = []; foreach ($argNodes as $argNode) { $argNodeMap[$argNode->name->value] = $argNode; } foreach ($fieldDef->args as $argDef) { $argNode = $argNodeMap[$argDef->name] ?? null; if ($argNode === null && $argDef->isRequired()) { $context->reportError(new Error( static::missingFieldArgMessage($fieldNode->name->value, $argDef->name, $argDef->getType()->toString()), [$fieldNode] )); } } return null; }, ], ]; } public static function missingFieldArgMessage(string $fieldName, string $argName, string $type): string { return "Field \"{$fieldName}\" argument \"{$argName}\" of type \"{$type}\" is required but not provided."; } }