Skip to content

Commit

Permalink
Merge branch 'master' into annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
mcg-web committed Dec 20, 2018
2 parents f9bd917 + 4e441b3 commit 92917ba
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 15 deletions.
7 changes: 7 additions & 0 deletions src/ExpressionLanguage/ExpressionLanguage.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

class ExpressionLanguage extends BaseExpressionLanguage
{
public const KNOWN_NAMES = ['value', 'args', 'context', 'info', 'object'];

private $globalNames = [];

/**
Expand All @@ -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));
Expand Down
10 changes: 8 additions & 2 deletions src/Generator/TypeGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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';
}
Expand Down
12 changes: 2 additions & 10 deletions tests/Functional/App/Resolver/NodeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ class NodeResolver implements ContainerAwareInterface
{
use ContainerAwareTrait;

/** @var TypeResolver */
private $typeResolver;

private $userData = [
'1' => [
'id' => 1,
Expand All @@ -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) {
Expand All @@ -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';
}
}
}
13 changes: 13 additions & 0 deletions tests/Functional/App/Service/PrivateService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Overblog\GraphQLBundle\Tests\Functional\App\Service;

class PrivateService
{
public function hasAccess()
{
return true;
}
}
7 changes: 7 additions & 0 deletions tests/Functional/App/config/access/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,10 @@ overblog_graphql:
-
type: yaml
dir: "%kernel.root_dir%/config/access/mapping"

services:
overblog_graphql.test.private:
class: Overblog\GraphQLBundle\Tests\Functional\App\Service\PrivateService
public: false
tags:
- { name: "overblog_graphql.global_variable", alias: "private_service" }
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Mutation:
config:
fields:
user:
access: '@=private_service.hasAccess()'
type: Human
resolve: '@=resolver("query")'

Expand Down
2 changes: 0 additions & 2 deletions tests/Functional/App/config/node/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ imports:
services:
node_resolver:
class: Overblog\GraphQLBundle\Tests\Functional\App\Resolver\NodeResolver
arguments:
- "@overblog_graphql.type_resolver"
tags:
- { name: "overblog_graphql.resolver", method: "typeResolver" }
- { name: "overblog_graphql.resolver", alias: "node_id_fetcher", method: "idFetcher" }
Expand Down
2 changes: 1 addition & 1 deletion tests/Functional/App/config/node/mapping/node_type.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Node:
type: relay-node
config:
resolveType: '@=resolver("node_resolver::typeResolver", [value])'
resolveType: '@=typeResolver.resolve(resolver("node_resolver::typeResolver", [value]))'

0 comments on commit 92917ba

Please sign in to comment.