From a27291a3b6552c0cdc8688e33ce22c0bfc675ebb Mon Sep 17 00:00:00 2001 From: Ruud Kamphuis Date: Mon, 11 Nov 2024 19:12:39 +0100 Subject: [PATCH] Store introspection field definitions as property Since the ReferenceExecutor is an instance, we can keep this cache on the instance. Great! --- src/Executor/ReferenceExecutor.php | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/Executor/ReferenceExecutor.php b/src/Executor/ReferenceExecutor.php index 303287080..224d50aef 100644 --- a/src/Executor/ReferenceExecutor.php +++ b/src/Executor/ReferenceExecutor.php @@ -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)) { @@ -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);