vendor/shopware/core/Framework/DataAbstractionLayer/Dbal/EntityDefinitionQueryHelper.php line 517

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Framework\DataAbstractionLayer\Dbal;
  3. use Doctrine\DBAL\Connection;
  4. use Shopware\Core\Defaults;
  5. use Shopware\Core\Framework\Context;
  6. use Shopware\Core\Framework\DataAbstractionLayer\Dbal\Exception\FieldAccessorBuilderNotFoundException;
  7. use Shopware\Core\Framework\DataAbstractionLayer\Dbal\Exception\UnmappedFieldException;
  8. use Shopware\Core\Framework\DataAbstractionLayer\Dbal\FieldResolver\FieldResolverContext;
  9. use Shopware\Core\Framework\DataAbstractionLayer\EntityDefinition;
  10. use Shopware\Core\Framework\DataAbstractionLayer\Field\AssociationField;
  11. use Shopware\Core\Framework\DataAbstractionLayer\Field\Field;
  12. use Shopware\Core\Framework\DataAbstractionLayer\Field\FkField;
  13. use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\Inherited;
  14. use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\PrimaryKey;
  15. use Shopware\Core\Framework\DataAbstractionLayer\Field\IdField;
  16. use Shopware\Core\Framework\DataAbstractionLayer\Field\ManyToManyAssociationField;
  17. use Shopware\Core\Framework\DataAbstractionLayer\Field\ReferenceVersionField;
  18. use Shopware\Core\Framework\DataAbstractionLayer\Field\StorageAware;
  19. use Shopware\Core\Framework\DataAbstractionLayer\Field\TranslatedField;
  20. use Shopware\Core\Framework\DataAbstractionLayer\Field\VersionField;
  21. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  22. use Shopware\Core\Framework\DataAbstractionLayer\Search\CriteriaPartInterface;
  23. use Shopware\Core\Framework\Log\Package;
  24. use Shopware\Core\Framework\Uuid\Uuid;
  25. /**
  26.  * This class acts only as helper/common class for all dbal operations for entity definitions.
  27.  * It knows how an association should be joined, how a parent-child inheritance should act, how translation chains work, ...
  28.  *
  29.  * @deprecated tag:v6.5.0 - reason:becomes-internal - Will be internal
  30.  */
  31. #[Package('core')]
  32. class EntityDefinitionQueryHelper
  33. {
  34.     public const HAS_TO_MANY_JOIN 'has_to_many_join';
  35.     public static function escape(string $string): string
  36.     {
  37.         if (mb_strpos($string'`') !== false) {
  38.             throw new \InvalidArgumentException('Backtick not allowed in identifier');
  39.         }
  40.         return '`' $string '`';
  41.     }
  42.     public static function columnExists(Connection $connectionstring $tablestring $column): bool
  43.     {
  44.         $exists $connection->fetchOne(
  45.             'SHOW COLUMNS FROM ' self::escape($table) . ' WHERE `Field` LIKE :column',
  46.             ['column' => $column]
  47.         );
  48.         return !empty($exists);
  49.     }
  50.     /**
  51.      * @return list<Field>
  52.      */
  53.     public static function getFieldsOfAccessor(EntityDefinition $definitionstring $accessorbool $resolveTranslated true): array
  54.     {
  55.         $parts explode('.'$accessor);
  56.         if ($definition->getEntityName() === $parts[0]) {
  57.             array_shift($parts);
  58.         }
  59.         $accessorFields = [];
  60.         $source $definition;
  61.         foreach ($parts as $part) {
  62.             if ($part === 'extensions') {
  63.                 continue;
  64.             }
  65.             $fields $source->getFields();
  66.             $field $fields->get($part);
  67.             // continue if the current part is not a real field to allow access on collections
  68.             if (!$field) {
  69.                 continue;
  70.             }
  71.             if ($field instanceof TranslatedField && $resolveTranslated) {
  72.                 /** @var EntityDefinition $source */
  73.                 $source $source->getTranslationDefinition();
  74.                 $fields $source->getFields();
  75.                 $accessorFields[] = $fields->get($part);
  76.                 continue;
  77.             }
  78.             if ($field instanceof TranslatedField && !$resolveTranslated) {
  79.                 $accessorFields[] = $field;
  80.                 continue;
  81.             }
  82.             $accessorFields[] = $field;
  83.             if (!$field instanceof AssociationField) {
  84.                 break;
  85.             }
  86.             $source $field->getReferenceDefinition();
  87.             if ($field instanceof ManyToManyAssociationField) {
  88.                 $source $field->getToManyReferenceDefinition();
  89.             }
  90.         }
  91.         return array_filter($accessorFields);
  92.     }
  93.     /**
  94.      * Returns the field instance of the provided fieldName.
  95.      *
  96.      * @example
  97.      *
  98.      * fieldName => 'product.name'
  99.      * Returns the (new TranslatedField('name')) declaration
  100.      *
  101.      * Allows additionally nested referencing
  102.      *
  103.      * fieldName => 'category.products.name'
  104.      * Returns as well the above field definition
  105.      */
  106.     public function getField(string $fieldNameEntityDefinition $definitionstring $rootbool $resolveTranslated true): ?Field
  107.     {
  108.         $original $fieldName;
  109.         $prefix $root '.';
  110.         if (mb_strpos($fieldName$prefix) === 0) {
  111.             $fieldName mb_substr($fieldNamemb_strlen($prefix));
  112.         } else {
  113.             $original $prefix $original;
  114.         }
  115.         $fields $definition->getFields();
  116.         $isAssociation mb_strpos($fieldName'.') !== false;
  117.         if (!$isAssociation && $fields->has($fieldName)) {
  118.             return $fields->get($fieldName);
  119.         }
  120.         $associationKey explode('.'$fieldName);
  121.         $associationKey array_shift($associationKey);
  122.         $field $fields->get($associationKey);
  123.         if ($field instanceof TranslatedField && $resolveTranslated) {
  124.             return self::getTranslatedField($definition$field);
  125.         }
  126.         if ($field instanceof TranslatedField) {
  127.             return $field;
  128.         }
  129.         if (!$field instanceof AssociationField) {
  130.             return $field;
  131.         }
  132.         $referenceDefinition $field->getReferenceDefinition();
  133.         if ($field instanceof ManyToManyAssociationField) {
  134.             $referenceDefinition $field->getToManyReferenceDefinition();
  135.         }
  136.         return $this->getField(
  137.             $original,
  138.             $referenceDefinition,
  139.             $root '.' $field->getPropertyName()
  140.         );
  141.     }
  142.     /**
  143.      * Builds the sql field accessor for the provided field.
  144.      *
  145.      * @example
  146.      *
  147.      * fieldName => product.taxId
  148.      * root      => product
  149.      * returns   => `product`.`tax_id`
  150.      *
  151.      * This function is also used for complex field accessors like JsonArray Field, JsonObject fields.
  152.      * It considers the translation and parent-child inheritance.
  153.      *
  154.      * fieldName => product.name
  155.      * root      => product
  156.      * return    => COALESCE(`product.translation`.`name`,`product.parent.translation`.`name`)
  157.      *
  158.      * @throws UnmappedFieldException
  159.      */
  160.     public function getFieldAccessor(string $fieldNameEntityDefinition $definitionstring $rootContext $context): string
  161.     {
  162.         $fieldName str_replace('extensions.'''$fieldName);
  163.         $original $fieldName;
  164.         $prefix $root '.';
  165.         if (str_starts_with($fieldName$prefix)) {
  166.             $fieldName mb_substr($fieldNamemb_strlen($prefix));
  167.         } else {
  168.             $original $prefix $original;
  169.         }
  170.         $fields $definition->getFields();
  171.         if ($fields->has($fieldName)) {
  172.             $field $fields->get($fieldName);
  173.             return $this->buildInheritedAccessor($field$root$definition$context$fieldName);
  174.         }
  175.         $parts explode('.'$fieldName);
  176.         $associationKey array_shift($parts);
  177.         if ($associationKey === 'extensions') {
  178.             $associationKey array_shift($parts);
  179.         }
  180.         if (!\is_string($associationKey) || !$fields->has($associationKey)) {
  181.             throw new UnmappedFieldException($original$definition);
  182.         }
  183.         $field $fields->get($associationKey);
  184.         //case for json object fields, other fields has now same option to act with more point notations but hasn't to be an association field. E.g. price.gross
  185.         if (!$field instanceof AssociationField && ($field instanceof StorageAware || $field instanceof TranslatedField)) {
  186.             return $this->buildInheritedAccessor($field$root$definition$context$fieldName);
  187.         }
  188.         if (!$field instanceof AssociationField) {
  189.             throw new \RuntimeException(sprintf('Expected field "%s" to be instance of %s'$associationKeyAssociationField::class));
  190.         }
  191.         $referenceDefinition $field->getReferenceDefinition();
  192.         if ($field instanceof ManyToManyAssociationField) {
  193.             $referenceDefinition $field->getToManyReferenceDefinition();
  194.         }
  195.         return $this->getFieldAccessor(
  196.             $original,
  197.             $referenceDefinition,
  198.             $root '.' $field->getPropertyName(),
  199.             $context
  200.         );
  201.     }
  202.     public static function getAssociationPath(string $accessorEntityDefinition $definition): ?string
  203.     {
  204.         $fields self::getFieldsOfAccessor($definition$accessor);
  205.         $path = [];
  206.         foreach ($fields as $field) {
  207.             if (!$field instanceof AssociationField) {
  208.                 break;
  209.             }
  210.             $path[] = $field->getPropertyName();
  211.         }
  212.         if (empty($path)) {
  213.             return null;
  214.         }
  215.         return implode('.'$path);
  216.     }
  217.     /**
  218.      * Creates the basic root query for the provided entity definition and application context.
  219.      * It considers the current context version.
  220.      */
  221.     public function getBaseQuery(QueryBuilder $queryEntityDefinition $definitionContext $context): QueryBuilder
  222.     {
  223.         $table $definition->getEntityName();
  224.         $query->from(self::escape($table));
  225.         $useVersionFallback // only applies for versioned entities
  226.             $definition->isVersionAware()
  227.             // only add live fallback if the current version isn't the live version
  228.             && $context->getVersionId() !== Defaults::LIVE_VERSION
  229.             // sub entities have no live fallback
  230.             && $definition->getParentDefinition() === null;
  231.         if ($useVersionFallback) {
  232.             $this->joinVersion($query$definition$definition->getEntityName(), $context);
  233.         } elseif ($definition->isVersionAware()) {
  234.             $versionIdField array_filter(
  235.                 $definition->getPrimaryKeys()->getElements(),
  236.                 function ($f) {
  237.                     return $f instanceof VersionField || $f instanceof ReferenceVersionField;
  238.                 }
  239.             );
  240.             if (!$versionIdField) {
  241.                 throw new \RuntimeException('Missing `VersionField` in `' $definition->getClass() . '`');
  242.             }
  243.             /** @var FkField $versionIdField */
  244.             $versionIdField array_shift($versionIdField);
  245.             $query->andWhere(self::escape($table) . '.' self::escape($versionIdField->getStorageName()) . ' = :version');
  246.             $query->setParameter('version'Uuid::fromHexToBytes($context->getVersionId()));
  247.         }
  248.         return $query;
  249.     }
  250.     /**
  251.      * Used for dynamic sql joins. In case that the given fieldName is unknown or event nested with multiple association
  252.      * roots, the function can resolve each association part of the field name, even if one part of the fieldName contains a translation or event inherited data field.
  253.      */
  254.     public function resolveAccessor(
  255.         string $accessor,
  256.         EntityDefinition $definition,
  257.         string $root,
  258.         QueryBuilder $query,
  259.         Context $context,
  260.         ?CriteriaPartInterface $criteriaPart null
  261.     ): void {
  262.         $accessor str_replace('extensions.'''$accessor);
  263.         $parts explode('.'$accessor);
  264.         if ($parts[0] === $root) {
  265.             unset($parts[0]);
  266.         }
  267.         $alias $root;
  268.         $path = [$root];
  269.         $rootDefinition $definition;
  270.         foreach ($parts as $part) {
  271.             $field $definition->getFields()->get($part);
  272.             if ($field === null) {
  273.                 return;
  274.             }
  275.             $resolver $field->getResolver();
  276.             if ($resolver === null) {
  277.                 continue;
  278.             }
  279.             if ($field instanceof AssociationField) {
  280.                 $path[] = $field->getPropertyName();
  281.             }
  282.             $currentPath implode('.'$path);
  283.             $resolverContext = new FieldResolverContext($currentPath$alias$field$definition$rootDefinition$query$context$criteriaPart);
  284.             $alias $this->callResolver($resolverContext);
  285.             if (!$field instanceof AssociationField) {
  286.                 return;
  287.             }
  288.             $definition $field->getReferenceDefinition();
  289.             if ($field instanceof ManyToManyAssociationField) {
  290.                 $definition $field->getToManyReferenceDefinition();
  291.             }
  292.             if ($definition->isInheritanceAware() && $context->considerInheritance() && $parent $definition->getField('parent')) {
  293.                 $resolverContext = new FieldResolverContext($currentPath$alias$parent$definition$rootDefinition$query$context$criteriaPart);
  294.                 $this->callResolver($resolverContext);
  295.             }
  296.         }
  297.     }
  298.     public function resolveField(Field $fieldEntityDefinition $definitionstring $rootQueryBuilder $queryContext $context): void
  299.     {
  300.         $resolver $field->getResolver();
  301.         if ($resolver === null) {
  302.             return;
  303.         }
  304.         $resolver->join(new FieldResolverContext($root$root$field$definition$definition$query$contextnull));
  305.     }
  306.     /**
  307.      * Adds the full translation select part to the provided sql query.
  308.      * Considers the parent-child inheritance and provided context language inheritance.
  309.      * The raw parameter allows to skip the parent-child inheritance.
  310.      *
  311.      * @param array<string, mixed> $partial
  312.      */
  313.     public function addTranslationSelect(string $rootEntityDefinition $definitionQueryBuilder $queryContext $context, array $partial = []): void
  314.     {
  315.         $translationDefinition $definition->getTranslationDefinition();
  316.         if (!$translationDefinition) {
  317.             return;
  318.         }
  319.         $fields $translationDefinition->getFields();
  320.         if (!empty($partial)) {
  321.             $fields $translationDefinition->getFields()->filter(function (Field $field) use ($partial) {
  322.                 return $field->is(PrimaryKey::class)
  323.                     || isset($partial[$field->getPropertyName()])
  324.                     || $field instanceof FkField;
  325.             });
  326.         }
  327.         $inherited $context->considerInheritance() && $definition->isInheritanceAware();
  328.         $chain EntityDefinitionQueryHelper::buildTranslationChain($root$context$inherited);
  329.         /** @var TranslatedField $field */
  330.         foreach ($fields as $field) {
  331.             if (!$field instanceof StorageAware) {
  332.                 continue;
  333.             }
  334.             $selects = [];
  335.             foreach ($chain as $select) {
  336.                 $vars = [
  337.                     '#root#' => $select,
  338.                     '#field#' => $field->getPropertyName(),
  339.                 ];
  340.                 $query->addSelect(str_replace(
  341.                     array_keys($vars),
  342.                     array_values($vars),
  343.                     EntityDefinitionQueryHelper::escape('#root#.#field#')
  344.                 ));
  345.                 $selects[] = str_replace(
  346.                     array_keys($vars),
  347.                     array_values($vars),
  348.                     self::escape('#root#.#field#')
  349.                 );
  350.             }
  351.             //check if current field is a translated field of the origin definition
  352.             $origin $definition->getFields()->get($field->getPropertyName());
  353.             if (!$origin instanceof TranslatedField) {
  354.                 continue;
  355.             }
  356.             $selects[] = self::escape($root '.translation.' $field->getPropertyName());
  357.             //add selection for resolved parent-child and language inheritance
  358.             $query->addSelect(
  359.                 sprintf('COALESCE(%s)'implode(','$selects)) . ' as '
  360.                 self::escape($root '.' $field->getPropertyName())
  361.             );
  362.         }
  363.     }
  364.     public function joinVersion(QueryBuilder $queryEntityDefinition $definitionstring $rootContext $context): void
  365.     {
  366.         $table $definition->getEntityName();
  367.         $versionRoot $root '_version';
  368.         $query->andWhere(
  369.             str_replace(
  370.                 ['#root#''#table#''#version#'],
  371.                 [self::escape($root), self::escape($table), self::escape($versionRoot)],
  372.                 '#root#.version_id = COALESCE(
  373.                     (SELECT DISTINCT version_id FROM #table# AS #version# WHERE #version#.`id` = #root#.`id` AND `version_id` = :version),
  374.                     :liveVersion
  375.                 )'
  376.             )
  377.         );
  378.         $query->setParameter('liveVersion'Uuid::fromHexToBytes(Defaults::LIVE_VERSION));
  379.         $query->setParameter('version'Uuid::fromHexToBytes($context->getVersionId()));
  380.     }
  381.     public static function getTranslatedField(EntityDefinition $definitionTranslatedField $translatedField): Field
  382.     {
  383.         $translationDefinition $definition->getTranslationDefinition();
  384.         if ($translationDefinition === null) {
  385.             throw new \RuntimeException(sprintf('Entity %s has no translation definition'$definition->getEntityName()));
  386.         }
  387.         $field $translationDefinition->getFields()->get($translatedField->getPropertyName());
  388.         if ($field === null || !$field instanceof StorageAware || !$field instanceof Field) {
  389.             throw new \RuntimeException(
  390.                 sprintf(
  391.                     'Missing translated storage aware property %s in %s',
  392.                     $translatedField->getPropertyName(),
  393.                     $translationDefinition->getEntityName()
  394.                 )
  395.             );
  396.         }
  397.         return $field;
  398.     }
  399.     /**
  400.      * @return list<string>
  401.      */
  402.     public static function buildTranslationChain(string $rootContext $contextbool $includeParent): array
  403.     {
  404.         $count = \count($context->getLanguageIdChain()) - 1;
  405.         for ($i $count$i >= 1; --$i) {
  406.             $chain[] = $root '.translation.fallback_' $i;
  407.             if ($includeParent) {
  408.                 $chain[] = $root '.parent.translation.fallback_' $i;
  409.             }
  410.         }
  411.         $chain[] = $root '.translation';
  412.         if ($includeParent) {
  413.             $chain[] = $root '.parent.translation';
  414.         }
  415.         return $chain;
  416.     }
  417.     public function addIdCondition(Criteria $criteriaEntityDefinition $definitionQueryBuilder $query): void
  418.     {
  419.         $primaryKeys $criteria->getIds();
  420.         $primaryKeys array_values($primaryKeys);
  421.         if (empty($primaryKeys)) {
  422.             return;
  423.         }
  424.         if (!\is_array($primaryKeys[0]) || \count($primaryKeys[0]) === 1) {
  425.             $primaryKeyField $definition->getPrimaryKeys()->first();
  426.             if ($primaryKeyField instanceof IdField || $primaryKeyField instanceof FkField) {
  427.                 $primaryKeys array_map(function ($id) {
  428.                     if (\is_array($id)) {
  429.                         /** @var string $shiftedId */
  430.                         $shiftedId array_shift($id);
  431.                         return Uuid::fromHexToBytes($shiftedId);
  432.                     }
  433.                     return Uuid::fromHexToBytes($id);
  434.                 }, $primaryKeys);
  435.             }
  436.             if (!$primaryKeyField instanceof StorageAware) {
  437.                 throw new \RuntimeException('Primary key fields has to be an instance of StorageAware');
  438.             }
  439.             $query->andWhere(sprintf(
  440.                 '%s.%s IN (:ids)',
  441.                 EntityDefinitionQueryHelper::escape($definition->getEntityName()),
  442.                 EntityDefinitionQueryHelper::escape($primaryKeyField->getStorageName())
  443.             ));
  444.             $query->setParameter('ids'$primaryKeysConnection::PARAM_STR_ARRAY);
  445.             return;
  446.         }
  447.         $this->addIdConditionWithOr($criteria$definition$query);
  448.     }
  449.     private function callResolver(FieldResolverContext $context): string
  450.     {
  451.         $resolver $context->getField()->getResolver();
  452.         if (!$resolver) {
  453.             return $context->getAlias();
  454.         }
  455.         return $resolver->join($context);
  456.     }
  457.     private function addIdConditionWithOr(Criteria $criteriaEntityDefinition $definitionQueryBuilder $query): void
  458.     {
  459.         $wheres = [];
  460.         foreach ($criteria->getIds() as $primaryKey) {
  461.             if (!\is_array($primaryKey)) {
  462.                 $primaryKey = ['id' => $primaryKey];
  463.             }
  464.             $where = [];
  465.             foreach ($primaryKey as $propertyName => $value) {
  466.                 $field $definition->getFields()->get($propertyName);
  467.                 /*
  468.                  * @deprecated tag:v6.5.0 - with 6.5.0 the only passing the propertyName will be supported
  469.                  */
  470.                 if (!$field) {
  471.                     $field $definition->getFields()->getByStorageName($propertyName);
  472.                 }
  473.                 if (!$field) {
  474.                     throw new UnmappedFieldException($propertyName$definition);
  475.                 }
  476.                 if (!$field instanceof StorageAware) {
  477.                     throw new \RuntimeException('Only storage aware fields are supported in read condition');
  478.                 }
  479.                 if ($field instanceof IdField || $field instanceof FkField) {
  480.                     $value Uuid::fromHexToBytes($value);
  481.                 }
  482.                 $key 'pk' Uuid::randomHex();
  483.                 $accessor EntityDefinitionQueryHelper::escape($definition->getEntityName()) . '.' EntityDefinitionQueryHelper::escape($field->getStorageName());
  484.                 /*
  485.                  * @deprecated tag:v6.5.0 - check for duplication in accessors will be removed,
  486.                  * when we only support propertyNames to be used in search and when IdSearchResult only returns the propertyNames
  487.                  */
  488.                 if (!\array_key_exists($accessor$where)) {
  489.                     $where[$accessor] = $accessor ' = :' $key;
  490.                     $query->setParameter($key$value);
  491.                 }
  492.             }
  493.             $wheres[] = '(' implode(' AND '$where) . ')';
  494.         }
  495.         $wheres implode(' OR '$wheres);
  496.         $query->andWhere($wheres);
  497.     }
  498.     /**
  499.      * @param list<string> $chain
  500.      */
  501.     private function getTranslationFieldAccessor(Field $fieldstring $accessor, array $chainContext $context): string
  502.     {
  503.         if (!$field instanceof StorageAware) {
  504.             throw new \RuntimeException('Only storage aware fields are supported as translated field');
  505.         }
  506.         $selects = [];
  507.         foreach ($chain as $part) {
  508.             $select $this->buildFieldSelector($part$field$context$accessor);
  509.             $selects[] = str_replace(
  510.                 '`.' self::escape($field->getStorageName()),
  511.                 '.' $field->getPropertyName() . '`',
  512.                 $select
  513.             );
  514.         }
  515.         /*
  516.          * Simplified Example:
  517.          * COALESCE(
  518.              JSON_UNQUOTE(JSON_EXTRACT(`tbl.translation.fallback_2`.`translated_attributes`, '$.path')) AS datetime(3), # child language
  519.              JSON_UNQUOTE(JSON_EXTRACT(`tbl.translation.fallback_1`.`translated_attributes`, '$.path')) AS datetime(3), # root language
  520.              JSON_UNQUOTE(JSON_EXTRACT(`tbl.translation`.`translated_attributes`, '$.path')) AS datetime(3) # system language
  521.            );
  522.          */
  523.         return sprintf('COALESCE(%s)'implode(','$selects));
  524.     }
  525.     private function buildInheritedAccessor(
  526.         Field $field,
  527.         string $root,
  528.         EntityDefinition $definition,
  529.         Context $context,
  530.         string $original
  531.     ): string {
  532.         if ($field instanceof TranslatedField) {
  533.             $inheritedChain self::buildTranslationChain($root$context$definition->isInheritanceAware() && $context->considerInheritance());
  534.             $translatedField self::getTranslatedField($definition$field);
  535.             return $this->getTranslationFieldAccessor($translatedField$original$inheritedChain$context);
  536.         }
  537.         $select $this->buildFieldSelector($root$field$context$original);
  538.         if (!$field->is(Inherited::class) || !$context->considerInheritance()) {
  539.             return $select;
  540.         }
  541.         $parentSelect $this->buildFieldSelector($root '.parent'$field$context$original);
  542.         return sprintf('IFNULL(%s, %s)'$select$parentSelect);
  543.     }
  544.     private function buildFieldSelector(string $rootField $fieldContext $contextstring $accessor): string
  545.     {
  546.         $accessorBuilder $field->getAccessorBuilder();
  547.         if (!$accessorBuilder) {
  548.             throw new FieldAccessorBuilderNotFoundException($field->getPropertyName());
  549.         }
  550.         $accessor $accessorBuilder->buildAccessor($root$field$context$accessor);
  551.         if (!$accessor) {
  552.             throw new \RuntimeException(sprintf('Can not build accessor for field "%s" on root "%s"'$field->getPropertyName(), $root));
  553.         }
  554.         return $accessor;
  555.     }
  556. }