Skip to content

Commit 0b3b90e

Browse files
authored
Merge pull request #179 from mcg-web/supports-graphql-php-v0_10
Add support for `webonyx/graphql-php#v0.10`
2 parents 1d2e0df + 262918d commit 0b3b90e

File tree

12 files changed

+1304
-1278
lines changed

12 files changed

+1304
-1278
lines changed

Definition/Builder/SchemaBuilder.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111

1212
namespace Overblog\GraphQLBundle\Definition\Builder;
1313

14-
use GraphQL\Schema;
15-
use GraphQL\Type\Definition\Config;
14+
use GraphQL\Type\Schema;
1615
use Overblog\GraphQLBundle\Resolver\ResolverInterface;
1716

1817
class SchemaBuilder
@@ -40,17 +39,20 @@ public function __construct(ResolverInterface $typeResolver, $enableValidation =
4039
*/
4140
public function create($queryAlias = null, $mutationAlias = null, $subscriptionAlias = null)
4241
{
43-
$this->enableValidation ? Config::enableValidation() : Config::disableValidation();
44-
4542
$query = $this->typeResolver->resolve($queryAlias);
4643
$mutation = $this->typeResolver->resolve($mutationAlias);
4744
$subscription = $this->typeResolver->resolve($subscriptionAlias);
4845

49-
return new Schema([
46+
$schema = new Schema([
5047
'query' => $query,
5148
'mutation' => $mutation,
5249
'subscription' => $subscription,
5350
'types' => $this->typeResolver->getSolutions(),
5451
]);
52+
if ($this->enableValidation) {
53+
$schema->assertValid();
54+
}
55+
56+
return $schema;
5557
}
5658
}

DependencyInjection/OverblogGraphQLExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace Overblog\GraphQLBundle\DependencyInjection;
1313

14-
use GraphQL\Schema;
14+
use GraphQL\Type\Schema;
1515
use Overblog\GraphQLBundle\Config\TypeWithOutputFieldsDefinition;
1616
use Symfony\Component\Cache\Adapter\ArrayAdapter;
1717
use Symfony\Component\Config\FileLocator;

Error/ErrorHandler.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ public function logException($exception, $errorLevel = LogLevel::ERROR)
157157

158158
public function handleErrors(ExecutionResult $executionResult, $throwRawException = false)
159159
{
160+
$executionResult->setErrorFormatter(sprintf('\%s::formatError', GraphQLError::class));
160161
$exceptions = $this->treatExceptions($executionResult->errors, $throwRawException);
161162
$executionResult->errors = $exceptions['errors'];
162163
if (!empty($exceptions['extensions']['warnings'])) {

Executor/Executor.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,16 @@
1414
use GraphQL\Executor\ExecutionResult;
1515
use GraphQL\Executor\Promise\Promise;
1616
use GraphQL\Executor\Promise\PromiseAdapter;
17-
use GraphQL\Schema;
17+
use GraphQL\GraphQL;
18+
use GraphQL\Type\Schema;
1819

1920
class Executor implements ExecutorInterface
2021
{
22+
/**
23+
* @var PromiseAdapter
24+
*/
25+
private $promiseAdapter;
26+
2127
/**
2228
* @param Schema $schema
2329
* @param string $requestString
@@ -30,14 +36,23 @@ class Executor implements ExecutorInterface
3036
*/
3137
public function execute(Schema $schema, $requestString, $rootValue = null, $contextValue = null, $variableValues = null, $operationName = null)
3238
{
33-
return call_user_func_array('GraphQL\GraphQL::executeAndReturnResult', func_get_args());
39+
$args = func_get_args();
40+
41+
if (null === $this->promiseAdapter) {
42+
$method = 'executeQuery';
43+
} else {
44+
array_unshift($args, $this->promiseAdapter);
45+
$method = 'promiseToExecute';
46+
}
47+
48+
return call_user_func_array(sprintf('\%s::%s', GraphQL::class, $method), $args);
3449
}
3550

3651
/**
3752
* @param PromiseAdapter|null $promiseAdapter
3853
*/
3954
public function setPromiseAdapter(PromiseAdapter $promiseAdapter = null)
4055
{
41-
call_user_func_array('GraphQL\GraphQL::setPromiseAdapter', func_get_args());
56+
$this->promiseAdapter = $promiseAdapter;
4257
}
4358
}

Executor/ExecutorInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use GraphQL\Executor\ExecutionResult;
1515
use GraphQL\Executor\Promise\Promise;
1616
use GraphQL\Executor\Promise\PromiseAdapter;
17-
use GraphQL\Schema;
17+
use GraphQL\Type\Schema;
1818

1919
interface ExecutorInterface
2020
{

Request/Executor.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
use GraphQL\Executor\ExecutionResult;
1515
use GraphQL\Executor\Promise\PromiseAdapter;
16-
use GraphQL\Schema;
16+
use GraphQL\Type\Schema;
1717
use GraphQL\Validator\DocumentValidator;
1818
use GraphQL\Validator\Rules\QueryComplexity;
1919
use GraphQL\Validator\Rules\QueryDepth;
@@ -176,7 +176,7 @@ public function execute(array $data, array $context = [], $schemaName = null)
176176
isset($data[ParserInterface::PARAM_OPERATION_NAME]) ? $data[ParserInterface::PARAM_OPERATION_NAME] : null
177177
);
178178

179-
if ($this->promiseAdapter && $this->promiseAdapter->isThenable($result)) {
179+
if ($this->promiseAdapter) {
180180
$result = $this->promiseAdapter->wait($result);
181181
}
182182

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

192+
/**
193+
* @param ExecutionResult $result
194+
* @param int $startTime
195+
* @param int $startMemoryUsage
196+
*
197+
* @return ExecutionResult
198+
*/
192199
private function prepareResult($result, $startTime, $startMemoryUsage)
193200
{
194201
if ($this->hasDebugInfo()) {

Tests/Functional/App/config/global/mapping/global.types.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ PhotoAndPost:
5454
type: union
5555
config:
5656
types: [Photo, Post]
57+
resolveType: '@=service("overblog_graphql.test.resolver.global").typeResolver(value)'
5758

5859
PhotoInput:
5960
type: input-object

0 commit comments

Comments
 (0)