77namespace Ibexa \GraphQL \Resolver ;
88
99use GraphQL \Error \UserError ;
10+ use Ibexa \Contracts \Core \Repository \Values \Content \Content ;
1011use Ibexa \Contracts \Core \Repository \Values \Content \Query ;
1112use Ibexa \Core \FieldType ;
1213use Ibexa \GraphQL \DataLoader \ContentLoader ;
@@ -36,7 +37,7 @@ public function __construct(
3637 $ this ->enablePagination = $ enablePagination ;
3738 }
3839
39- public function resolveRelationFieldValue (Field $ field , $ multiple = false , Argument $ args )
40+ public function resolveRelationFieldValue (Field $ field , $ multiple = false , ? Argument $ args = null )
4041 {
4142 $ destinationContentIds = $ this ->getContentIds ($ field );
4243
@@ -49,13 +50,13 @@ public function resolveRelationFieldValue(Field $field, $multiple = false, Argum
4950 );
5051
5152 if ($ multiple ) {
52- if (!$ this ->enablePagination ) {
53+ if (!$ this ->enablePagination || $ args === null ) {
5354 $ contentItems = $ this ->contentLoader ->find ($ query );
5455
5556 return array_map (
56- function ($ contentId ) use ($ contentItems ) {
57+ function (int $ contentId ) use ($ contentItems ) {
5758 return $ this ->itemFactory ->fromContent (
58- $ contentItems [array_search ($ contentId , array_column ($ contentItems , 'id ' ))]
59+ $ contentItems [array_search ($ contentId , array_column ($ contentItems , 'id ' ), true )]
5960 );
6061 },
6162 $ destinationContentIds
@@ -68,7 +69,7 @@ function ($contentId) use ($contentItems) {
6869 $ contentItems = $ this ->contentLoader ->find ($ query );
6970
7071 return array_map (
71- function ($ content ) {
72+ function (Content $ content ) {
7273 return $ this ->itemFactory ->fromContent (
7374 $ content
7475 );
@@ -103,11 +104,13 @@ private function getContentIds(Field $field): array
103104 {
104105 if ($ field ->value instanceof FieldType \RelationList \Value) {
105106 return $ field ->value ->destinationContentIds ;
106- } elseif ($ field ->value instanceof FieldType \Relation \Value) {
107+ }
108+
109+ if ($ field ->value instanceof FieldType \Relation \Value) {
107110 return [$ field ->value ->destinationContentId ];
108- } else {
109- throw new UserError ('\$field does not contain a RelationList or Relation Field value ' );
110111 }
112+
113+ throw new UserError ('\$field does not contain a RelationList or Relation Field value ' );
111114 }
112115}
113116
0 commit comments