2121use Pimcore \Bundle \DataHubBundle \GraphQL \Exception \ClientSafeException ;
2222use Pimcore \Bundle \DataHubBundle \GraphQL \FieldHelper \AbstractFieldHelper ;
2323use Pimcore \Bundle \DataHubBundle \GraphQL \Service ;
24+ use Pimcore \Bundle \DataHubBundle \GraphQL \Traits \ElementLoaderTrait ;
2425use Pimcore \Bundle \DataHubBundle \GraphQL \Traits \ElementTagTrait ;
2526use Pimcore \Bundle \DataHubBundle \GraphQL \Traits \ServiceTrait ;
2627use Pimcore \Bundle \DataHubBundle \WorkspaceHelper ;
2930use Pimcore \Model \DataObject \AbstractObject ;
3031use Pimcore \Model \Document ;
3132use Pimcore \Model \Element \ElementInterface ;
32- use Pimcore \Model \Element \Service as ElementService ;
3333use Pimcore \Model \Property ;
3434
3535class Element
3636{
37- use ServiceTrait, ElementTagTrait;
37+ use ServiceTrait, ElementTagTrait, ElementLoaderTrait ;
3838
3939 /** @var string */
4040 protected $ elementType ;
@@ -57,7 +57,7 @@ public function __construct(string $elementType, Service $graphQlService)
5757 */
5858 public function resolveTag ($ value = null , $ args = [], $ context = [], ResolveInfo $ resolveInfo = null )
5959 {
60- $ element = $ value[ElementInterface::class] ?? ElementService:: getElementById ( $ this ->elementType , $ value [ ' id ' ] );
60+ $ element = $ this -> loadDataElement ( $ value, $ this ->elementType );
6161
6262 if ($ element ) {
6363 $ result = $ this ->getTags ('document ' , $ element ->getId ());
@@ -82,7 +82,7 @@ public function resolveTag($value = null, $args = [], $context = [], ResolveInfo
8282 public function resolveProperties ($ value = null , array $ args = [], array $ context = [], ResolveInfo $ resolveInfo = null )
8383 {
8484 $ elementId = $ value ['id ' ];
85- $ element = $ value[ElementInterface::class] ?? ElementService:: getElementById ( $ this ->elementType , $ elementId );
85+ $ element = $ this -> loadDataElement ( $ value, $ this ->elementType );
8686
8787 if (!$ element ) {
8888 throw new ClientSafeException ('element ' . $ this ->elementType . ' ' . $ elementId . ' not found ' );
@@ -116,7 +116,7 @@ public function resolveProperties($value = null, array $args = [], array $contex
116116 */
117117 public function resolveParent ($ value = null , $ args = [], $ context = [], ResolveInfo $ resolveInfo = null )
118118 {
119- $ element = $ value[ElementInterface::class] ?? ElementService:: getElementById ( $ this ->elementType , $ value [ ' id ' ] );
119+ $ element = $ this -> loadDataElement ( $ value, $ this ->elementType );
120120 if ($ element ) {
121121 $ parent = $ element ->getParent ();
122122 if ($ parent ) {
@@ -139,7 +139,7 @@ public function resolveParent($value = null, $args = [], $context = [], ResolveI
139139 */
140140 public function resolveChildren ($ value = null , $ args = [], $ context = [], ResolveInfo $ resolveInfo = null )
141141 {
142- $ element = $ value[ElementInterface::class] ?? ElementService:: getElementById ( $ this ->elementType , $ value [ ' id ' ] );
142+ $ element = $ this -> loadDataElement ( $ value, $ this ->elementType );
143143
144144 if ($ element ) {
145145 $ arguments = $ this ->composeArguments ($ args );
@@ -162,7 +162,7 @@ public function resolveChildren($value = null, $args = [], $context = [], Resolv
162162 */
163163 public function resolveSiblings ($ value = null , $ args = [], $ context = [], ResolveInfo $ resolveInfo = null )
164164 {
165- $ element = $ value[ElementInterface::class] ?? ElementService:: getElementById ( $ this ->elementType , $ value [ ' id ' ] );
165+ $ element = $ this -> loadDataElement ( $ value, $ this ->elementType );
166166 if ($ element ) {
167167 $ arguments = $ this ->composeArguments ($ args );
168168
0 commit comments