-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAutoEntitiesType.php
43 lines (37 loc) · 1.21 KB
/
AutoEntitiesType.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
namespace AlanKent\GraphQL\Types;
use GraphQL\Type\Definition\ObjectType;
use GraphQL\Type\Definition\ResolveInfo;
use GraphQL\Type\Definition\Type;
use GraphQL\Type\Definition\NonNull;
use Magento\Webapi\Model\ServiceMetadata;
/**
* Object type for querying the available entities (*RepositoryInterface service contracts).
* This class might go away.
*/
class AutoEntitiesType extends ObjectType
{
/**
* Constructor.
* param \Magento\Webapi\Model\ServiceMetadata $serviceMetadata
* @param \AlanKent\GraphQL\Persistence\EntityManager $entityManager
*/
public function __construct(
\AlanKent\GraphQL\Persistence\EntityManager $entityManager
) {
$fields = [];
foreach ($entityManager->listEntities() as $entityName) {
$entity = $entityManager->getEntity($entityName);
$fields[$entityName] = [
'type' => $entity->getType(),
'description' => $entity->getDescription(),
];
}
$config = [
'name' => 'AutoEntities',
'description' => 'All repository interfaces exposed via GraphQL.',
'fields' => $fields,
];
parent::__construct($config);
}
}