-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathNodeResolver.php
More file actions
75 lines (65 loc) · 1.98 KB
/
NodeResolver.php
File metadata and controls
75 lines (65 loc) · 1.98 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
namespace BD\EzPlatformGraphQLBundle\GraphQL\Relay;
use BD\EzPlatformGraphQLBundle\DomainContent\NameHelper;
use eZ\Publish\API\Repository\ContentService;
use eZ\Publish\API\Repository\ContentTypeService;
use eZ\Publish\API\Repository\Values\Content\ContentInfo;
use Overblog\GraphQLBundle\Relay\Node\GlobalId;
use Overblog\GraphQLBundle\Resolver\TypeResolver;
class NodeResolver
{
/**
* @var ContentService
*/
private $contentService;
/**
* @var TypeResolver
*/
private $typeResolver;
/**
* @var ContentTypeService
*/
private $contentTypeService;
/**
* @var NameHelper
*/
private $nameHelper;
public function __construct(ContentService $contentService, TypeResolver $typeResolver, ContentTypeService $contentTypeService, NameHelper $nameHelper)
{
$this->contentService = $contentService;
$this->typeResolver = $typeResolver;
$this->contentTypeService = $contentTypeService;
$this->nameHelper = $nameHelper;
}
/**
* @param $globalId
*
* @return null|\eZ\Publish\API\Repository\Values\Content\ContentInfo
*
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
*/
public function resolveNode($globalId)
{
$params = GlobalId::fromGlobalId($globalId);
if (in_array($params['type'], ['Content', 'DomainContent'])) {
return $this->contentService->loadContentInfo($params['id']);
}
return null;
}
/**
* @param $object
*
* @return \GraphQL\Type\Definition\Type
*/
public function resolveType($object)
{
if ($object instanceof ContentInfo) {
return $this->typeResolver->resolve(
$this->nameHelper->domainContentName(
$this->contentTypeService->loadContentType($object->contentTypeId)
)
);
}
}
}