diff --git a/examples/01-blog/Blog/Data/DataSource.php b/examples/01-blog/Blog/Data/DataSource.php index 39abe78..fdb0e24 100644 --- a/examples/01-blog/Blog/Data/DataSource.php +++ b/examples/01-blog/Blog/Data/DataSource.php @@ -104,6 +104,11 @@ class DataSource 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) { $storiesFound = array_filter($this->stories, function(Story $story) use ($authorId) { diff --git a/examples/01-blog/Blog/Type/CommentType.php b/examples/01-blog/Blog/Type/CommentType.php index f4c4420..a432fdc 100644 --- a/examples/01-blog/Blog/Type/CommentType.php +++ b/examples/01-blog/Blog/Type/CommentType.php @@ -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) { - 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)