Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add compiler pass to collect GraphQL query and mutation types
- Loading branch information
Showing
6 changed files
with
156 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,89 @@ | |||
<?php declare(strict_types=1); | |||
|
|||
/** | |||
* Copyright © OXID eSales AG. All rights reserved. | |||
* See LICENSE file for license details. | |||
*/ | |||
|
|||
namespace OxidEsales\EshopCommunity\Internal\Application\Utility; | |||
|
|||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | |||
use Symfony\Component\DependencyInjection\ContainerBuilder; | |||
use Symfony\Component\DependencyInjection\Reference; | |||
|
|||
/** | |||
* Class GraphQlTypePass | |||
* | |||
* This class configures the query/mutation type factories used | |||
* to build the GraphQL schema. It collects all appropriately | |||
* tagged queries / mutations and places them into the factories. | |||
* | |||
* @package OxidEsales\EshopCommunity\Internal\Application\Utility | |||
*/ | |||
class GraphQlTypePass implements CompilerPassInterface | |||
{ | |||
|
|||
/** | |||
* @var string $queryTypeFactoryId The container key for the query | |||
* type factory | |||
*/ | |||
protected $queryTypeFactoryId; | |||
/** | |||
* @var string $queryTypeTag The tag string for query types | |||
*/ | |||
protected $queryTypeTag; | |||
/** | |||
* @var string $mutationTypeFactoryId The container key for the | |||
* mutation type factory | |||
*/ | |||
protected $mutationTypeFactoryId; | |||
/** | |||
* @var string $mutationTypeTag The tag string for the mutation types | |||
*/ | |||
protected $mutationTypeTag; | |||
|
|||
/** | |||
* GraphQlTypePass constructor. | |||
* | |||
* @param string $queryTypeFactoryId | |||
* @param string $queryTypeTag | |||
* @param string $mutationTypeFactoryId | |||
* @param string $mutationTypeTag | |||
*/ | |||
public function __construct( | |||
$queryTypeFactoryId = 'query_type_factory', | |||
$queryTypeTag = 'graphql_query_type', | |||
$mutationTypeFactoryId = 'mutation_type_factory', | |||
$mutationTypeTag = 'graphql_mutation_type' | |||
) { | |||
$this->queryTypeFactoryId = $queryTypeFactoryId; | |||
$this->queryTypeTag = $queryTypeTag; | |||
$this->mutationTypeFactoryId = $mutationTypeFactoryId; | |||
$this->mutationTypeTag = $mutationTypeTag; | |||
} | |||
|
|||
/** | |||
* @param ContainerBuilder $container | |||
* @return null | |||
*/ | |||
public function process(ContainerBuilder $container) | |||
{ | |||
if (!$container->hasDefinition($this->queryTypeFactoryId) && !$container->hasAlias($this->queryTypeFactoryId)) { | |||
return; | |||
} | |||
|
|||
if (!$container->hasDefinition($this->mutationTypeFactoryId) && !$container->hasAlias($this->mutationTypeFactoryId)) { | |||
return; | |||
} | |||
|
|||
$queryTypeFactoryDefinition = $container->findDefinition($this->queryTypeFactoryId); | |||
$mutationTypeFactoryDefinition = $container->findDefinition($this->mutationTypeFactoryId); | |||
|
|||
foreach ($container->findTaggedServiceIds($this->queryTypeTag, true) as $id => $type) { | |||
$queryTypeFactoryDefinition->addMethodCall('addSubType', array(new Reference($id))); | |||
} | |||
foreach ($container->findTaggedServiceIds($this->mutationTypeTag, true) as $id => $type) { | |||
$mutationTypeFactoryDefinition->addMethodCall('addSubType', array(new Reference($id))); | |||
} | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
tests/Integration/Internal/Application/Fixtures/CE/Internal/Application/DummyGraphQLType.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,12 @@ | |||
<?php declare(strict_types=1); | |||
|
|||
namespace OxidEsales\EshopCommunity\Tests\Integration\Internal\Application\Fixtures\CE\Internal\Application; | |||
|
|||
class DummyGraphQLType | |||
{ | |||
public function getInfo() | |||
{ | |||
return 'Type is installed'; | |||
} | |||
|
|||
} |
28 changes: 28 additions & 0 deletions
28
...gration/Internal/Application/Fixtures/CE/Internal/Application/DummyGraphQLTypeFactory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,28 @@ | |||
<?php declare(strict_types=1); | |||
|
|||
namespace OxidEsales\EshopCommunity\Tests\Integration\Internal\Application\Fixtures\CE\Internal\Application; | |||
|
|||
/** | |||
* Copyright © OXID eSales AG. All rights reserved. | |||
* See LICENSE file for license details. | |||
*/ | |||
|
|||
class DummyGraphQLTypeFactory | |||
{ | |||
|
|||
/** | |||
* @var DummyGraphQLType | |||
*/ | |||
private $type = null; | |||
|
|||
public function addSubType($type) | |||
{ | |||
$this->type = $type; | |||
} | |||
|
|||
public function verifySubType() | |||
{ | |||
return $this->type !== null && $this->type->getInfo() == 'Type is installed'; | |||
} | |||
|
|||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters