You are here

public function EntityDefinition::resolve in GraphQL 8.4

Resolves entity definition for a given entity type.

Parameters

string $entity_type: The entity type.

string|null $bundle: Optional. The entity bundle which are stored as a context for upcoming data producers deeper in hierarchy.

string|null $field_types: Optional. The field types to retrieve (base fields, configurable fields, or both) which are stored as a context for upcoming data producers deeper in hierarchy.

\Drupal\graphql\GraphQL\Execution\FieldContext $field_context: Field context.

Return value

\Drupal\Core\Entity\EntityTypeInterface The entity definition.

File

src/Plugin/GraphQL/DataProducer/EntityDefinition/EntityDefinition.php, line 103

Class

EntityDefinition
Gets entity definition for a given entity type.

Namespace

Drupal\graphql\Plugin\GraphQL\DataProducer\EntityDefinition

Code

public function resolve(string $entity_type, ?string $bundle = NULL, ?string $field_types = NULL, FieldContext $field_context) : EntityTypeInterface {
  if ($bundle) {
    $bundle_info = \Drupal::service('entity_type.bundle.info')
      ->getBundleInfo($entity_type);
    if (isset($bundle_info[$bundle])) {
      $bundle_context = $bundle_info[$bundle];
      $bundle_context['key'] = $bundle;
      $field_context
        ->setContextValue('bundle', $bundle_context);
    }
  }
  if ($field_types) {
    $field_context
      ->setContextValue('field_types', $field_types);
  }
  return $this->entityTypeManager
    ->getDefinition($entity_type);
}