| @@ 26-67 (lines=42) @@ | ||
| 23 | use Overblog\GraphQLBundle\Relay\Connection\Output\ConnectionBuilder; |
|
| 24 | use function count; |
|
| 25 | ||
| 26 | final class CommentAuthorsResolver |
|
| 27 | { |
|
| 28 | /** |
|
| 29 | * @var UserRepositoryInterface |
|
| 30 | */ |
|
| 31 | private $userRepository; |
|
| 32 | ||
| 33 | /** |
|
| 34 | * @var FindAuthorIdByCommentIdQueryInterface |
|
| 35 | */ |
|
| 36 | private $findAuthorIdByCommentIdQuery; |
|
| 37 | ||
| 38 | public function __construct( |
|
| 39 | UserRepositoryInterface $userRepository, |
|
| 40 | FindAuthorIdByCommentIdQueryInterface $findAuthorIdByCommentIdQuery |
|
| 41 | ) { |
|
| 42 | $this->userRepository = $userRepository; |
|
| 43 | $this->findAuthorIdByCommentIdQuery = $findAuthorIdByCommentIdQuery; |
|
| 44 | } |
|
| 45 | ||
| 46 | public function getCommentAuthorsConnection(CommentId $commentId): Connection |
|
| 47 | { |
|
| 48 | try { |
|
| 49 | $author = $this->userRepository->findOneById( |
|
| 50 | $this->findAuthorIdByCommentIdQuery->execute($commentId) |
|
| 51 | ); |
|
| 52 | } catch (EmptyQueryResultException $e) { |
|
| 53 | return ConnectionBuilder::connectionFromArray([]); |
|
| 54 | } |
|
| 55 | ||
| 56 | return ConnectionBuilder::connectionFromArray( |
|
| 57 | [ |
|
| 58 | AbstractUserViewModel::constructFromEntity($author), |
|
| 59 | ] |
|
| 60 | ); |
|
| 61 | } |
|
| 62 | ||
| 63 | public function countEdges(Connection $connection): int |
|
| 64 | { |
|
| 65 | return count($connection->edges); |
|
| 66 | } |
|
| 67 | } |
|
| 68 | ||
| @@ 26-67 (lines=42) @@ | ||
| 23 | use Overblog\GraphQLBundle\Relay\Connection\Output\ConnectionBuilder; |
|
| 24 | use function count; |
|
| 25 | ||
| 26 | final class PostAuthorsResolver |
|
| 27 | { |
|
| 28 | /** |
|
| 29 | * @var UserRepositoryInterface |
|
| 30 | */ |
|
| 31 | private $userRepository; |
|
| 32 | ||
| 33 | /** |
|
| 34 | * @var FindAuthorIdByPostIdQueryInterface |
|
| 35 | */ |
|
| 36 | private $findAuthorIdByPostIdQuery; |
|
| 37 | ||
| 38 | public function __construct( |
|
| 39 | UserRepositoryInterface $userRepository, |
|
| 40 | FindAuthorIdByPostIdQueryInterface $findAuthorIdByPostIdQuery |
|
| 41 | ) { |
|
| 42 | $this->userRepository = $userRepository; |
|
| 43 | $this->findAuthorIdByPostIdQuery = $findAuthorIdByPostIdQuery; |
|
| 44 | } |
|
| 45 | ||
| 46 | public function getPostAuthorsConnection(PostId $postId): Connection |
|
| 47 | { |
|
| 48 | try { |
|
| 49 | $author = $this->userRepository->findOneById( |
|
| 50 | $this->findAuthorIdByPostIdQuery->execute($postId) |
|
| 51 | ); |
|
| 52 | } catch (EmptyQueryResultException $e) { |
|
| 53 | return ConnectionBuilder::connectionFromArray([]); |
|
| 54 | } |
|
| 55 | ||
| 56 | return ConnectionBuilder::connectionFromArray( |
|
| 57 | [ |
|
| 58 | AbstractUserViewModel::constructFromEntity($author), |
|
| 59 | ] |
|
| 60 | ); |
|
| 61 | } |
|
| 62 | ||
| 63 | public function countEdges(Connection $connection): int |
|
| 64 | { |
|
| 65 | return count($connection->edges); |
|
| 66 | } |
|
| 67 | } |
|
| 68 | ||