Skip to content

Commit

Permalink
Store introspection field definitions as property
Browse files Browse the repository at this point in the history
Since the ReferenceExecutor is an instance, we can keep this cache on the instance. Great!
  • Loading branch information
ruudk committed Nov 11, 2024
1 parent 9954572 commit 07d754d
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/Executor/ReferenceExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ class ReferenceExecutor implements ExecutorImplementation
*/
protected \SplObjectStorage $fieldArgsCache;

protected FieldDefinition $schemaMetaFieldDef;
protected FieldDefinition $typeMetaFieldDef;
protected FieldDefinition $typeNameMetaFieldDef;

protected function __construct(ExecutionContext $context)
{
if (! isset(static::$UNDEFINED)) {
Expand Down Expand Up @@ -701,23 +705,22 @@ protected function resolveField(
*/
protected function getFieldDef(Schema $schema, ObjectType $parentType, string $fieldName): ?FieldDefinition
{
static $schemaMetaFieldDef, $typeMetaFieldDef, $typeNameMetaFieldDef;
$schemaMetaFieldDef ??= Introspection::schemaMetaFieldDef();
$typeMetaFieldDef ??= Introspection::typeMetaFieldDef();
$typeNameMetaFieldDef ??= Introspection::typeNameMetaFieldDef();
$this->schemaMetaFieldDef ??= Introspection::schemaMetaFieldDef();
$this->typeMetaFieldDef ??= Introspection::typeMetaFieldDef();
$this->typeNameMetaFieldDef ??= Introspection::typeNameMetaFieldDef();

$queryType = $schema->getQueryType();

if ($fieldName === $schemaMetaFieldDef->name && $queryType === $parentType) {
return $schemaMetaFieldDef;
if ($fieldName === $this->schemaMetaFieldDef->name && $queryType === $parentType) {
return $this->schemaMetaFieldDef;
}

if ($fieldName === $typeMetaFieldDef->name && $queryType === $parentType) {
return $typeMetaFieldDef;
if ($fieldName === $this->typeMetaFieldDef->name && $queryType === $parentType) {
return $this->typeMetaFieldDef;
}

if ($fieldName === $typeNameMetaFieldDef->name) {
return $typeNameMetaFieldDef;
if ($fieldName === $this->typeNameMetaFieldDef->name) {
return $this->typeNameMetaFieldDef;
}

return $parentType->findField($fieldName);
Expand Down

0 comments on commit 07d754d

Please sign in to comment.