Several other updates to blog example

This commit is contained in:
vladar 2016-10-23 05:30:31 +07:00
parent 85d2c2cef3
commit 5125741899
2 changed files with 14 additions and 1 deletions

View File

@ -104,6 +104,11 @@ class DataSource
return isset($this->stories[$id]) ? $this->stories[$id] : null; return isset($this->stories[$id]) ? $this->stories[$id] : null;
} }
public function findComment($id)
{
return isset($this->comments[$id]) ? $this->comments[$id] : null;
}
public function findLastStoryFor($authorId) public function findLastStoryFor($authorId)
{ {
$storiesFound = array_filter($this->stories, function(Story $story) use ($authorId) { $storiesFound = array_filter($this->stories, function(Story $story) use ($authorId) {

View File

@ -43,9 +43,17 @@ class CommentType extends BaseType
]); ]);
} }
public function author(Comment $comment, $args, AppContext $context)
{
return $context->dataSource->findUser($comment->authorId);
}
public function parent(Comment $comment, $args, AppContext $context) public function parent(Comment $comment, $args, AppContext $context)
{ {
return $context->dataSource->findReplies($comment->id, $args['limit'], $args['after']); if ($comment->parentId) {
return $context->dataSource->findComment($comment->parentId);
}
return null;
} }
public function replies(Comment $comment, $args, AppContext $context) public function replies(Comment $comment, $args, AppContext $context)