From f668300cd87c471a026fd0026c9b9e65e7765554 Mon Sep 17 00:00:00 2001 From: Vladimir Razuvaev Date: Tue, 27 Jun 2017 20:04:12 +0700 Subject: [PATCH] Fixed minor bug in blog example (#114) --- examples/01-blog/Blog/Type/CommentType.php | 13 +++++++------ examples/01-blog/Blog/Type/StoryType.php | 15 ++++++++------- examples/01-blog/Blog/Type/UserType.php | 9 +++++---- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/examples/01-blog/Blog/Type/CommentType.php b/examples/01-blog/Blog/Type/CommentType.php index b89aa54..cbcad4d 100644 --- a/examples/01-blog/Blog/Type/CommentType.php +++ b/examples/01-blog/Blog/Type/CommentType.php @@ -36,8 +36,9 @@ class CommentType extends ObjectType ]; }, 'resolveField' => function($value, $args, $context, ResolveInfo $info) { - if (method_exists($this, $info->fieldName)) { - return $this->{$info->fieldName}($value, $args, $context, $info); + $method = 'resolve' . ucfirst($info->fieldName); + if (method_exists($this, $method)) { + return $this->{$method}($value, $args, $context, $info); } else { return $value->{$info->fieldName}; } @@ -46,7 +47,7 @@ class CommentType extends ObjectType parent::__construct($config); } - public function author(Comment $comment) + public function resolveAuthor(Comment $comment) { if ($comment->isAnonymous) { return null; @@ -54,7 +55,7 @@ class CommentType extends ObjectType return DataSource::findUser($comment->authorId); } - public function parent(Comment $comment) + public function resolveParent(Comment $comment) { if ($comment->parentId) { return DataSource::findComment($comment->parentId); @@ -62,13 +63,13 @@ class CommentType extends ObjectType return null; } - public function replies(Comment $comment, $args) + public function resolveReplies(Comment $comment, $args) { $args += ['after' => null]; return DataSource::findReplies($comment->id, $args['limit'], $args['after']); } - public function totalReplyCount(Comment $comment) + public function resolveTotalReplyCount(Comment $comment) { return DataSource::countReplies($comment->id); } diff --git a/examples/01-blog/Blog/Type/StoryType.php b/examples/01-blog/Blog/Type/StoryType.php index 38cf73f..32cea4e 100644 --- a/examples/01-blog/Blog/Type/StoryType.php +++ b/examples/01-blog/Blog/Type/StoryType.php @@ -76,8 +76,9 @@ class StoryType extends ObjectType Types::node() ], 'resolveField' => function($value, $args, $context, ResolveInfo $info) { - if (method_exists($this, $info->fieldName)) { - return $this->{$info->fieldName}($value, $args, $context, $info); + $method = 'resolve' . ucfirst($info->fieldName); + if (method_exists($this, $method)) { + return $this->{$method}($value, $args, $context, $info); } else { return $value->{$info->fieldName}; } @@ -86,12 +87,12 @@ class StoryType extends ObjectType parent::__construct($config); } - public function author(Story $story) + public function resolveAuthor(Story $story) { return DataSource::findUser($story->authorId); } - public function affordances(Story $story, $args, AppContext $context) + public function resolveAffordances(Story $story, $args, AppContext $context) { $isViewer = $context->viewer === DataSource::findUser($story->authorId); $isLiked = DataSource::isLikedBy($story->id, $context->viewer->id); @@ -108,17 +109,17 @@ class StoryType extends ObjectType return $affordances; } - public function hasViewerLiked(Story $story, $args, AppContext $context) + public function resolveHasViewerLiked(Story $story, $args, AppContext $context) { return DataSource::isLikedBy($story->id, $context->viewer->id); } - public function totalCommentCount(Story $story) + public function resolveTotalCommentCount(Story $story) { return DataSource::countComments($story->id); } - public function comments(Story $story, $args) + public function resolveComments(Story $story, $args) { $args += ['after' => null]; return DataSource::findComments($story->id, $args['limit'], $args['after']); diff --git a/examples/01-blog/Blog/Type/UserType.php b/examples/01-blog/Blog/Type/UserType.php index 347da46..9960b62 100644 --- a/examples/01-blog/Blog/Type/UserType.php +++ b/examples/01-blog/Blog/Type/UserType.php @@ -45,8 +45,9 @@ class UserType extends ObjectType Types::node() ], 'resolveField' => function($value, $args, $context, ResolveInfo $info) { - if (method_exists($this, $info->fieldName)) { - return $this->{$info->fieldName}($value, $args, $context, $info); + $method = 'resolve' . ucfirst($info->fieldName); + if (method_exists($this, $method)) { + return $this->{$method}($value, $args, $context, $info); } else { return $value->{$info->fieldName}; } @@ -55,12 +56,12 @@ class UserType extends ObjectType parent::__construct($config); } - public function photo(User $user, $args) + public function resolvePhoto(User $user, $args) { return DataSource::getUserPhoto($user->id, $args['size']); } - public function lastStoryPosted(User $user) + public function resolveLastStoryPosted(User $user) { return DataSource::findLastStoryFor($user->id); }