Skip to content

Commit

Permalink
chore(dataproducer): suggestions from code review (drupal-graphql#1382)
Browse files Browse the repository at this point in the history
  • Loading branch information
edurenye committed Aug 26, 2024
1 parent b1c88c8 commit f4fe495
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
11 changes: 7 additions & 4 deletions src/Plugin/GraphQL/DataProducer/Entity/EntityLabel.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* "entity" = @ContextDefinition("entity",
* label = @Translation("Entity")
* ),
* "access" = @ContextDefinition("boolean",
* "check_access" = @ContextDefinition("boolean",
* label = @Translation("Check access"),
* required = FALSE,
* default_value = TRUE
Expand All @@ -41,14 +41,17 @@ class EntityLabel extends DataProducerPluginBase implements DataProducerPluginCa
* Resolver.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* @param bool $access
* @param bool $check_access
* @param \Drupal\Core\Session\AccountInterface|null $accessUser
* @param \Drupal\graphql\GraphQL\Execution\FieldContext $context
*
* @return string|null
*/
public function resolve(EntityInterface $entity, bool $access, ?AccountInterface $accessUser, FieldContext $context) {
if ($access) {
public function resolve(EntityInterface $entity, ?bool $check_access, ?AccountInterface $accessUser, FieldContext $context) {
if (is_null($check_access)) {
$check_access = TRUE;
}
if ($check_access) {
/** @var \Drupal\Core\Access\AccessResultInterface $accessResult */
$accessResult = $entity->access('view label', $accessUser, TRUE);
$context->addCacheableDependency($accessResult);
Expand Down
4 changes: 0 additions & 4 deletions tests/src/Kernel/DataProducer/EntityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,14 +223,10 @@ public function testResolveLabel(): void {

$this->assertEquals('Dummy label', $this->executeDataProducer('entity_label', [
'entity' => $this->entity,
// @todo Remove when https://github.com/drupal-graphql/graphql/issues/1233 is fixed.
'access' => TRUE,
]));

$this->assertNull($this->executeDataProducer('entity_label', [
'entity' => $this->entity,
// @todo Remove when https://github.com/drupal-graphql/graphql/issues/1233 is fixed.
'access' => TRUE,
]));
}

Expand Down

0 comments on commit f4fe495

Please sign in to comment.