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 12, 2024
1 parent 897f46b commit a27291a
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/Executor/ReferenceExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ 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 +707,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 a27291a

Please sign in to comment.