|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Drupal\graphql\Plugin\GraphQL\Schemas; |
|
4
|
|
|
|
|
5
|
|
|
use Drupal\Core\Plugin\ContainerFactoryPluginInterface; |
|
6
|
|
|
use Drupal\graphql\Plugin\GraphQL\PluggableSchemaManagerInterface; |
|
7
|
|
|
use Drupal\graphql\Plugin\GraphQL\PluggableSchemaPluginInterface; |
|
8
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
9
|
|
|
use Youshido\GraphQL\Schema\InternalSchemaMutationObject; |
|
10
|
|
|
use Youshido\GraphQL\Schema\InternalSchemaQueryObject; |
|
11
|
|
|
|
|
12
|
|
|
abstract class PluggableSchemaPluginBase extends SchemaPluginBase implements PluggableSchemaPluginInterface, ContainerFactoryPluginInterface { |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @param \Drupal\graphql\Plugin\GraphQL\PluggableSchemaManagerInterface $schemaManager |
|
16
|
|
|
* @return \Youshido\GraphQL\Schema\InternalSchemaMutationObject |
|
17
|
|
|
*/ |
|
18
|
|
|
protected static function getSchemaMutationObject(PluggableSchemaManagerInterface $schemaManager) { |
|
19
|
|
|
$mutation = new InternalSchemaMutationObject(['name' => 'RootMutation']); |
|
20
|
|
|
$mutation->addFields($schemaManager->getMutations()); |
|
21
|
|
|
|
|
22
|
|
|
return $mutation; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @param \Drupal\graphql\Plugin\GraphQL\PluggableSchemaManagerInterface $schemaManager |
|
27
|
|
|
* @return \Youshido\GraphQL\Schema\InternalSchemaQueryObject |
|
28
|
|
|
*/ |
|
29
|
|
|
protected static function getSchemaQueryObject(PluggableSchemaManagerInterface $schemaManager) { |
|
30
|
|
|
$query = new InternalSchemaQueryObject(['name' => 'RootQuery']); |
|
31
|
|
|
$query->addFields($schemaManager->getRootFields()); |
|
32
|
|
|
|
|
33
|
|
|
return $query; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @param \Drupal\graphql\Plugin\GraphQL\PluggableSchemaManagerInterface $schemaManager |
|
38
|
|
|
* @return \object[] |
|
39
|
|
|
*/ |
|
40
|
|
|
protected static function getSchemaTypesList(PluggableSchemaManagerInterface $schemaManager) { |
|
41
|
|
|
$types = $schemaManager->find(function() { |
|
42
|
|
|
return TRUE; |
|
43
|
|
|
}, [ |
|
44
|
|
|
GRAPHQL_UNION_TYPE_PLUGIN, |
|
45
|
|
|
GRAPHQL_TYPE_PLUGIN, |
|
46
|
|
|
GRAPHQL_INPUT_TYPE_PLUGIN, |
|
47
|
|
|
]); |
|
48
|
|
|
|
|
49
|
|
|
return $types; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @param \Drupal\graphql\Plugin\GraphQL\PluggableSchemaManagerInterface $schemaManager |
|
54
|
|
|
* @return array |
|
55
|
|
|
*/ |
|
56
|
|
|
protected static function getSchemaConfiguration(PluggableSchemaManagerInterface $schemaManager) { |
|
57
|
|
|
return [ |
|
58
|
|
|
'query' => static::getSchemaQueryObject($schemaManager), |
|
59
|
|
|
'mutation' => static::getSchemaMutationObject($schemaManager), |
|
60
|
|
|
'types' => static::getSchemaTypesList($schemaManager), |
|
61
|
|
|
]; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* {@inheritdoc} |
|
66
|
|
|
*/ |
|
67
|
|
|
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { |
|
68
|
|
|
/** @var \Drupal\graphql\Plugin\GraphQL\PluggableSchemaManagerFactory $schemaManagerFactory */ |
|
69
|
|
|
$schemaManagerFactory = $container->get('graphql.pluggable_schema_manager_factory'); |
|
70
|
|
|
$schemaManager = $schemaManagerFactory->getSchemaManager($plugin_id); |
|
71
|
|
|
$schemaConfig = static::getSchemaConfiguration($schemaManager); |
|
72
|
|
|
|
|
73
|
|
|
return new static($configuration + ['schema' => $schemaConfig], $plugin_id, $plugin_definition); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|