1 | <?php |
||
2 | |||
3 | namespace Drupal\graphql\Access; |
||
4 | |||
5 | use Drupal\Core\Access\AccessResult; |
||
0 ignored issues
–
show
|
|||
6 | use Drupal\Core\Routing\Access\AccessInterface; |
||
0 ignored issues
–
show
The type
Drupal\Core\Routing\Access\AccessInterface was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
7 | use Drupal\Core\Session\AccountInterface; |
||
0 ignored issues
–
show
The type
Drupal\Core\Session\AccountInterface was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
8 | use Symfony\Component\HttpFoundation\RequestStack; |
||
0 ignored issues
–
show
The type
Symfony\Component\HttpFoundation\RequestStack was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
9 | |||
10 | class QueryAccessCheck implements AccessInterface { |
||
11 | |||
12 | /** |
||
13 | * The request stack. |
||
14 | * |
||
15 | * @var \Symfony\Component\HttpFoundation\RequestStack |
||
16 | */ |
||
17 | protected $requestStack; |
||
18 | |||
19 | /** |
||
20 | * QueryAccessCheck constructor. |
||
21 | * |
||
22 | * @param \Symfony\Component\HttpFoundation\RequestStack $requestStack |
||
23 | * The request stack. |
||
24 | */ |
||
25 | public function __construct(RequestStack $requestStack) { |
||
26 | $this->requestStack = $requestStack; |
||
27 | } |
||
28 | |||
29 | /** |
||
30 | * Checks access. |
||
31 | * |
||
32 | * @param \Drupal\Core\Session\AccountInterface $account |
||
33 | * The currently logged in account. |
||
34 | * |
||
35 | * @return \Drupal\Core\Access\AccessResultInterface |
||
0 ignored issues
–
show
The type
Drupal\Core\Access\AccessResultInterface was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
36 | * The access result. |
||
37 | */ |
||
38 | public function access(AccountInterface $account) { |
||
39 | // If the user has the global permission to execute any query, let them. |
||
40 | if ($account->hasPermission('execute graphql requests')) { |
||
41 | return AccessResult::allowed(); |
||
42 | } |
||
43 | |||
44 | $request = $this->requestStack->getCurrentRequest(); |
||
45 | /** @var \GraphQL\Server\OperationParams[] $operations */ |
||
46 | if (!$operations = $request->attributes->get('operations', [])) { |
||
47 | return AccessResult::forbidden(); |
||
48 | } |
||
49 | |||
50 | $operations = is_array($operations) ? $operations : [$operations]; |
||
0 ignored issues
–
show
|
|||
51 | foreach ($operations as $operation) { |
||
52 | // If a query was provided by the user, this is an arbitrary query (it's |
||
53 | // not a persisted query). Hence, we only grant access if the user has the |
||
54 | // permission to execute any query. |
||
55 | if ($operation->getOriginalInput('query')) { |
||
56 | return AccessResult::allowedIfHasPermission($account, 'execute graphql requests'); |
||
57 | } |
||
58 | } |
||
59 | |||
60 | // If we reach this point, this is a persisted query. |
||
61 | return AccessResult::allowedIfHasPermission($account, 'execute persisted graphql requests'); |
||
62 | } |
||
63 | |||
64 | } |
||
65 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths