Version 4.7.6

This commit is contained in:
Neo committed 2025-12-19 16:05:19 -08:00
1 parent 8ba7d43898
commit 7b7404e741
1085 files changed
+30590 -7837

No files matched your search

@@ -85,15 +85,13 @@ class FieldsOnCorrectType extends ValidationRule
$interfaceUsageCount = [];
foreach ($schema->getPossibleTypes($type) as $possibleType) {
$fields = $possibleType->getFields();
if (! isset($fields[$fieldName])) {
if (! $possibleType->hasField($fieldName)) {
continue;
}
// This object type defines this field.
$suggestedObjectTypes[] = $possibleType->name;
foreach ($possibleType->getInterfaces() as $possibleInterface) {
$fields = $possibleInterface->getFields();
if (! isset($fields[$fieldName])) {
if (! $possibleInterface->hasField($fieldName)) {
continue;
}
// This interface type defines this field.
@@ -128,7 +126,7 @@ class FieldsOnCorrectType extends ValidationRule
private function getSuggestedFieldNames(Schema $schema, $type, $fieldName)
{
if ($type instanceof ObjectType || $type instanceof InterfaceType) {
$possibleFieldNames = array_keys($type->getFields());
$possibleFieldNames = $type->getFieldNames();
return Utils::suggestionList($fieldName, $possibleFieldNames);
}
@@ -250,10 +250,10 @@ class OverlappingFieldsCanBeMerged extends ValidationRule
$fieldName = $selection->name->value;
$fieldDef = null;
if ($parentType instanceof ObjectType ||
$parentType instanceof InterfaceType) {
$tmp = $parentType->getFields();
if (isset($tmp[$fieldName])) {
$fieldDef = $tmp[$fieldName];
$parentType instanceof InterfaceType
) {
if ($parentType->hasField($fieldName)) {
$fieldDef = $parentType->getField($fieldName);
}
}
$responseName = $selection->alias ? $selection->alias->value : $fieldName;
@@ -10,13 +10,14 @@ use GraphQL\Language\AST\FragmentDefinitionNode;
use GraphQL\Language\AST\FragmentSpreadNode;
use GraphQL\Language\AST\InlineFragmentNode;
use GraphQL\Language\AST\SelectionSetNode;
use GraphQL\Type\Definition\HasFieldsType;
use GraphQL\Type\Definition\InputObjectType;
use GraphQL\Type\Definition\Type;
use GraphQL\Type\Introspection;
use GraphQL\Utils\TypeInfo;
use GraphQL\Validator\ValidationContext;
use InvalidArgumentException;
use function class_alias;
use function method_exists;
use function sprintf;
abstract class QuerySecurityRule extends ValidationRule
@@ -117,8 +118,7 @@ abstract class QuerySecurityRule extends ValidationRule
case $selection instanceof FieldNode:
$fieldName = $selection->name->value;
$fieldDef = null;
if ($parentType && method_exists($parentType, 'getFields')) {
$tmp = $parentType->getFields();
if ($parentType instanceof HasFieldsType || $parentType instanceof InputObjectType) {
$schemaMetaFieldDef = Introspection::schemaMetaFieldDef();
$typeMetaFieldDef = Introspection::typeMetaFieldDef();
$typeNameMetaFieldDef = Introspection::typeNameMetaFieldDef();
@@ -129,8 +129,8 @@ abstract class QuerySecurityRule extends ValidationRule
$fieldDef = $typeMetaFieldDef;
} elseif ($fieldName === $typeNameMetaFieldDef->name) {
$fieldDef = $typeNameMetaFieldDef;
} elseif (isset($tmp[$fieldName])) {
$fieldDef = $tmp[$fieldName];
} elseif ($parentType->hasField($fieldName)) {
$fieldDef = $parentType->getField($fieldName);
}
}
$responseName = $this->getFieldName($selection);
@@ -34,6 +34,7 @@ class UniqueDirectivesPerLocation extends ValidationRule
public function getASTVisitor(ASTValidationContext $context)
{
/** @var array<string, true> $uniqueDirectiveMap */
$uniqueDirectiveMap = [];
$schema = $context->getSchema();
@@ -41,16 +42,22 @@ class UniqueDirectivesPerLocation extends ValidationRule
? $schema->getDirectives()
: Directive::getInternalDirectives();
foreach ($definedDirectives as $directive) {
$uniqueDirectiveMap[$directive->name] = ! $directive->isRepeatable;
if ($directive->isRepeatable) {
continue;
}
$uniqueDirectiveMap[$directive->name] = true;
}
$astDefinitions = $context->getDocument()->definitions;
foreach ($astDefinitions as $definition) {
if (! ($definition instanceof DirectiveDefinitionNode)) {
if (! ($definition instanceof DirectiveDefinitionNode)
|| $definition->repeatable
) {
continue;
}
$uniqueDirectiveMap[$definition->name->value] = $definition->repeatable;
$uniqueDirectiveMap[$definition->name->value] = true;
}
return [
@@ -81,7 +81,7 @@ class ValuesOfCorrectType extends ValidationRule
return null;
},
NodeKind::OBJECT => function (ObjectValueNode $node) use ($context, &$fieldName) {
NodeKind::OBJECT => function (ObjectValueNode $node) use ($context, &$fieldName) : ?VisitorOperation {
// Note: TypeInfo will traverse into a list's item type, so look to the
// parent input type to check if it is a list.
$type = Type::getNamedType($context->getInputType());
@@ -116,6 +116,8 @@ class ValuesOfCorrectType extends ValidationRule
)
);
}
return null;
},
NodeKind::OBJECT_FIELD => static function (ObjectFieldNode $node) use ($context) : void {
$parentType = Type::getNamedType($context->getParentInputType());
@@ -31,6 +31,7 @@ use GraphQL\Utils\TypeInfo;
use SplObjectStorage;
use function array_merge;
use function array_pop;
use function assert;
use function count;
/**
@@ -180,16 +181,15 @@ class ValidationContext extends ASTValidationContext
while (count($setsToVisit) > 0) {
$set = array_pop($setsToVisit);
for ($i = 0, $selectionCount = count($set->selections); $i < $selectionCount; $i++) {
$selection = $set->selections[$i];
foreach ($set->selections as $selection) {
if ($selection instanceof FragmentSpreadNode) {
$spreads[] = $selection;
} elseif ($selection instanceof FieldNode || $selection instanceof InlineFragmentNode) {
if ($selection->selectionSet) {
$setsToVisit[] = $selection->selectionSet;
}
} else {
throw InvariantViolation::shouldNotHappen();
assert($selection instanceof FieldNode || $selection instanceof InlineFragmentNode);
$selectionSet = $selection->selectionSet;
if ($selectionSet !== null) {
$setsToVisit[] = $selectionSet;
}
}
}
}