Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Config/EnumTypeDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@ public function getDefinition()
->useAttributeAsKey('name')
->prototype('array')
->beforeNormalization()
->ifTrue(function ($v) { return !is_null($v) && !is_array($v); })
->then(function ($v) { return ['value' => $v]; })
->ifTrue(function ($v) {
return !is_null($v) && !is_array($v);
})
->then(function ($v) {
return ['value' => $v];
})
->end()
->isRequired()
->children()
Expand Down
1 change: 0 additions & 1 deletion Config/ObjectTypeDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public function getDefinition()

$node->validate()
->ifTrue(function ($v) {

return array_key_exists('fieldsDefaultAccess', $v) && null !== $v['fieldsDefaultAccess'];
})
->then(function ($v) {
Expand Down
19 changes: 13 additions & 6 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Configuration implements ConfigurationInterface
*/
public function __construct($debug)
{
$this->debug = (Boolean) $debug;
$this->debug = (bool) $debug;
}

public function getConfigTreeBuilder()
Expand All @@ -44,6 +44,7 @@ public function getConfigTreeBuilder()
->addDefaultsIfNotSet()
->children()
->scalarNode('internal_error_message')->defaultNull()->end()
->booleanNode('show_debug_info')->defaultValue(false)->end()
->booleanNode('config_validation')->defaultValue($this->debug)->end()
->arrayNode('schema')
->beforeNormalization()
Expand Down Expand Up @@ -84,11 +85,11 @@ public function getConfigTreeBuilder()
->arrayNode('exceptions')
->children()
->arrayNode('warnings')
->treatNullLike(array())
->treatNullLike([])
->prototype('scalar')->end()
->end()
->arrayNode('errors')
->treatNullLike(array())
->treatNullLike([])
->prototype('scalar')->end()
->end()
->arrayNode('types')
Expand Down Expand Up @@ -174,12 +175,18 @@ private function addSecurityQuerySection($name, $disabledValue)
$node
->info('Disabled if equal to false.')
->beforeNormalization()
->ifTrue(function ($v) { return false === $v; })
->then(function () use ($disabledValue) { return $disabledValue; })
->ifTrue(function ($v) {
return false === $v;
})
->then(function () use ($disabledValue) {
return $disabledValue;
})
->end()
->defaultFalse()
->validate()
->ifTrue(function ($v) { return $v < 0; })
->ifTrue(function ($v) {
return $v < 0;
})
->thenInvalid('"overblog_graphql.security.'.$name.'" must be greater or equal to 0.')
->end()
;
Expand Down
4 changes: 3 additions & 1 deletion DependencyInjection/OverblogGraphQLExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public function load(array $configs, ContainerBuilder $container)
$this->setConfigBuilders($config);
$this->setVersions($config, $container);

$container->getDefinition('overblog_graphql.request_executor')->replaceArgument(3, $config['definitions']['show_debug_info']);
$container->setParameter($this->getAlias().'.resources_dir', realpath(__DIR__.'/../Resources'));
}

Expand Down Expand Up @@ -161,7 +162,8 @@ public function getConfiguration(array $config, ContainerBuilder $container)
* Returns a list of custom exceptions mapped to error/warning classes.
*
* @param array $exceptionConfig
* @return array Custom exception map, [exception => UserError/UserWarning].
*
* @return array Custom exception map, [exception => UserError/UserWarning]
*/
private function buildExceptionMap(array $exceptionConfig)
{
Expand Down
1 change: 0 additions & 1 deletion DependencyInjection/OverblogGraphQLTypesExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ private function typesConfigsMappingFromConfig(array $config, ContainerBuilder $
if (!empty($config['definitions']['mappings']['types'])) {
$typesMappings = array_filter(array_map(
function (array $typeMapping) use ($container) {

$params = $this->detectConfigFiles($container, $typeMapping['dir'], $typeMapping['type']);

return $params;
Expand Down
8 changes: 6 additions & 2 deletions DependencyInjection/TypesConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ function ($type) {

private function addBeforeNormalization(ArrayNodeDefinition $node)
{
$typeKeyExists = function ($types) { return !empty($types) && is_array($types); };
$typeKeyExists = function ($types) {
return !empty($types) && is_array($types);
};

$node
// set type config.name
Expand Down Expand Up @@ -147,7 +149,9 @@ private function addBeforeNormalization(ArrayNodeDefinition $node)
->end()
// normalized relay-mutation-payload
->beforeNormalization()
->ifTrue(function ($types) { return !empty($types) && is_array($types); })
->ifTrue(function ($types) {
return !empty($types) && is_array($types);
})
->then($this->relayNormalizer('relay-mutation-payload', 'Overblog\GraphQLBundle\Relay\Mutation\PayloadDefinition'))
->end();
}
Expand Down
3 changes: 2 additions & 1 deletion Error/ErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,13 @@ public function handleErrors(ExecutionResult $executionResult, $throwRawExceptio
* that is displayed to the user.
*
* @param \Exception $rawException
*
* @return \Exception
*/
protected function convertException(\Exception $rawException = null)
{
if (null === $rawException) {
return null;
return;
}

if (!empty($this->exceptionMap[get_class($rawException)])) {
Expand Down
24 changes: 16 additions & 8 deletions ExpressionLanguage/AuthorizationExpressionProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public function getFunctions()
function ($role) {
return sprintf('$container->get(\'security.authorization_checker\')->isGranted(%s)', $role);
},
function () {}
function () {
}
),

new ExpressionFunction(
Expand All @@ -34,39 +35,44 @@ function ($roles) {

return $code;
},
function () {}
function () {
}
),

new ExpressionFunction(
'isAnonymous',
function () {
return '$container->get(\'security.authorization_checker\')->isGranted(\'IS_AUTHENTICATED_ANONYMOUSLY\')';
},
function () {}
function () {
}
),

new ExpressionFunction(
'isRememberMe',
function () {
return '$container->get(\'security.authorization_checker\')->isGranted(\'IS_AUTHENTICATED_REMEMBERED\')';
},
function () {}
function () {
}
),

new ExpressionFunction(
'isFullyAuthenticated',
function () {
return '$container->get(\'security.authorization_checker\')->isGranted(\'IS_AUTHENTICATED_FULLY\')';
},
function () {}
function () {
}
),

new ExpressionFunction(
'isAuthenticated',
function () {
return '$container->get(\'security.authorization_checker\')->isGranted(\'IS_AUTHENTICATED_REMEMBERED\') || $container->get(\'security.authorization_checker\')->isGranted(\'IS_AUTHENTICATED_FULLY\')';
},
function () {}
function () {
}
),

new ExpressionFunction(
Expand All @@ -76,7 +82,8 @@ function ($object, $permission) {

return $code;
},
function () {}
function () {
}
),

new ExpressionFunction(
Expand All @@ -86,7 +93,8 @@ function ($object, $permissions) {

return $code;
},
function () {}
function () {
}
),
];
}
Expand Down
36 changes: 24 additions & 12 deletions ExpressionLanguage/ConfigExpressionProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,35 @@ public function getFunctions()
function ($value) {
return sprintf('$container->get(%s)', $value);
},
function () {}
function () {
}
),

new ExpressionFunction(
'parameter',
function ($value) {
return sprintf('$container->getParameter(%s)', $value);
},
function () {}
function () {
}
),

new ExpressionFunction(
'isTypeOf',
function ($className) {
return sprintf('($className = %s) && $value instanceof $className', $className);
},
function () {}
function () {
}
),

new ExpressionFunction(
'resolver',
function ($alias, $args = '[]') {
return sprintf('$container->get(\'overblog_graphql.resolver_resolver\')->resolve([%s, %s])', $alias, $args);
},
function () {}
function () {
}
),

new ExpressionFunction(
Expand All @@ -60,7 +64,8 @@ function ($mutateAndGetPayload) {

return $code;
},
function () {}
function () {
}
),

new ExpressionFunction(
Expand All @@ -71,7 +76,8 @@ function ($mutateAndGetPayload) {

return $code;
},
function () {}
function () {
}
),

new ExpressionFunction(
Expand All @@ -82,7 +88,8 @@ function ($idFetcher) {

return $code;
},
function () {}
function () {
}
),

new ExpressionFunction(
Expand All @@ -93,15 +100,17 @@ function ($resolveSingleInput) {

return $code;
},
function () {}
function () {
}
),

new ExpressionFunction(
'mutation',
function ($alias, $args = '[]') {
return sprintf('$container->get(\'overblog_graphql.mutation_resolver\')->resolve([%s, %s])', $alias, $args);
},
function () {}
function () {
}
),

new ExpressionFunction(
Expand All @@ -115,7 +124,8 @@ function ($id, $typeName = null) {
$id
);
},
function () {}
function () {
}
),

new ExpressionFunction(
Expand All @@ -126,15 +136,17 @@ function ($globalId) {
$globalId
);
},
function () {}
function () {
}
),

new ExpressionFunction(
'newObject',
function ($className, $args = '[]') {
return sprintf('(new \ReflectionClass(%s))->newInstanceArgs(%s)', $className, $args);
},
function () {}
function () {
}
),
];
}
Expand Down
5 changes: 3 additions & 2 deletions Generator/TypeGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function setCacheDir($cacheDir)

protected function generateClassDocBlock(array $value)
{
return <<<EOF
return <<<'EOF'

/**
* THIS FIELD WAS GENERATED AND SHOULD NOT BE MODIFIED!
Expand All @@ -73,9 +73,10 @@ protected function resolveTypeCode($alias)
}

/**
* todo replace generateResolve in vendor after spec-april2016 is merged
* todo replace generateResolve in vendor after spec-april2016 is merged.
*
* @param array $value
*
* @return string
*/
protected function generateResolve2(array $value)
Expand Down
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,32 @@ simple request | `/graphql/bar`
batch request | `/graphql/bar/batch`
graphiQL | `/graphiql/bar`

Debug information
-----------------

To enabled or disabled debug information:

```yaml
# app/config/config.yml

overblog_graphql:
definitions:
show_debug_info: true # Debug info is disabled by default
```

here an example of an answer when debug information is enabled
```json
{
"data": [{"isEnabled": true}],
"extensions": {
"debug": {
"executionTime": "400 ms",
"memoryUsage": "1.00 MiB"
}
}
}
```

Contribute
----------

Expand Down
Loading