diff --git a/src/ExpressionLanguage/ExpressionLanguage.php b/src/ExpressionLanguage/ExpressionLanguage.php index 9923e603d..ebaee286f 100644 --- a/src/ExpressionLanguage/ExpressionLanguage.php +++ b/src/ExpressionLanguage/ExpressionLanguage.php @@ -8,6 +8,8 @@ class ExpressionLanguage extends BaseExpressionLanguage { + public const KNOWN_NAMES = ['value', 'args', 'context', 'info', 'object']; + private $globalNames = []; /** @@ -19,6 +21,11 @@ public function addGlobalName($index, $name): void $this->globalNames[$index] = $name; } + public function getGlobalNames() + { + return $this->globalNames; + } + public function compile($expression, $names = []) { return parent::compile($expression, \array_merge($names, $this->globalNames)); diff --git a/src/Generator/TypeGenerator.php b/src/Generator/TypeGenerator.php index ec928b148..af9aeda97 100644 --- a/src/Generator/TypeGenerator.php +++ b/src/Generator/TypeGenerator.php @@ -8,6 +8,7 @@ use Overblog\GraphQLBundle\Config\Processor; use Overblog\GraphQLBundle\Definition\Argument; use Overblog\GraphQLBundle\Definition\Type\CustomScalarType; +use Overblog\GraphQLBundle\ExpressionLanguage\ExpressionLanguage; use Overblog\GraphQLGenerator\Generator\TypeGenerator as BaseTypeGenerator; use Symfony\Component\ExpressionLanguage\Expression; use Symfony\Component\Filesystem\Filesystem; @@ -202,9 +203,14 @@ protected function generateTypeName(array $config) protected function generateUseStrictAccess(array $value) { + $expressionLanguage = $this->getExpressionLanguage(); $useStrictAccess = 'true'; - if (null !== $this->getExpressionLanguage() && $this->arrayKeyExistsAndIsNotNull($value, 'access') && $value['access'] instanceof Expression) { - $parsedExpression = $this->getExpressionLanguage()->parse($value['access'], ['value', 'args', 'context', 'info', 'object']); + if (null !== $expressionLanguage && $this->arrayKeyExistsAndIsNotNull($value, 'access') && $value['access'] instanceof Expression) { + $names = ExpressionLanguage::KNOWN_NAMES; + if ($expressionLanguage instanceof ExpressionLanguage) { + $names = \array_merge($names, $expressionLanguage->getGlobalNames()); + } + $parsedExpression = $expressionLanguage->parse($value['access'], $names); $serializedNode = \str_replace("\n", '//', (string) $parsedExpression->getNodes()); $useStrictAccess = false === \strpos($serializedNode, 'NameNode(name: \'object\')') ? 'true' : 'false'; } diff --git a/tests/Functional/App/Resolver/NodeResolver.php b/tests/Functional/App/Resolver/NodeResolver.php index 6e70fe0b9..e52980e45 100644 --- a/tests/Functional/App/Resolver/NodeResolver.php +++ b/tests/Functional/App/Resolver/NodeResolver.php @@ -13,9 +13,6 @@ class NodeResolver implements ContainerAwareInterface { use ContainerAwareTrait; - /** @var TypeResolver */ - private $typeResolver; - private $userData = [ '1' => [ 'id' => 1, @@ -38,11 +35,6 @@ class NodeResolver implements ContainerAwareInterface ], ]; - public function __construct(TypeResolver $typeResolver) - { - $this->typeResolver = $typeResolver; - } - public function resolvePhotoField($value, ResolveInfo $info) { switch ($info->fieldName) { @@ -69,9 +61,9 @@ public function idFetcher($id) public function typeResolver($value) { if (isset($value['name'])) { - return $this->typeResolver->resolve('User'); + return 'User'; } else { - return $this->typeResolver->resolve('Photo'); + return 'Photo'; } } } diff --git a/tests/Functional/App/Service/PrivateService.php b/tests/Functional/App/Service/PrivateService.php new file mode 100644 index 000000000..323c9cc31 --- /dev/null +++ b/tests/Functional/App/Service/PrivateService.php @@ -0,0 +1,13 @@ +