diff --git a/src/Executor/ReferenceExecutor.php b/src/Executor/ReferenceExecutor.php index 5bf1a4e0c..b179138a6 100644 --- a/src/Executor/ReferenceExecutor.php +++ b/src/Executor/ReferenceExecutor.php @@ -532,9 +532,8 @@ private function resolveField(ObjectType $parentType, $rootValue, $fieldNodes, $ // The resolve function's optional 4th argument is a collection of // information about the current execution state. $info = new ResolveInfo( - $fieldName, + $fieldDef, $fieldNodes, - $returnType, $parentType, $path, $exeContext->schema, diff --git a/src/Experimental/Executor/CoroutineExecutor.php b/src/Experimental/Executor/CoroutineExecutor.php index b754427cc..087898fec 100644 --- a/src/Experimental/Executor/CoroutineExecutor.php +++ b/src/Experimental/Executor/CoroutineExecutor.php @@ -401,9 +401,8 @@ private function spawn(CoroutineContext $ctx) $returnType = $fieldDefinition->getType(); $ctx->resolveInfo = new ResolveInfo( - $ctx->shared->fieldName, + $fieldDefinition, $ctx->shared->fieldNodes, - $returnType, $ctx->type, $ctx->path, $this->schema, diff --git a/src/Type/Definition/ResolveInfo.php b/src/Type/Definition/ResolveInfo.php index 822a0fa2b..4ca536ad3 100644 --- a/src/Type/Definition/ResolveInfo.php +++ b/src/Type/Definition/ResolveInfo.php @@ -21,20 +21,20 @@ class ResolveInfo { /** - * The name of the field being resolved. + * The definition of the field being resolved. * * @api - * @var string + * @var FieldDefinition */ - public $fieldName; + public $fieldDefinition; /** - * AST of all nodes referencing this field in the query. + * The name of the field being resolved. * * @api - * @var FieldNode[] + * @var string */ - public $fieldNodes = []; + public $fieldName; /** * Expected return type of the field being resolved. @@ -44,6 +44,14 @@ class ResolveInfo */ public $returnType; + /** + * AST of all nodes referencing this field in the query. + * + * @api + * @var FieldNode[] + */ + public $fieldNodes = []; + /** * Parent type of the field being resolved. * @@ -104,17 +112,15 @@ class ResolveInfo private $queryPlan; /** - * @param FieldNode[] $fieldNodes - * @param ScalarType|ObjectType|InterfaceType|UnionType|EnumType|ListOfType|NonNull $returnType - * @param string[][] $path - * @param FragmentDefinitionNode[] $fragments - * @param mixed|null $rootValue - * @param mixed[] $variableValues + * @param FieldNode[] $fieldNodes + * @param string[][] $path + * @param FragmentDefinitionNode[] $fragments + * @param mixed|null $rootValue + * @param mixed[] $variableValues */ public function __construct( - string $fieldName, + FieldDefinition $fieldDefinition, iterable $fieldNodes, - $returnType, ObjectType $parentType, array $path, Schema $schema, @@ -123,16 +129,17 @@ public function __construct( ?OperationDefinitionNode $operation, array $variableValues ) { - $this->fieldName = $fieldName; - $this->fieldNodes = $fieldNodes; - $this->returnType = $returnType; - $this->parentType = $parentType; - $this->path = $path; - $this->schema = $schema; - $this->fragments = $fragments; - $this->rootValue = $rootValue; - $this->operation = $operation; - $this->variableValues = $variableValues; + $this->fieldDefinition = $fieldDefinition; + $this->fieldName = $fieldDefinition->name; + $this->returnType = $fieldDefinition->getType(); + $this->fieldNodes = $fieldNodes; + $this->parentType = $parentType; + $this->path = $path; + $this->schema = $schema; + $this->fragments = $fragments; + $this->rootValue = $rootValue; + $this->operation = $operation; + $this->variableValues = $variableValues; } /** diff --git a/tests/Executor/ExecutorTest.php b/tests/Executor/ExecutorTest.php index eb8e4a12e..77ef6e938 100644 --- a/tests/Executor/ExecutorTest.php +++ b/tests/Executor/ExecutorTest.php @@ -12,6 +12,7 @@ use GraphQL\Tests\Executor\TestClasses\NotSpecial; use GraphQL\Tests\Executor\TestClasses\Special; use GraphQL\Type\Definition\EnumType; +use GraphQL\Type\Definition\FieldDefinition; use GraphQL\Type\Definition\InputObjectType; use GraphQL\Type\Definition\InterfaceType; use GraphQL\Type\Definition\ObjectType; @@ -295,6 +296,7 @@ public function testProvidesInfoAboutCurrentExecutionState() : void self::assertSame($rootValue, $info->rootValue); self::assertEquals($ast->definitions[0], $info->operation); self::assertEquals(['var' => '123'], $info->variableValues); + self::assertInstanceOf(FieldDefinition::class, $info->fieldDefinition); } /** diff --git a/tests/Type/ResolveInfoTest.php b/tests/Type/ResolveInfoTest.php index d05a44c35..8b7e93065 100644 --- a/tests/Type/ResolveInfoTest.php +++ b/tests/Type/ResolveInfoTest.php @@ -5,6 +5,7 @@ namespace GraphQL\Tests\Type; use GraphQL\GraphQL; +use GraphQL\Type\Definition\FieldDefinition; use GraphQL\Type\Definition\ObjectType; use GraphQL\Type\Definition\ResolveInfo; use GraphQL\Type\Definition\Type;