Skip to content

Commit bb0ab97

Browse files
authored
Merge pull request #497 from mcg-web/experimental_executor
Allow using GraphQL experimental Coroutine executor
2 parents aa8ea89 + 3b3f40a commit bb0ab97

File tree

11 files changed

+29
-2
lines changed

11 files changed

+29
-2
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ jobs:
4141
env: SYMFONY_VERSION=4.2.*
4242
- php: 7.3
4343
env: SYMFONY_VERSION=4.3.* SYMFONY_DEPRECATIONS_HELPER=max[total]=0
44+
- php: 7.3
45+
env: SYMFONY_VERSION=4.3.* USE_EXPERIMENTAL_EXECUTOR=1 SYMFONY_DEPRECATIONS_HELPER=max[total]=0
4446
- php: 7.3
4547
env: SYMFONY_VERSION=4.4.* STABILITY=dev SYMFONY_DEPRECATIONS_HELPER=max[total]=0
4648
- php: 7.3

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Documentation
4444
- [GraphQL schema language](docs/definitions/graphql-schema-language.md)
4545
- [Schema](docs/definitions/schema.md)
4646
- [Resolver](docs/definitions/resolver.md)
47+
- [Experimental coroutine executor](docs/definitions/coroutine-executor.md)
4748
- [Solving N+1 problem](docs/definitions/solving-n-plus-1-problem.md)
4849
- [Mutation](docs/definitions/mutation.md)
4950
- [Relay](docs/definitions/relay/index.md)

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"symfony/framework-bundle": "^3.4 || ^4.0",
3939
"symfony/options-resolver": "^3.4 || ^4.0",
4040
"symfony/property-access": "^3.4 || ^4.0",
41-
"webonyx/graphql-php": "^0.13.0"
41+
"webonyx/graphql-php": "^0.13.5"
4242
},
4343
"replace": {
4444
"overblog/graphql-php-generator": "self.version"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Experimental coroutine executor
2+
================================
3+
4+
[The experimental coroutine executor](https://github.com/webonyx/graphql-php/blob/0.13.x/UPGRADE.md#try-it-experimental-executor-with-improved-performance)
5+
can be enabled using configuration:
6+
7+
```yaml
8+
overblog_graphql:
9+
definitions:
10+
use_experimental_executor: true
11+
```

docs/definitions/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
## Go further
99

10+
- [Experimental coroutine executor](coroutine-executor.md)
1011
- [Solving N+1 problem](solving-n-plus-1-problem.md)
1112
- [Resolver](resolver.md)
1213
- [Mutation](mutation.md)

phpunit.xml.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
<php>
3030
<ini name="error_reporting" value="-1" />
3131
<env name="SYMFONY_DEPRECATIONS_HELPER" value="999999" />
32+
<env name="USE_EXPERIMENTAL_EXECUTOR" value="0" />
3233
</php>
3334
<listeners>
3435
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener" />

src/DependencyInjection/Configuration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ private function definitionsSection()
118118
->addDefaultsIfNotSet()
119119
->children()
120120
->scalarNode('argument_class')->defaultValue(Argument::class)->end()
121+
->scalarNode('use_experimental_executor')->defaultFalse()->end()
121122
->variableNode('default_resolver')->defaultValue([Resolver::class, 'defaultResolveFn'])->end()
122123
->scalarNode('class_namespace')->defaultValue('Overblog\\GraphQLBundle\\__DEFINITIONS__')->end()
123124
->scalarNode('cache_dir')->defaultNull()->end()

src/DependencyInjection/OverblogGraphQLExtension.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ private function setDefinitionParameters(array $config, ContainerBuilder $contai
121121
$container->setParameter($this->getAlias().'.cache_dir', $config['definitions']['cache_dir']);
122122
$container->setParameter($this->getAlias().'.cache_dir_permissions', $config['definitions']['cache_dir_permissions']);
123123
$container->setParameter($this->getAlias().'.argument_class', $config['definitions']['argument_class']);
124+
$container->setParameter($this->getAlias().'.use_experimental_executor', $config['definitions']['use_experimental_executor']);
124125
}
125126

126127
private function setBatchingMethod(array $config, ContainerBuilder $container): void

src/Request/Executor.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use GraphQL\Executor\ExecutionResult;
88
use GraphQL\Executor\Promise\PromiseAdapter;
9+
use GraphQL\GraphQL;
910
use GraphQL\Type\Schema;
1011
use GraphQL\Validator\DocumentValidator;
1112
use GraphQL\Validator\Rules\DisableIntrospection;
@@ -34,16 +35,20 @@ class Executor
3435

3536
private $defaultFieldResolver;
3637

38+
private $useExperimentalExecutor;
39+
3740
public function __construct(
3841
ExecutorInterface $executor,
3942
PromiseAdapter $promiseAdapter,
4043
EventDispatcherInterface $dispatcher,
41-
?callable $defaultFieldResolver = null
44+
?callable $defaultFieldResolver = null,
45+
bool $useExperimental = false
4246
) {
4347
$this->executor = $executor;
4448
$this->promiseAdapter = $promiseAdapter;
4549
$this->dispatcher = $dispatcher;
4650
$this->defaultFieldResolver = $defaultFieldResolver;
51+
$this->useExperimentalExecutor = $useExperimental;
4752
}
4853

4954
public function setExecutor(ExecutorInterface $executor): self
@@ -122,6 +127,8 @@ public function disableIntrospectionQuery(): void
122127
*/
123128
public function execute(?string $schemaName, array $request, $rootValue = null): ExecutionResult
124129
{
130+
$this->useExperimentalExecutor ? GraphQL::useExperimentalExecutor() : GraphQL::useReferenceExecutor();
131+
125132
$executorArgumentsEvent = $this->preExecute(
126133
$this->getSchema($schemaName),
127134
$request[ParserInterface::PARAM_QUERY] ?? null,

src/Resources/config/services.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ services:
1515
- "@overblog_graphql.promise_adapter"
1616
- "@event_dispatcher"
1717
- '%overblog_graphql.default_resolver%'
18+
- "%overblog_graphql.use_experimental_executor%"
1819
calls:
1920
- ["setMaxQueryComplexity", ["%overblog_graphql.query_max_complexity%"]]
2021
- ["setMaxQueryDepth", ["%overblog_graphql.query_max_depth%"]]

0 commit comments

Comments
 (0)