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

+48 -49
View File
@@ -55,18 +55,18 @@ use function sprintf;
class ReferenceExecutor implements ExecutorImplementation
{
/** @var object */
private static $UNDEFINED;
protected static $UNDEFINED;
/** @var ExecutionContext */
private $exeContext;
protected $exeContext;
/** @var SplObjectStorage */
private $subFieldCache;
protected $subFieldCache;
private function __construct(ExecutionContext $context)
protected function __construct(ExecutionContext $context)
{
if (! self::$UNDEFINED) {
self::$UNDEFINED = Utils::undefined();
if (! static::$UNDEFINED) {
static::$UNDEFINED = Utils::undefined();
}
$this->exeContext = $context;
$this->subFieldCache = new SplObjectStorage();
@@ -87,7 +87,7 @@ class ReferenceExecutor implements ExecutorImplementation
?string $operationName,
callable $fieldResolver
) : ExecutorImplementation {
$exeContext = self::buildExecutionContext(
$exeContext = static::buildExecutionContext(
$schema,
$documentNode,
$rootValue,
@@ -116,7 +116,7 @@ class ReferenceExecutor implements ExecutorImplementation
};
}
return new self($exeContext);
return new static($exeContext);
}
/**
@@ -129,7 +129,7 @@ class ReferenceExecutor implements ExecutorImplementation
*
* @return ExecutionContext|array<Error>
*/
private static function buildExecutionContext(
protected static function buildExecutionContext(
Schema $schema,
DocumentNode $documentNode,
$rootValue,
@@ -227,7 +227,7 @@ class ReferenceExecutor implements ExecutorImplementation
*
* @return ExecutionResult|Promise
*/
private function buildResponse($data)
protected function buildResponse($data)
{
if ($this->isPromise($data)) {
return $data->then(function ($resolved) {
@@ -248,7 +248,7 @@ class ReferenceExecutor implements ExecutorImplementation
*
* @return array<mixed>|Promise|stdClass|null
*/
private function executeOperation(OperationDefinitionNode $operation, $rootValue)
protected function executeOperation(OperationDefinitionNode $operation, $rootValue)
{
$type = $this->getOperationRootType($this->exeContext->schema, $operation);
$fields = $this->collectFields($type, $operation->selectionSet, new ArrayObject(), new ArrayObject());
@@ -290,7 +290,7 @@ class ReferenceExecutor implements ExecutorImplementation
*
* @throws Error
*/
private function getOperationRootType(Schema $schema, OperationDefinitionNode $operation) : ObjectType
protected function getOperationRootType(Schema $schema, OperationDefinitionNode $operation) : ObjectType
{
switch ($operation->operation) {
case 'query':
@@ -339,7 +339,7 @@ class ReferenceExecutor implements ExecutorImplementation
* returns an Interface or Union type, the "runtime type" will be the actual
* Object type returned by that field.
*/
private function collectFields(
protected function collectFields(
ObjectType $runtimeType,
SelectionSetNode $selectionSet,
ArrayObject $fields,
@@ -352,7 +352,7 @@ class ReferenceExecutor implements ExecutorImplementation
if (! $this->shouldIncludeNode($selection)) {
break;
}
$name = self::getFieldEntryKey($selection);
$name = static::getFieldEntryKey($selection);
if (! isset($fields[$name])) {
$fields[$name] = new ArrayObject();
}
@@ -402,7 +402,7 @@ class ReferenceExecutor implements ExecutorImplementation
*
* @param FragmentSpreadNode|FieldNode|InlineFragmentNode $node
*/
private function shouldIncludeNode(SelectionNode $node) : bool
protected function shouldIncludeNode(SelectionNode $node) : bool
{
$variableValues = $this->exeContext->variableValues;
$skipDirective = Directive::skipDirective();
@@ -427,7 +427,7 @@ class ReferenceExecutor implements ExecutorImplementation
/**
* Implements the logic to compute the key of a given fields entry
*/
private static function getFieldEntryKey(FieldNode $node) : string
protected static function getFieldEntryKey(FieldNode $node) : string
{
return $node->alias === null ? $node->name->value : $node->alias->value;
}
@@ -437,7 +437,7 @@ class ReferenceExecutor implements ExecutorImplementation
*
* @param FragmentDefinitionNode|InlineFragmentNode $fragment
*/
private function doesFragmentConditionMatch(Node $fragment, ObjectType $type) : bool
protected function doesFragmentConditionMatch(Node $fragment, ObjectType $type) : bool
{
$typeConditionNode = $fragment->typeCondition;
if ($typeConditionNode === null) {
@@ -463,7 +463,7 @@ class ReferenceExecutor implements ExecutorImplementation
*
* @return array<mixed>|Promise|stdClass
*/
private function executeFieldsSerially(ObjectType $parentType, $rootValue, array $path, ArrayObject $fields)
protected function executeFieldsSerially(ObjectType $parentType, $rootValue, array $path, ArrayObject $fields)
{
$result = $this->promiseReduce(
array_keys($fields->getArrayCopy()),
@@ -472,7 +472,7 @@ class ReferenceExecutor implements ExecutorImplementation
$fieldPath = $path;
$fieldPath[] = $responseName;
$result = $this->resolveField($parentType, $rootValue, $fieldNodes, $fieldPath);
if ($result === self::$UNDEFINED) {
if ($result === static::$UNDEFINED) {
return $results;
}
$promise = $this->getPromise($result);
@@ -492,11 +492,11 @@ class ReferenceExecutor implements ExecutorImplementation
if ($this->isPromise($result)) {
return $result->then(static function ($resolvedResults) {
return self::fixResultsIfEmptyArray($resolvedResults);
return static::fixResultsIfEmptyArray($resolvedResults);
});
}
return self::fixResultsIfEmptyArray($result);
return static::fixResultsIfEmptyArray($result);
}
/**
@@ -511,14 +511,14 @@ class ReferenceExecutor implements ExecutorImplementation
*
* @return array<mixed>|Throwable|mixed|null
*/
private function resolveField(ObjectType $parentType, $rootValue, ArrayObject $fieldNodes, array $path)
protected function resolveField(ObjectType $parentType, $rootValue, ArrayObject $fieldNodes, array $path)
{
$exeContext = $this->exeContext;
$fieldNode = $fieldNodes[0];
$fieldName = $fieldNode->name->value;
$fieldDef = $this->getFieldDef($exeContext->schema, $parentType, $fieldName);
if ($fieldDef === null) {
return self::$UNDEFINED;
return static::$UNDEFINED;
}
$returnType = $fieldDef->getType();
// The resolve function's optional 3rd argument is a context value that
@@ -574,7 +574,7 @@ class ReferenceExecutor implements ExecutorImplementation
* added to the query type, but that would require mutating type
* definitions, which would cause issues.
*/
private function getFieldDef(Schema $schema, ObjectType $parentType, string $fieldName) : ?FieldDefinition
protected function getFieldDef(Schema $schema, ObjectType $parentType, string $fieldName) : ?FieldDefinition
{
static $schemaMetaFieldDef, $typeMetaFieldDef, $typeNameMetaFieldDef;
$schemaMetaFieldDef = $schemaMetaFieldDef ?? Introspection::schemaMetaFieldDef();
@@ -591,9 +591,8 @@ class ReferenceExecutor implements ExecutorImplementation
if ($fieldName === $typeNameMetaFieldDef->name) {
return $typeNameMetaFieldDef;
}
$tmp = $parentType->getFields();
return $tmp[$fieldName] ?? null;
return $parentType->findField($fieldName);
}
/**
@@ -604,7 +603,7 @@ class ReferenceExecutor implements ExecutorImplementation
*
* @return Throwable|Promise|mixed
*/
private function resolveFieldValueOrError(
protected function resolveFieldValueOrError(
FieldDefinition $fieldDef,
FieldNode $fieldNode,
callable $resolveFn,
@@ -636,7 +635,7 @@ class ReferenceExecutor implements ExecutorImplementation
*
* @return array<mixed>|Promise|stdClass|null
*/
private function completeValueCatchingError(
protected function completeValueCatchingError(
Type $returnType,
ArrayObject $fieldNodes,
ResolveInfo $info,
@@ -676,7 +675,7 @@ class ReferenceExecutor implements ExecutorImplementation
*
* @throws Error
*/
private function handleFieldError($rawError, ArrayObject $fieldNodes, array $path, Type $returnType) : void
protected function handleFieldError($rawError, ArrayObject $fieldNodes, array $path, Type $returnType) : void
{
$error = Error::createLocatedError(
$rawError,
@@ -723,7 +722,7 @@ class ReferenceExecutor implements ExecutorImplementation
* @throws Error
* @throws Throwable
*/
private function completeValue(
protected function completeValue(
Type $returnType,
ArrayObject $fieldNodes,
ResolveInfo $info,
@@ -799,7 +798,7 @@ class ReferenceExecutor implements ExecutorImplementation
/**
* @param mixed $value
*/
private function isPromise($value) : bool
protected function isPromise($value) : bool
{
return $value instanceof Promise || $this->exeContext->promiseAdapter->isThenable($value);
}
@@ -810,7 +809,7 @@ class ReferenceExecutor implements ExecutorImplementation
*
* @param mixed $value
*/
private function getPromise($value) : ?Promise
protected function getPromise($value) : ?Promise
{
if ($value === null || $value instanceof Promise) {
return $value;
@@ -843,7 +842,7 @@ class ReferenceExecutor implements ExecutorImplementation
*
* @return Promise|mixed|null
*/
private function promiseReduce(array $values, callable $callback, $initialValue)
protected function promiseReduce(array $values, callable $callback, $initialValue)
{
return array_reduce(
$values,
@@ -871,7 +870,7 @@ class ReferenceExecutor implements ExecutorImplementation
*
* @throws Exception
*/
private function completeListValue(ListOfType $returnType, ArrayObject $fieldNodes, ResolveInfo $info, array $path, &$results)
protected function completeListValue(ListOfType $returnType, ArrayObject $fieldNodes, ResolveInfo $info, array $path, &$results)
{
$itemType = $returnType->getWrappedType();
Utils::invariant(
@@ -906,7 +905,7 @@ class ReferenceExecutor implements ExecutorImplementation
*
* @throws Exception
*/
private function completeLeafValue(LeafType $returnType, &$result)
protected function completeLeafValue(LeafType $returnType, &$result)
{
try {
return $returnType->serialize($result);
@@ -930,7 +929,7 @@ class ReferenceExecutor implements ExecutorImplementation
*
* @throws Error
*/
private function completeAbstractValue(
protected function completeAbstractValue(
AbstractType $returnType,
ArrayObject $fieldNodes,
ResolveInfo $info,
@@ -941,7 +940,7 @@ class ReferenceExecutor implements ExecutorImplementation
$typeCandidate = $returnType->resolveType($result, $exeContext->contextValue, $info);
if ($typeCandidate === null) {
$runtimeType = self::defaultTypeResolver($result, $exeContext->contextValue, $info, $returnType);
$runtimeType = static::defaultTypeResolver($result, $exeContext->contextValue, $info, $returnType);
} elseif (is_callable($typeCandidate)) {
$runtimeType = Schema::resolveType($typeCandidate);
} else {
@@ -1001,7 +1000,7 @@ class ReferenceExecutor implements ExecutorImplementation
*
* @return Promise|Type|string|null
*/
private function defaultTypeResolver($value, $contextValue, ResolveInfo $info, AbstractType $abstractType)
protected function defaultTypeResolver($value, $contextValue, ResolveInfo $info, AbstractType $abstractType)
{
// First, look for `__typename`.
if ($value !== null &&
@@ -1066,7 +1065,7 @@ class ReferenceExecutor implements ExecutorImplementation
*
* @throws Error
*/
private function completeObjectValue(
protected function completeObjectValue(
ObjectType $returnType,
ArrayObject $fieldNodes,
ResolveInfo $info,
@@ -1116,7 +1115,7 @@ class ReferenceExecutor implements ExecutorImplementation
*
* @return Error
*/
private function invalidReturnTypeError(
protected function invalidReturnTypeError(
ObjectType $returnType,
$result,
ArrayObject $fieldNodes
@@ -1135,7 +1134,7 @@ class ReferenceExecutor implements ExecutorImplementation
*
* @throws Error
*/
private function collectAndExecuteSubfields(
protected function collectAndExecuteSubfields(
ObjectType $returnType,
ArrayObject $fieldNodes,
array $path,
@@ -1151,7 +1150,7 @@ class ReferenceExecutor implements ExecutorImplementation
* type. Memoizing ensures the subfields are not repeatedly calculated, which
* saves overhead when resolving lists of values.
*/
private function collectSubFields(ObjectType $returnType, ArrayObject $fieldNodes) : ArrayObject
protected function collectSubFields(ObjectType $returnType, ArrayObject $fieldNodes) : ArrayObject
{
if (! isset($this->subFieldCache[$returnType])) {
$this->subFieldCache[$returnType] = new SplObjectStorage();
@@ -1186,7 +1185,7 @@ class ReferenceExecutor implements ExecutorImplementation
*
* @return Promise|stdClass|array<mixed>
*/
private function executeFields(ObjectType $parentType, $rootValue, array $path, ArrayObject $fields)
protected function executeFields(ObjectType $parentType, $rootValue, array $path, ArrayObject $fields)
{
$containsPromise = false;
$results = [];
@@ -1194,7 +1193,7 @@ class ReferenceExecutor implements ExecutorImplementation
$fieldPath = $path;
$fieldPath[] = $responseName;
$result = $this->resolveField($parentType, $rootValue, $fieldNodes, $fieldPath);
if ($result === self::$UNDEFINED) {
if ($result === static::$UNDEFINED) {
continue;
}
if (! $containsPromise && $this->isPromise($result)) {
@@ -1204,7 +1203,7 @@ class ReferenceExecutor implements ExecutorImplementation
}
// If there are no promises, we can just return the object
if (! $containsPromise) {
return self::fixResultsIfEmptyArray($results);
return static::fixResultsIfEmptyArray($results);
}
// Otherwise, results is a map from field name to the result of resolving that
@@ -1222,7 +1221,7 @@ class ReferenceExecutor implements ExecutorImplementation
*
* @return array<mixed>|stdClass|mixed
*/
private static function fixResultsIfEmptyArray($results)
protected static function fixResultsIfEmptyArray($results)
{
if ($results === []) {
return new stdClass();
@@ -1237,7 +1236,7 @@ class ReferenceExecutor implements ExecutorImplementation
*
* @param array<string, Promise|mixed> $assoc
*/
private function promiseForAssocArray(array $assoc) : Promise
protected function promiseForAssocArray(array $assoc) : Promise
{
$keys = array_keys($assoc);
$valuesAndPromises = array_values($assoc);
@@ -1249,7 +1248,7 @@ class ReferenceExecutor implements ExecutorImplementation
$resolvedResults[$keys[$i]] = $value;
}
return self::fixResultsIfEmptyArray($resolvedResults);
return static::fixResultsIfEmptyArray($resolvedResults);
});
}
@@ -1258,7 +1257,7 @@ class ReferenceExecutor implements ExecutorImplementation
* @param InterfaceType|UnionType $returnType
* @param mixed $result
*/
private function ensureValidRuntimeType(
protected function ensureValidRuntimeType(
$runtimeTypeOrName,
AbstractType $returnType,
ResolveInfo $info,