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
12 changes: 7 additions & 5 deletions Definition/Builder/SchemaBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@

namespace Overblog\GraphQLBundle\Definition\Builder;

use GraphQL\Schema;
use GraphQL\Type\Definition\Config;
use GraphQL\Type\Schema;
use Overblog\GraphQLBundle\Resolver\ResolverInterface;

class SchemaBuilder
Expand Down Expand Up @@ -40,17 +39,20 @@ public function __construct(ResolverInterface $typeResolver, $enableValidation =
*/
public function create($queryAlias = null, $mutationAlias = null, $subscriptionAlias = null)
{
$this->enableValidation ? Config::enableValidation() : Config::disableValidation();

$query = $this->typeResolver->resolve($queryAlias);
$mutation = $this->typeResolver->resolve($mutationAlias);
$subscription = $this->typeResolver->resolve($subscriptionAlias);

return new Schema([
$schema = new Schema([
'query' => $query,
'mutation' => $mutation,
'subscription' => $subscription,
'types' => $this->typeResolver->getSolutions(),
]);
if ($this->enableValidation) {
$schema->assertValid();
}

return $schema;
}
}
2 changes: 1 addition & 1 deletion DependencyInjection/OverblogGraphQLExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Overblog\GraphQLBundle\DependencyInjection;

use GraphQL\Schema;
use GraphQL\Type\Schema;
use Overblog\GraphQLBundle\Config\TypeWithOutputFieldsDefinition;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\Config\FileLocator;
Expand Down
1 change: 1 addition & 0 deletions Error/ErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ public function logException($exception, $errorLevel = LogLevel::ERROR)

public function handleErrors(ExecutionResult $executionResult, $throwRawException = false)
{
$executionResult->setErrorFormatter(sprintf('\%s::formatError', GraphQLError::class));
$exceptions = $this->treatExceptions($executionResult->errors, $throwRawException);
$executionResult->errors = $exceptions['errors'];
if (!empty($exceptions['extensions']['warnings'])) {
Expand Down
21 changes: 18 additions & 3 deletions Executor/Executor.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,16 @@
use GraphQL\Executor\ExecutionResult;
use GraphQL\Executor\Promise\Promise;
use GraphQL\Executor\Promise\PromiseAdapter;
use GraphQL\Schema;
use GraphQL\GraphQL;
use GraphQL\Type\Schema;

class Executor implements ExecutorInterface
{
/**
* @var PromiseAdapter
*/
private $promiseAdapter;

/**
* @param Schema $schema
* @param string $requestString
Expand All @@ -30,14 +36,23 @@ class Executor implements ExecutorInterface
*/
public function execute(Schema $schema, $requestString, $rootValue = null, $contextValue = null, $variableValues = null, $operationName = null)
{
return call_user_func_array('GraphQL\GraphQL::executeAndReturnResult', func_get_args());
$args = func_get_args();

if (null === $this->promiseAdapter) {
$method = 'executeQuery';
} else {
array_unshift($args, $this->promiseAdapter);
$method = 'promiseToExecute';
}

return call_user_func_array(sprintf('\%s::%s', GraphQL::class, $method), $args);
}

/**
* @param PromiseAdapter|null $promiseAdapter
*/
public function setPromiseAdapter(PromiseAdapter $promiseAdapter = null)
{
call_user_func_array('GraphQL\GraphQL::setPromiseAdapter', func_get_args());
$this->promiseAdapter = $promiseAdapter;
}
}
2 changes: 1 addition & 1 deletion Executor/ExecutorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use GraphQL\Executor\ExecutionResult;
use GraphQL\Executor\Promise\Promise;
use GraphQL\Executor\Promise\PromiseAdapter;
use GraphQL\Schema;
use GraphQL\Type\Schema;

interface ExecutorInterface
{
Expand Down
11 changes: 9 additions & 2 deletions Request/Executor.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

use GraphQL\Executor\ExecutionResult;
use GraphQL\Executor\Promise\PromiseAdapter;
use GraphQL\Schema;
use GraphQL\Type\Schema;
use GraphQL\Validator\DocumentValidator;
use GraphQL\Validator\Rules\QueryComplexity;
use GraphQL\Validator\Rules\QueryDepth;
Expand Down Expand Up @@ -176,7 +176,7 @@ public function execute(array $data, array $context = [], $schemaName = null)
isset($data[ParserInterface::PARAM_OPERATION_NAME]) ? $data[ParserInterface::PARAM_OPERATION_NAME] : null
);

if ($this->promiseAdapter && $this->promiseAdapter->isThenable($result)) {
if ($this->promiseAdapter) {
$result = $this->promiseAdapter->wait($result);
}

Expand All @@ -189,6 +189,13 @@ public function execute(array $data, array $context = [], $schemaName = null)
return $this->prepareResult($result, $startTime, $startMemoryUsage);
}

/**
* @param ExecutionResult $result
* @param int $startTime
* @param int $startMemoryUsage
*
* @return ExecutionResult
*/
private function prepareResult($result, $startTime, $startMemoryUsage)
{
if ($this->hasDebugInfo()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ PhotoAndPost:
type: union
config:
types: [Photo, Post]
resolveType: '@=service("overblog_graphql.test.resolver.global").typeResolver(value)'

PhotoInput:
type: input-object
Expand Down
Loading