Automattic\WooCommerce\Vendor\GraphQL\Executor

ReferenceExecutor::getFieldDefprotectedWC 1.0

This method looks up the field on the given type definition.

It has special casing for the two introspection fields, __schema and __typename. __typename is special because it can always be queried as a field, even in situations where no other fields are allowed, like on a Union. __schema could get automatically added to the query type, but that would require mutating type definitions, which would cause issues.

Method of the class: ReferenceExecutor{}

No Hooks.

Returns

null. Nothing (null).

Usage

// protected - for code of main (parent) or child class
$result = $this->getFieldDef( $schema, $parentType, $fieldName ): ?FieldDefinition;
$schema(Schema) (required)
.
$parentType(ObjectType) (required)
.
$fieldName(string) (required)
.

ReferenceExecutor::getFieldDef() code WC 10.9.1

protected function getFieldDef(Schema $schema, ObjectType $parentType, string $fieldName): ?FieldDefinition
{
    $this->schemaMetaFieldDef ??= Introspection::schemaMetaFieldDef();
    $this->typeMetaFieldDef ??= Introspection::typeMetaFieldDef();
    $this->typeNameMetaFieldDef ??= Introspection::typeNameMetaFieldDef();

    $queryType = $schema->getQueryType();

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

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

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

    return $parentType->findField($fieldName);
}