EntityId.php in GraphQL 8.4
File
src/Plugin/GraphQL/DataProducer/Entity/EntityId.phpView source
<?php
namespace Drupal\graphql\Plugin\GraphQL\DataProducer\Entity;
use Drupal\Core\Entity\EntityInterface;
use Drupal\graphql\Plugin\GraphQL\DataProducer\DataProducerPluginBase;
/**
* Returns the ID of an entity.
*
* @DataProducer(
* id = "entity_id",
* name = @Translation("Entity identifier"),
* description = @Translation("Returns the entity identifier."),
* produces = @ContextDefinition("string",
* label = @Translation("Identifier")
* ),
* consumes = {
* "entity" = @ContextDefinition("entity",
* label = @Translation("Entity")
* )
* }
* )
*/
class EntityId extends DataProducerPluginBase {
/**
* Resolver.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
*
* @return int|string|null
*/
public function resolve(EntityInterface $entity) {
return $entity
->id();
}
}