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: 2 additions & 1 deletion Controller/GraphController.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ private function createResponse(Request $request, $schemaName, $batched)
private function processBatchQuery(Request $request, $schemaName = null)
{
$queries = $this->get('overblog_graphql.request_batch_parser')->parse($request);
$apolloBatching = 'apollo' === $this->getParameter('overblog_graphql.batching_method');
$payloads = [];

foreach ($queries as $query) {
Expand All @@ -71,7 +72,7 @@ private function processBatchQuery(Request $request, $schemaName = null)
[],
$schemaName
);
$payloads[] = ['id' => $query['id'], 'payload' => $payloadResult->toArray()];
$payloads[] = $apolloBatching ? $payloadResult->toArray() : ['id' => $query['id'], 'payload' => $payloadResult->toArray()];
}

return $payloads;
Expand Down
4 changes: 4 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ public function getConfigTreeBuilder()

$rootNode
->children()
->enumNode('batching_method')
->values(['relay', 'apollo'])
->defaultValue('relay')
->end()
->arrayNode('definitions')
->addDefaultsIfNotSet()
->children()
Expand Down
6 changes: 6 additions & 0 deletions DependencyInjection/OverblogGraphQLExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public function load(array $configs, ContainerBuilder $container)

$config = $this->treatConfigs($configs, $container);

$this->setBatchingMethod($config, $container);
$this->setExpressionLanguageDefaultParser($container);
$this->setServicesAliases($config, $container);
$this->setSchemaBuilderArguments($config, $container);
Expand Down Expand Up @@ -76,6 +77,11 @@ private function setAutoMappingParameters(array $config, ContainerBuilder $conta
$container->setParameter($this->getAlias().'.auto_mapping.directories', $config['definitions']['auto_mapping']['directories']);
}

private function setBatchingMethod(array $config, ContainerBuilder $container)
{
$container->setParameter($this->getAlias().'.batching_method', $config['batching_method']);
}

private function setExpressionLanguageDefaultParser(ContainerBuilder $container)
{
$class = version_compare(Kernel::VERSION, '3.2.0', '>=') ? ArrayAdapter::class : ArrayParserCache::class;
Expand Down
19 changes: 19 additions & 0 deletions Resources/doc/data-fetching/batching.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Query batching

The bundle supports batching using [ReactRelayNetworkLayer](https://github.com/nodkz/react-relay-network-layer) or [Apollo GraphQL](http://dev.apollodata.com/core/network.html#query-batching) directly.
To use batching, you must use "/batch" as a suffix to your graphql endpoint (see routing config).
Then you can switch between implementations in your configuration like so:

For Relay (default value):
```yaml
overblog_graphql:
batching_method: "relay"
```

For Apollo:
```yaml
overblog_graphql:
batching_method: "apollo"
```

Done!
1 change: 1 addition & 0 deletions Resources/doc/data-fetching/index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Data fetching
=============

* [Batching](batching.md)
* [Promise](promise.md)

Next step [secure your server](../security/index.md).
4 changes: 2 additions & 2 deletions Resources/doc/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ OverblogGraphQLBundle

This Symfony 2 / 3 bundle provide integration [GraphQL](https://facebook.github.io/graphql/) using [webonyx/graphql-php](https://github.com/webonyx/graphql-php)
and [GraphQL Relay](https://facebook.github.io/relay/docs/graphql-relay-specification.html).
It also supports batching using libs like [ReactRelayNetworkLayer](https://github.com/nodkz/react-relay-network-layer).
It also supports batching using libs like [ReactRelayNetworkLayer](https://github.com/nodkz/react-relay-network-layer) or [Apollo GraphQL](http://dev.apollodata.com/core/network.html#query-batching).

Requirements
------------
Expand Down Expand Up @@ -54,4 +54,4 @@ overblog_graphql_graphiql:
resource: "@OverblogGraphQLBundle/Resources/config/routing/graphiql.yml"
```

Now you can define your [graphQL schema](definitions/index.md).
Now you can define your [graphQL schema](definitions/index.md).