1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Drupal\graphql_core\Plugin\GraphQL\Schemas; |
4
|
|
|
|
5
|
|
|
use Drupal\Core\Plugin\ContainerFactoryPluginInterface; |
6
|
|
|
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; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Default generated schema. |
14
|
|
|
* |
15
|
|
|
* @GraphQLSchema( |
16
|
|
|
* id = "default", |
17
|
|
|
* name = "Default", |
18
|
|
|
* path = "/graphql" |
19
|
|
|
* ) |
20
|
|
|
*/ |
21
|
|
|
class DefaultSchema extends SchemaPluginBase implements ContainerFactoryPluginInterface { |
22
|
|
|
|
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
|
|
|
$mutation->addFields($schemaBuilder->getMutations()); |
34
|
|
|
|
35
|
|
|
$query = new InternalSchemaQueryObject(['name' => 'RootQuery']); |
36
|
|
|
$query->addFields($schemaBuilder->getRootFields()); |
37
|
|
|
|
38
|
|
|
$types = $schemaBuilder->find(function() { |
39
|
|
|
return TRUE; |
40
|
|
|
}, [ |
41
|
|
|
GRAPHQL_UNION_TYPE_PLUGIN, |
42
|
|
|
GRAPHQL_TYPE_PLUGIN, |
43
|
|
|
GRAPHQL_INPUT_TYPE_PLUGIN, |
44
|
|
|
]); |
45
|
|
|
|
46
|
|
|
$schema = [ |
47
|
|
|
'query' => $query, |
48
|
|
|
'mutation' => $mutation, |
49
|
|
|
'types' => $types, |
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']); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|