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
3 changes: 3 additions & 0 deletions DependencyInjection/TypesConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ private function addConfigSelection()
->info('One of internal or custom types.')
->end()
->end()
->variableNode('fieldsDefaultAccess')
->info('Default access control to fields (expression language can be use here)')
->end()
->append($this->addFieldsSelection('fields'))
->variableNode('resolveType')->end()
->arrayNode('values')
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -617,9 +617,9 @@ class CharacterResolver
Access Control
--------------

An access control can be add on each field using `config.fields.*.access`.
An access control can be add on each field using `config.fields.*.access` or globally with `config.fieldsDefaultAccess`.
If `config.fields.*.access` value is true field will be normally resolved but will be `null` otherwise.
Default value is true.
Act like access is`true` if not set.

In the example below the Human name is available only for authenticated users.

Expand Down
11 changes: 8 additions & 3 deletions Resolver/Config/FieldsConfigSolution.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use Overblog\GraphQLBundle\Relay\Connection\Output\Edge;
use Overblog\GraphQLBundle\Resolver\ResolverInterface;

class FieldsConfigSolution extends AbstractConfigSolution implements UniqueConfigSolutionInterface
class FieldsConfigSolution extends AbstractConfigSolution
{
/**
* @var TypeConfigSolution
Expand All @@ -37,19 +37,24 @@ public function __construct(
$this->resolveCallbackConfigSolution = $resolveCallbackConfigSolution;
}

public function solve($values, $config = null)
public function solve($values, array &$config = null)
{
// builder must be last
$fieldsTreated = ['type', 'args', 'argsBuilder', 'deprecationReason', 'builder'];

$fieldsDefaultAccess = isset($config['fieldsDefaultAccess']) ? $config['fieldsDefaultAccess'] : null;
unset($config['fieldsDefaultAccess']);

foreach ($values as $field => &$options) {
//init access with fields default access if needed
$options['access'] = isset($options['access']) ? $options['access'] : $fieldsDefaultAccess;

foreach ($fieldsTreated as $fieldTreated) {
if (isset($options[$fieldTreated])) {
$method = 'solve'.ucfirst($fieldTreated);
$options = $this->$method($options, $field);
}
}

$options = $this->resolveResolveAndAccessIfNeeded($options);
}

Expand Down
4 changes: 2 additions & 2 deletions Resolver/Config/ResolveCallbackConfigSolution.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

namespace Overblog\GraphQLBundle\Resolver\Config;

class ResolveCallbackConfigSolution extends AbstractConfigSolution implements UniqueConfigSolutionInterface
class ResolveCallbackConfigSolution extends AbstractConfigSolution
{
public function solve($value, $config = null)
public function solve($value)
{
if (is_callable($value)) {
return $value;
Expand Down
16 changes: 0 additions & 16 deletions Resolver/Config/UniqueConfigSolutionInterface.php

This file was deleted.

4 changes: 2 additions & 2 deletions Resolver/Config/ValuesConfigSolution.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

namespace Overblog\GraphQLBundle\Resolver\Config;

class ValuesConfigSolution extends AbstractConfigSolution implements UniqueConfigSolutionInterface
class ValuesConfigSolution extends AbstractConfigSolution
{
public function solve($values, $config = null)
public function solve($values)
{
if (!empty($values)) {
foreach ($values as $name => &$options) {
Expand Down
2 changes: 1 addition & 1 deletion Resolver/ConfigResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function resolve($config)
}
$options = $this->getSolutionOptions($name);

$values = call_user_func_array([$solution, $options['method']], [$values]);
$values = call_user_func_array([$solution, $options['method']], [$values, &$config]);
}

return $config;
Expand Down