Skip to content

Commit 5946f2e

Browse files
fubhypmelab
authored andcommitted
Removing run-time dependency on schema manager and adding ability to … (#401)
* Removing run-time dependency on schema manager and adding ability to have multiple instances of the schema manager. * Fixing docblocks. * Fixing test schema. * Fixing tests. * Triggering tests.
1 parent debf709 commit 5946f2e

Some content is hidden

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

43 files changed

+500
-534
lines changed

graphql.services.yml

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ services:
7878
- '@graphql.schema_loader'
7979
- '@current_user'
8080
- '%graphql.config%'
81+
8182
graphql.schema_loader:
8283
class: Drupal\graphql\GraphQL\Schema\SchemaLoader
8384
arguments:
@@ -182,12 +183,6 @@ services:
182183
graphql.batched_resolver:
183184
class: Drupal\graphql\GraphQL\Batching\BatchedFieldResolver
184185

185-
# Plugin system based schema manager.
186-
graphql.pluggable_schema_manager:
187-
class: Drupal\graphql\Plugin\GraphQL\PluggableSchemaManager
188-
tags:
189-
- { name: service_collector, tag: graphql_plugin_manager, call: addPluginManager }
190-
191186
# Plugin manager for schemas
192187
plugin.manager.graphql.schema:
193188
class: Drupal\graphql\Plugin\GraphQL\SchemaPluginManager
@@ -199,13 +194,17 @@ services:
199194
- '\Drupal\graphql\Annotation\GraphQLSchema'
200195
- 'graphql_schemas'
201196

197+
# Schema builder service. Collects all registered type system plugin managers.
198+
graphql.schema_builder_factory:
199+
class: Drupal\graphql\Plugin\GraphQL\SchemaBuilderFactory
200+
tags:
201+
- { name: service_collector, tag: graphql_plugin_manager, call: addPluginManager }
202+
202203
# Plugin manager implementations for schema types.
203204
plugin.manager.graphql.union_type:
204205
class: Drupal\graphql\Plugin\GraphQL\TypeSystemPluginManager
205206
tags:
206207
- { name: graphql_plugin_manager }
207-
calls:
208-
- [setSchemaManager, ['@graphql.pluggable_schema_manager']]
209208
arguments:
210209
- 'Plugin/GraphQL/UnionTypes'
211210
- '@container.namespaces'
@@ -218,8 +217,6 @@ services:
218217
class: Drupal\graphql\Plugin\GraphQL\TypeSystemPluginManager
219218
tags:
220219
- { name: graphql_plugin_manager }
221-
calls:
222-
- [setSchemaManager, ['@graphql.pluggable_schema_manager']]
223220
arguments:
224221
- 'Plugin/GraphQL/Interfaces'
225222
- '@container.namespaces'
@@ -232,8 +229,6 @@ services:
232229
class: Drupal\graphql\Plugin\GraphQL\TypeSystemPluginManager
233230
tags:
234231
- { name: graphql_plugin_manager }
235-
calls:
236-
- [setSchemaManager, ['@graphql.pluggable_schema_manager']]
237232
arguments:
238233
- 'Plugin/GraphQL/Types'
239234
- '@container.namespaces'
@@ -246,8 +241,6 @@ services:
246241
class: Drupal\graphql\Plugin\GraphQL\TypeSystemPluginManager
247242
tags:
248243
- { name: graphql_plugin_manager }
249-
calls:
250-
- [setSchemaManager, ['@graphql.pluggable_schema_manager']]
251244
arguments:
252245
- 'Plugin/GraphQL/InputTypes'
253246
- '@container.namespaces'
@@ -260,8 +253,6 @@ services:
260253
class: Drupal\graphql\Plugin\GraphQL\TypeSystemPluginManager
261254
tags:
262255
- { name: graphql_plugin_manager }
263-
calls:
264-
- [setSchemaManager, ['@graphql.pluggable_schema_manager']]
265256
arguments:
266257
- 'Plugin/GraphQL/Fields'
267258
- '@container.namespaces'
@@ -274,8 +265,6 @@ services:
274265
class: Drupal\graphql\Plugin\GraphQL\TypeSystemPluginManager
275266
tags:
276267
- { name: graphql_plugin_manager }
277-
calls:
278-
- [setSchemaManager, ['@graphql.pluggable_schema_manager']]
279268
arguments:
280269
- 'Plugin/GraphQL/Mutations'
281270
- '@container.namespaces'
@@ -288,8 +277,6 @@ services:
288277
class: Drupal\graphql\Plugin\GraphQL\TypeSystemPluginManager
289278
tags:
290279
- { name: graphql_plugin_manager }
291-
calls:
292-
- [setSchemaManager, ['@graphql.pluggable_schema_manager']]
293280
arguments:
294281
- 'Plugin/GraphQL/Scalars'
295282
- '@container.namespaces'
@@ -302,8 +289,6 @@ services:
302289
class: Drupal\graphql\Plugin\GraphQL\TypeSystemPluginManager
303290
tags:
304291
- { name: graphql_plugin_manager }
305-
calls:
306-
- [setSchemaManager, ['@graphql.pluggable_schema_manager']]
307292
arguments:
308293
- 'Plugin/GraphQL/Enums'
309294
- '@container.namespaces'

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

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

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

99
/**
1010
* @GraphQLEnum(
1111
* id = "image_style_id",
12-
* name = "ImageStyleId"
12+
* name = "ImageStyleId",
13+
* provider = "image"
1314
* )
1415
*/
1516
class ImageStyleId extends EnumPluginBase {
1617

17-
public function buildValues(PluggableSchemaManagerInterface $schemaManager) {
18+
public function buildValues(SchemaBuilder $schemaManager) {
1819
$items = [];
1920
foreach (ImageStyleConfig::loadMultiple() as $imageStyle) {
2021
$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\PluggableSchemaManagerInterface;
8+
use Drupal\graphql\Plugin\GraphQL\SchemaBuilder;
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(PluggableSchemaManagerInterface $schemaManager) {
52+
public function buildValues(SchemaBuilder $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\PluggableSchemaManagerInterface;
9+
use Drupal\graphql\Plugin\GraphQL\SchemaBuilder;
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(PluggableSchemaManagerInterface $schemaManager) {
71+
protected function buildType(SchemaBuilder $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\PluggableSchemaManagerInterface;
6+
use Drupal\graphql\Plugin\GraphQL\SchemaBuilder;
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(PluggableSchemaManagerInterface $schemaManager) {
25+
protected function buildType(SchemaBuilder $schemaManager) {
2626
try {
2727
return $schemaManager->findByName('User', [GRAPHQL_INTERFACE_PLUGIN]);
2828
}

modules/graphql_core/src/Plugin/GraphQL/Fields/Images/ImageDerivative.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
* field_types = {
2727
* "image"
2828
* },
29+
* provider = "image",
2930
* deriver = "Drupal\graphql_core\Plugin\Deriver\Fields\EntityFieldPropertyDeriver"
3031
* )
3132
*/

modules/graphql_core/src/Plugin/GraphQL/Fields/Images/ImageResourceHeight.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* name = "height",
1616
* type = "Int",
1717
* nullable = true,
18+
* provider = "image",
1819
* parents = {"ImageResource"},
1920
* field_types = {"image"},
2021
* deriver = "Drupal\graphql_core\Plugin\Deriver\Fields\EntityFieldPropertyDeriver"

modules/graphql_core/src/Plugin/GraphQL/Fields/Images/ImageResourceUrl.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* nullable = true,
1818
* parents = {"ImageResource"},
1919
* field_types = {"image"},
20+
* provider = "image",
2021
* deriver = "Drupal\graphql_core\Plugin\Deriver\Fields\EntityFieldPropertyDeriver"
2122
* )
2223
*/

modules/graphql_core/src/Plugin/GraphQL/Fields/Images/ImageResourceWidth.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* name = "width",
1616
* type = "Int",
1717
* nullable = true,
18+
* provider = "image",
1819
* parents = {"ImageResource"},
1920
* field_types = {"image"},
2021
* deriver = "Drupal\graphql_core\Plugin\Deriver\Fields\EntityFieldPropertyDeriver"

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

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Drupal\graphql_core\Plugin\GraphQL\Schemas;
44

55
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
6-
use Drupal\graphql\Plugin\GraphQL\SchemaPluginInterface;
76
use Drupal\graphql\Plugin\GraphQL\Schemas\SchemaPluginBase;
87
use Symfony\Component\DependencyInjection\ContainerInterface;
98
use Youshido\GraphQL\Config\Schema\SchemaConfig;
@@ -19,40 +18,48 @@
1918
* path = "/graphql"
2019
* )
2120
*/
22-
class DefaultSchema extends SchemaPluginBase implements SchemaPluginInterface, ContainerFactoryPluginInterface {
23-
24-
/**
25-
* The pluggable schema manager service.
26-
*
27-
* @var \Drupal\graphql\Plugin\GraphQL\PluggableSchemaManagerInterface
28-
*/
29-
protected $schemaManager;
21+
class DefaultSchema extends SchemaPluginBase implements ContainerFactoryPluginInterface {
3022

3123
/**
3224
* {@inheritdoc}
3325
*/
3426
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
35-
/** @var \Drupal\graphql\Plugin\GraphQL\PluggableSchemaManagerInterface $schemaManager */
36-
$schemaManager = $container->get('graphql.pluggable_schema_manager');
37-
38-
$query = new InternalSchemaQueryObject(['name' => 'RootQuery']);
39-
$query->addFields($schemaManager->getRootFields());
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();
4031

4132
$mutation = new InternalSchemaMutationObject(['name' => 'RootMutation']);
42-
$mutation->addFields($schemaManager->getMutations());
33+
$mutation->addFields($schemaBuilder->getMutations());
34+
35+
$query = new InternalSchemaQueryObject(['name' => 'RootQuery']);
36+
$query->addFields($schemaBuilder->getRootFields());
4337

44-
$types = $schemaManager->find(function() {
38+
$types = $schemaBuilder->find(function() {
4539
return TRUE;
4640
}, [
4741
GRAPHQL_UNION_TYPE_PLUGIN,
4842
GRAPHQL_TYPE_PLUGIN,
4943
GRAPHQL_INPUT_TYPE_PLUGIN,
5044
]);
5145

52-
return new static($configuration + ['schema' => [
46+
$schema = [
5347
'query' => $query,
5448
'mutation' => $mutation,
5549
'types' => $types,
56-
]], $plugin_id, $plugin_definition);
50+
];
51+
52+
return new static(
53+
$configuration + ['schema' => $schema],
54+
$plugin_id,
55+
$plugin_definition
56+
);
57+
}
58+
59+
/**
60+
* {@inheritdoc}
61+
*/
62+
protected function constructSchema($configuration, $pluginId, $pluginDefinition) {
63+
$this->config = new SchemaConfig($configuration['schema']);
5764
}
5865
}

0 commit comments

Comments
 (0)