You are here

public static function EntitySchemaProvider::getEntitySingle in GraphQL 8

Same name and namespace in other branches
  1. 8.2 src/SchemaProvider/EntitySchemaProvider.php \Drupal\graphql\SchemaProvider\EntitySchemaProvider::getEntitySingle()

Single entity resolver callback.

File

src/SchemaProvider/EntitySchemaProvider.php, line 164

Class

EntitySchemaProvider
Generates a GraphQL Schema for content entity types.

Namespace

Drupal\graphql\SchemaProvider

Code

public static function getEntitySingle($source, array $args = NULL, $root, Node $field, $a, $b, $c, $data) {

  // @todo Fix injection of container dependencies in resolver functions.
  $storage = \Drupal::entityManager()
    ->getStorage($data['type']);
  if ($entity = $storage
    ->load($args['id'])) {
    return $entity
      ->getTypedData();
  }
  return NULL;
}