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
2 changes: 1 addition & 1 deletion Command/GraphQLDumpSchemaCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private function createFile(InputInterface $input)
$modern = $this->useModernJsonFormat($input);

$result = $this->getRequestExecutor()
->execute($request, [], $schemaName)
->execute($schemaName, $request)
->toArray();

$content = json_encode($modern ? $result : $result['data'], \JSON_PRETTY_PRINT);
Expand Down
9 changes: 2 additions & 7 deletions Controller/GraphController.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,7 @@ private function processBatchQuery(Request $request, $schemaName = null)

foreach ($queries as $query) {
$payloadResult = $this->requestExecutor->execute(
[
'query' => $query['query'],
'variables' => $query['variables'],
],
[],
$schemaName
$schemaName, ['query' => $query['query'], 'variables' => $query['variables']]
);
$payloads[] = $apolloBatching ? $payloadResult->toArray() : ['id' => $query['id'], 'payload' => $payloadResult->toArray()];
}
Expand All @@ -112,6 +107,6 @@ private function processNormalQuery(Request $request, $schemaName = null)
{
$params = $this->requestParser->parse($request);

return $this->requestExecutor->execute($params, [], $schemaName)->toArray();
return $this->requestExecutor->execute($schemaName, $params)->toArray();
}
}
360 changes: 227 additions & 133 deletions DependencyInjection/Configuration.php

Large diffs are not rendered by default.

83 changes: 54 additions & 29 deletions DependencyInjection/OverblogGraphQLExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@

namespace Overblog\GraphQLBundle\DependencyInjection;

use GraphQL\Error\UserError;
use GraphQL\Type\Schema;
use Overblog\GraphQLBundle\CacheWarmer\CompileCacheWarmer;
use Overblog\GraphQLBundle\Config\Processor\BuilderProcessor;
use Overblog\GraphQLBundle\Error\ErrorHandler;
use Overblog\GraphQLBundle\Error\UserWarning;
use Overblog\GraphQLBundle\Event\Events;
use Overblog\GraphQLBundle\EventListener\ClassLoaderListener;
use Overblog\GraphQLBundle\EventListener\DebugListener;
use Overblog\GraphQLBundle\EventListener\ErrorHandlerListener;
use Overblog\GraphQLBundle\EventListener\ErrorLoggerListener;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
Expand All @@ -32,10 +40,10 @@ public function load(array $configs, ContainerBuilder $container)
$this->setServicesAliases($config, $container);
$this->setSchemaBuilderArguments($config, $container);
$this->setSchemaArguments($config, $container);
$this->setErrorHandlerArguments($config, $container);
$this->setErrorHandler($config, $container);
$this->setSecurity($config, $container);
$this->setConfigBuilders($config, $container);
$this->setShowDebug($config, $container);
$this->setDebugListener($config, $container);
$this->setDefinitionParameters($config, $container);
$this->setClassLoaderListener($config, $container);
$this->setCompilerCacheWarmer($config, $container);
Expand All @@ -56,7 +64,7 @@ public function prepend(ContainerBuilder $container)

public function getAlias()
{
return 'overblog_graphql';
return Configuration::NAME;
}

public function getConfiguration(array $config, ContainerBuilder $container)
Expand Down Expand Up @@ -87,6 +95,7 @@ private function setClassLoaderListener(array $config, ContainerBuilder $contain
$this->getAlias().'.event_listener.classloader_listener',
new Definition(ClassLoaderListener::class)
);
$definition->setPublic(true);
$definition->setArguments([new Reference($this->getAlias().'.cache_compiler')]);
$definition->addTag('kernel.event_listener', ['event' => 'kernel.request', 'method' => 'load', 'priority' => 255]);
$definition->addTag('kernel.event_listener', ['event' => 'console.command', 'method' => 'load', 'priority' => 255]);
Expand Down Expand Up @@ -117,9 +126,16 @@ private function setExpressionLanguageDefaultParser(ContainerBuilder $container)
$container->setDefinition($this->getAlias().'.cache_expression_language_parser.default', $definition);
}

private function setShowDebug(array $config, ContainerBuilder $container)
private function setDebugListener(array $config, ContainerBuilder $container)
{
$container->getDefinition($this->getAlias().'.request_executor')->replaceArgument(4, $config['definitions']['show_debug_info']);
if ($config['definitions']['show_debug_info']) {
$definition = $container->setDefinition(
DebugListener::class,
new Definition(DebugListener::class)
);
$definition->addTag('kernel.event_listener', ['event' => Events::PRE_EXECUTOR, 'method' => 'onPreExecutor']);
$definition->addTag('kernel.event_listener', ['event' => Events::POST_EXECUTOR, 'method' => 'onPostExecutor']);
}
}

private function setConfigBuilders(array $config, ContainerBuilder $container)
Expand Down Expand Up @@ -157,27 +173,37 @@ private function setSecurity(array $config, ContainerBuilder $container)
}
}

private function setErrorHandlerArguments(array $config, ContainerBuilder $container)
private function setErrorHandler(array $config, ContainerBuilder $container)
{
$errorHandlerDefinition = $container->getDefinition($this->getAlias().'.error_handler');

if (isset($config['definitions']['internal_error_message'])) {
$errorHandlerDefinition->replaceArgument(0, $config['definitions']['internal_error_message']);
}

if (isset($config['definitions']['map_exceptions_to_parent'])) {
$errorHandlerDefinition->replaceArgument(
3,
$config['definitions']['map_exceptions_to_parent']
);
}
if ($config['errors_handler']['enabled']) {
$id = $this->getAlias().'.error_handler';
$errorHandlerDefinition = $container->setDefinition($id, new Definition(ErrorHandler::class));
$errorHandlerDefinition->setPublic(false)
->setArguments(
[
new Reference('event_dispatcher'),
$config['errors_handler']['internal_error_message'],
$this->buildExceptionMap($config['errors_handler']['exceptions']),
$config['errors_handler']['map_exceptions_to_parent'],
]
)
;

if (isset($config['definitions']['exceptions'])) {
$errorHandlerDefinition
->replaceArgument(2, $this->buildExceptionMap($config['definitions']['exceptions']))
->addMethodCall('setUserWarningClass', [$config['definitions']['exceptions']['types']['warnings']])
->addMethodCall('setUserErrorClass', [$config['definitions']['exceptions']['types']['errors']])
$errorHandlerListenerDefinition = $container->setDefinition(ErrorHandlerListener::class, new Definition(ErrorHandlerListener::class));
$errorHandlerListenerDefinition->setPublic(true)
->setArguments([new Reference($id), $config['errors_handler']['rethrow_internal_exceptions'], $config['errors_handler']['debug']])
->addTag('kernel.event_listener', ['event' => Events::POST_EXECUTOR, 'method' => 'onPostExecutor'])
;

if ($config['errors_handler']['log']) {
$loggerServiceId = $config['errors_handler']['logger_service'];
$invalidBehavior = ErrorLoggerListener::DEFAULT_LOGGER_SERVICE === $loggerServiceId ? ContainerInterface::NULL_ON_INVALID_REFERENCE : ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE;
$errorHandlerListenerDefinition = $container->setDefinition(ErrorLoggerListener::class, new Definition(ErrorLoggerListener::class));
$errorHandlerListenerDefinition->setPublic(true)
->setArguments([new Reference($loggerServiceId, $invalidBehavior)])
->addTag('kernel.event_listener', ['event' => Events::ERROR_FORMATTING, 'method' => 'onErrorFormatting'])
;
}
}
}

Expand Down Expand Up @@ -225,15 +251,14 @@ private function setServicesAliases(array $config, ContainerBuilder $container)
private function buildExceptionMap(array $exceptionConfig)
{
$exceptionMap = [];
$typeMap = $exceptionConfig['types'];
$errorsMapping = [
'errors' => UserError::class,
'warnings' => UserWarning::class,
];

foreach ($exceptionConfig as $type => $exceptionList) {
if ('types' === $type) {
continue;
}

foreach ($exceptionList as $exception) {
$exceptionMap[$exception] = $typeMap[$type];
$exceptionMap[$exception] = $errorsMapping[$type];
}
}

Expand Down
Loading