Skip to content

Commit 871a1b4

Browse files
authored
fix(example): Add query access check for unpublished articles (#1333)
1 parent 961eb3a commit 871a1b4

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

examples/graphql_example/src/Plugin/GraphQL/DataProducer/QueryArticles.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
88
use Drupal\graphql\Plugin\GraphQL\DataProducer\DataProducerPluginBase;
99
use Drupal\graphql_examples\Wrappers\QueryConnection;
10+
use Drupal\node\Entity\Node;
1011
use GraphQL\Error\UserError;
1112
use Symfony\Component\DependencyInjection\ContainerInterface;
1213

@@ -94,7 +95,13 @@ public function resolve($offset, $limit, RefinableCacheableDependencyInterface $
9495
$entityType = $storage->getEntityType();
9596
$query = $storage->getQuery()
9697
->currentRevision()
97-
->accessCheck();
98+
->accessCheck()
99+
// The access check does not filter out unpublished nodes automatically,
100+
// so we need to do this explicitly here. We don't want to run access
101+
// checks on loaded nodes later, as that would then make the query count
102+
// numbers wrong. Therefore all fields relevant for access need to be
103+
// included here.
104+
->condition('status', Node::PUBLISHED);
98105

99106
$query->condition($entityType->getKey('bundle'), 'article');
100107
$query->range($offset, $limit);

0 commit comments

Comments
 (0)