Skip to content

Commit 885c5d4

Browse files
authored
Refactoring schema builder logic. (#404)
1 parent 9f5f1b3 commit 885c5d4

44 files changed

Lines changed: 341 additions & 295 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

graphql.services.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,11 @@ services:
193193
- '\Drupal\graphql\Plugin\GraphQL\Schemas\SchemaPluginBase'
194194
- '\Drupal\graphql\Annotation\GraphQLSchema'
195195
- 'graphql_schemas'
196+
- '@service_container'
196197

197198
# Schema builder service. Collects all registered type system plugin managers.
198-
graphql.schema_builder_factory:
199-
class: Drupal\graphql\Plugin\GraphQL\SchemaBuilderFactory
199+
graphql.plugin_manager_aggregator:
200+
class: Drupal\graphql\Plugin\GraphQL\TypeSystemPluginManagerAggregator
200201
tags:
201202
- { name: service_collector, tag: graphql_plugin_manager, call: addPluginManager }
202203

modules/graphql_core/src/Plugin/GraphQL/Enums/Images/ImageStyleId.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace Drupal\graphql_core\Plugin\GraphQL\Enums\Images;
44

55
use Drupal\graphql\Plugin\GraphQL\Enums\EnumPluginBase;
6-
use Drupal\graphql\Plugin\GraphQL\SchemaBuilder;
6+
use Drupal\graphql\Plugin\GraphQL\SchemaBuilderInterface;
77
use Drupal\image\Entity\ImageStyle as ImageStyleConfig;
88

99
/**
@@ -15,7 +15,7 @@
1515
*/
1616
class ImageStyleId extends EnumPluginBase {
1717

18-
public function buildValues(SchemaBuilder $schemaManager) {
18+
public function buildValues(SchemaBuilderInterface $schemaManager) {
1919
$items = [];
2020
foreach (ImageStyleConfig::loadMultiple() as $imageStyle) {
2121
$items[$imageStyle->id()] = [

modules/graphql_core/src/Plugin/GraphQL/Enums/Languages/AvailableLanguages.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Drupal\Core\Language\LanguageManagerInterface;
66
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
77
use Drupal\graphql\Plugin\GraphQL\Enums\EnumPluginBase;
8-
use Drupal\graphql\Plugin\GraphQL\SchemaBuilder;
8+
use Drupal\graphql\Plugin\GraphQL\SchemaBuilderInterface;
99
use Symfony\Component\DependencyInjection\ContainerInterface;
1010

1111
/**
@@ -49,7 +49,7 @@ public static function create(ContainerInterface $container, array $configuratio
4949
/**
5050
* {@inheritdoc}
5151
*/
52-
public function buildValues(SchemaBuilder $schemaManager) {
52+
public function buildValues(SchemaBuilderInterface $schemaManager) {
5353
$values = [];
5454

5555
foreach ($this->languageManager->getLanguages() as $language) {

modules/graphql_core/src/Plugin/GraphQL/Fields/Context/Context.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use Drupal\Core\Plugin\Context\ContextRepositoryInterface;
77
use Drupal\graphql\GraphQL\Batching\BatchedFieldResolver;
88
use Drupal\graphql\Plugin\GraphQL\Fields\SubrequestFieldBase;
9-
use Drupal\graphql\Plugin\GraphQL\SchemaBuilder;
9+
use Drupal\graphql\Plugin\GraphQL\SchemaBuilderInterface;
1010
use Symfony\Component\DependencyInjection\ContainerInterface;
1111
use Symfony\Component\HttpFoundation\RequestStack;
1212
use Symfony\Component\HttpKernel\HttpKernelInterface;
@@ -68,7 +68,7 @@ public function __construct(
6868
/**
6969
* {@inheritdoc}
7070
*/
71-
protected function buildType(SchemaBuilder $schemaManager) {
71+
protected function buildType(SchemaBuilderInterface $schemaManager) {
7272
if ($this instanceof PluginInspectionInterface) {
7373
$definition = $this->getPluginDefinition();
7474
if (array_key_exists('data_type', $definition) && $definition['data_type']) {

modules/graphql_core/src/Plugin/GraphQL/Fields/Entity/EntityOwner.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace Drupal\graphql_core\Plugin\GraphQL\Fields\Entity;
44

55
use Drupal\graphql\Plugin\GraphQL\Fields\FieldPluginBase;
6-
use Drupal\graphql\Plugin\GraphQL\SchemaBuilder;
6+
use Drupal\graphql\Plugin\GraphQL\SchemaBuilderInterface;
77
use Drupal\user\EntityOwnerInterface;
88
use Youshido\GraphQL\Execution\ResolveInfo;
99

@@ -22,7 +22,7 @@ class EntityOwner extends FieldPluginBase {
2222
/**
2323
* {@inheritdoc}
2424
*/
25-
protected function buildType(SchemaBuilder $schemaManager) {
25+
protected function buildType(SchemaBuilderInterface $schemaManager) {
2626
try {
2727
return $schemaManager->findByName('User', [GRAPHQL_INTERFACE_PLUGIN]);
2828
}

modules/graphql_core/src/Plugin/GraphQL/Schemas/DefaultSchema.php

Lines changed: 3 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,63 +2,18 @@
22

33
namespace Drupal\graphql_core\Plugin\GraphQL\Schemas;
44

5-
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
65
use Drupal\graphql\Plugin\GraphQL\Schemas\SchemaPluginBase;
7-
use Symfony\Component\DependencyInjection\ContainerInterface;
8-
use Youshido\GraphQL\Config\Schema\SchemaConfig;
9-
use Youshido\GraphQL\Schema\InternalSchemaMutationObject;
10-
use Youshido\GraphQL\Schema\InternalSchemaQueryObject;
116

127
/**
138
* Default generated schema.
149
*
1510
* @GraphQLSchema(
1611
* id = "default",
1712
* name = "Default",
18-
* path = "/graphql"
13+
* path = "/graphql",
14+
* builder = "\Drupal\graphql\Plugin\GraphQL\PluggableSchemaBuilder"
1915
* )
2016
*/
21-
class DefaultSchema extends SchemaPluginBase implements ContainerFactoryPluginInterface {
17+
class DefaultSchema extends SchemaPluginBase {
2218

23-
/**
24-
* {@inheritdoc}
25-
*/
26-
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
27-
/** @var \Drupal\graphql\Plugin\GraphQL\SchemaBuilderFactory $schemaBuilderFactory */
28-
$schemaBuilderFactory = $container->get('graphql.schema_builder_factory');
29-
// TODO: Inject schema reducer configuration into the schema builder.
30-
$schemaBuilder = $schemaBuilderFactory->getSchemaBuilder();
31-
32-
$mutation = new InternalSchemaMutationObject(['name' => 'RootMutation']);
33-
34-
$query = new InternalSchemaQueryObject(['name' => 'RootQuery']);
35-
$query->addFields($schemaBuilder->getRootFields());
36-
37-
$types = $schemaBuilder->find(function() {
38-
return TRUE;
39-
}, [
40-
GRAPHQL_UNION_TYPE_PLUGIN,
41-
GRAPHQL_TYPE_PLUGIN,
42-
GRAPHQL_INPUT_TYPE_PLUGIN,
43-
]);
44-
45-
$schema = [
46-
'query' => $query,
47-
'mutation' => $mutation,
48-
'types' => $types,
49-
];
50-
51-
return new static(
52-
$configuration + ['schema' => $schema],
53-
$plugin_id,
54-
$plugin_definition
55-
);
56-
}
57-
58-
/**
59-
* {@inheritdoc}
60-
*/
61-
protected function constructSchema($configuration, $pluginId, $pluginDefinition) {
62-
$this->config = new SchemaConfig($configuration['schema']);
63-
}
6419
}

modules/graphql_legacy/graphql_image/src/Plugin/GraphQL/Enums/ImageStyleId.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace Drupal\graphql_image\Plugin\GraphQL\Enums;
44

55
use Drupal\graphql\Plugin\GraphQL\Enums\EnumPluginBase;
6-
use Drupal\graphql\Plugin\GraphQL\SchemaBuilder;
6+
use Drupal\graphql\Plugin\GraphQL\SchemaBuilderInterface;
77
use Drupal\image\Entity\ImageStyle as ImageStyleConfig;
88
use Youshido\GraphQL\Type\Enum\AbstractEnumType;
99

@@ -15,7 +15,7 @@
1515
*/
1616
class ImageStyleId extends EnumPluginBase {
1717

18-
public function buildValues(SchemaBuilder $schemaManager) {
18+
public function buildValues(SchemaBuilderInterface $schemaManager) {
1919
$items = [];
2020
foreach (ImageStyleConfig::loadMultiple() as $imageStyle) {
2121
$items[$imageStyle->id()] = [

modules/graphql_legacy/graphql_image/src/Plugin/GraphQL/Enums/ResponsiveImageStyleId.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace Drupal\graphql_image\Plugin\GraphQL\Enums;
44

55
use Drupal\graphql\Plugin\GraphQL\Enums\EnumPluginBase;
6-
use Drupal\graphql\Plugin\GraphQL\SchemaBuilder;
6+
use Drupal\graphql\Plugin\GraphQL\SchemaBuilderInterface;
77
use Drupal\responsive_image\Entity\ResponsiveImageStyle;
88

99
/**
@@ -14,7 +14,7 @@
1414
*/
1515
class ResponsiveImageStyleId extends EnumPluginBase {
1616

17-
public function buildValues(SchemaBuilder $schemaManager) {
17+
public function buildValues(SchemaBuilderInterface $schemaManager) {
1818
$items = [];
1919
foreach (ResponsiveImageStyle::loadMultiple() as $responsiveImageStyle) {
2020
$items[$responsiveImageStyle->id()] = [

src/Annotation/GraphQLSchema.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ public function __construct($values) {
4242
*/
4343
public $path;
4444

45+
/**
46+
* Whether the schema uses the type plugin system.
47+
*
48+
* @var string
49+
*/
50+
public $builder = '\Drupal\graphql\Plugin\GraphQL\PluggableSchemaBuilder';
51+
4552
/**
4653
* Weight for precedence calculations.
4754
*

src/Plugin/GraphQL/Enums/EnumPluginBase.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
namespace Drupal\graphql\Plugin\GraphQL\Enums;
44

5-
use Drupal\Core\Cache\CacheableDependencyInterface;
6-
use Drupal\graphql\Plugin\GraphQL\SchemaBuilder;
5+
use Drupal\graphql\Plugin\GraphQL\SchemaBuilderInterface;
76
use Drupal\graphql\Plugin\GraphQL\Traits\CacheablePluginTrait;
87
use Drupal\graphql\Plugin\GraphQL\Traits\NamedPluginTrait;
98
use Drupal\graphql\Plugin\GraphQL\Traits\PluginTrait;
@@ -29,7 +28,7 @@ public function __construct(array $configuration, $pluginId, $pluginDefinition)
2928
/**
3029
* {@inheritdoc}
3130
*/
32-
abstract public function buildValues(SchemaBuilder $schemaManager);
31+
abstract public function buildValues(SchemaBuilderInterface $schemaManager);
3332

3433
/**
3534
* {@inheritdoc}
@@ -41,7 +40,7 @@ public function getValues() {
4140
/**
4241
* {@inheritdoc}
4342
*/
44-
public function buildConfig(SchemaBuilder $schemaManager) {
43+
public function buildConfig(SchemaBuilderInterface $schemaManager) {
4544
$this->config = new EnumTypeConfig([
4645
'name' => $this->buildName(),
4746
'description' => $this->buildDescription(),

0 commit comments

Comments
 (0)