Skip to content
Snippets Groups Projects

Add graphql sub module.

Merged Andy Marquis requested to merge issue/custom_field-3423901:3423901-graphql-compose-3 into 3.0.x
Files
9
<?php
declare(strict_types=1);
namespace Drupal\custom_field_graphql\Plugin\GraphQLCompose\FieldType;
use Drupal\Core\Field\FieldItemInterface;
use Drupal\graphql\GraphQL\Execution\FieldContext;
use Drupal\graphql_compose\Plugin\GraphQL\DataProducer\FieldProducerItemInterface;
use Drupal\graphql_compose\Plugin\GraphQL\DataProducer\FieldProducerTrait;
use Drupal\graphql_compose\Plugin\GraphQLCompose\GraphQLComposeFieldTypeBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* {@inheritdoc}
*
* @GraphQLComposeFieldType(
* id = "custom_field_entity_reference",
* )
*/
class CustomFieldEntityReference extends GraphQLComposeFieldTypeBase implements FieldProducerItemInterface {
use FieldProducerTrait;
/**
* The entity repository.
*
* @var \Drupal\Core\Entity\EntityRepositoryInterface
*/
protected $entityRepository;
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
$instance = parent::create($container, $configuration, $plugin_id, $plugin_definition);
$instance->entityRepository = $container->get('entity.repository');
return $instance;
}
/**
* {@inheritdoc}
*/
public function resolveFieldItem(FieldItemInterface $item, FieldContext $context) {
if (!$item->entity) {
return NULL;
}
$entity = $item->entity;
$context->addCacheableDependency($entity);
return $entity;
}
}
Loading