Fixed minor bug in blog example (#114)

This commit is contained in:
Vladimir Razuvaev 2017-06-27 20:04:12 +07:00
parent 141afc1cf7
commit f668300cd8
3 changed files with 20 additions and 17 deletions

View File

@ -36,8 +36,9 @@ class CommentType extends ObjectType
]; ];
}, },
'resolveField' => function($value, $args, $context, ResolveInfo $info) { 'resolveField' => function($value, $args, $context, ResolveInfo $info) {
if (method_exists($this, $info->fieldName)) { $method = 'resolve' . ucfirst($info->fieldName);
return $this->{$info->fieldName}($value, $args, $context, $info); if (method_exists($this, $method)) {
return $this->{$method}($value, $args, $context, $info);
} else { } else {
return $value->{$info->fieldName}; return $value->{$info->fieldName};
} }
@ -46,7 +47,7 @@ class CommentType extends ObjectType
parent::__construct($config); parent::__construct($config);
} }
public function author(Comment $comment) public function resolveAuthor(Comment $comment)
{ {
if ($comment->isAnonymous) { if ($comment->isAnonymous) {
return null; return null;
@ -54,7 +55,7 @@ class CommentType extends ObjectType
return DataSource::findUser($comment->authorId); return DataSource::findUser($comment->authorId);
} }
public function parent(Comment $comment) public function resolveParent(Comment $comment)
{ {
if ($comment->parentId) { if ($comment->parentId) {
return DataSource::findComment($comment->parentId); return DataSource::findComment($comment->parentId);
@ -62,13 +63,13 @@ class CommentType extends ObjectType
return null; return null;
} }
public function replies(Comment $comment, $args) public function resolveReplies(Comment $comment, $args)
{ {
$args += ['after' => null]; $args += ['after' => null];
return DataSource::findReplies($comment->id, $args['limit'], $args['after']); return DataSource::findReplies($comment->id, $args['limit'], $args['after']);
} }
public function totalReplyCount(Comment $comment) public function resolveTotalReplyCount(Comment $comment)
{ {
return DataSource::countReplies($comment->id); return DataSource::countReplies($comment->id);
} }

View File

@ -76,8 +76,9 @@ class StoryType extends ObjectType
Types::node() Types::node()
], ],
'resolveField' => function($value, $args, $context, ResolveInfo $info) { 'resolveField' => function($value, $args, $context, ResolveInfo $info) {
if (method_exists($this, $info->fieldName)) { $method = 'resolve' . ucfirst($info->fieldName);
return $this->{$info->fieldName}($value, $args, $context, $info); if (method_exists($this, $method)) {
return $this->{$method}($value, $args, $context, $info);
} else { } else {
return $value->{$info->fieldName}; return $value->{$info->fieldName};
} }
@ -86,12 +87,12 @@ class StoryType extends ObjectType
parent::__construct($config); parent::__construct($config);
} }
public function author(Story $story) public function resolveAuthor(Story $story)
{ {
return DataSource::findUser($story->authorId); 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); $isViewer = $context->viewer === DataSource::findUser($story->authorId);
$isLiked = DataSource::isLikedBy($story->id, $context->viewer->id); $isLiked = DataSource::isLikedBy($story->id, $context->viewer->id);
@ -108,17 +109,17 @@ class StoryType extends ObjectType
return $affordances; 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); return DataSource::isLikedBy($story->id, $context->viewer->id);
} }
public function totalCommentCount(Story $story) public function resolveTotalCommentCount(Story $story)
{ {
return DataSource::countComments($story->id); return DataSource::countComments($story->id);
} }
public function comments(Story $story, $args) public function resolveComments(Story $story, $args)
{ {
$args += ['after' => null]; $args += ['after' => null];
return DataSource::findComments($story->id, $args['limit'], $args['after']); return DataSource::findComments($story->id, $args['limit'], $args['after']);

View File

@ -45,8 +45,9 @@ class UserType extends ObjectType
Types::node() Types::node()
], ],
'resolveField' => function($value, $args, $context, ResolveInfo $info) { 'resolveField' => function($value, $args, $context, ResolveInfo $info) {
if (method_exists($this, $info->fieldName)) { $method = 'resolve' . ucfirst($info->fieldName);
return $this->{$info->fieldName}($value, $args, $context, $info); if (method_exists($this, $method)) {
return $this->{$method}($value, $args, $context, $info);
} else { } else {
return $value->{$info->fieldName}; return $value->{$info->fieldName};
} }
@ -55,12 +56,12 @@ class UserType extends ObjectType
parent::__construct($config); parent::__construct($config);
} }
public function photo(User $user, $args) public function resolvePhoto(User $user, $args)
{ {
return DataSource::getUserPhoto($user->id, $args['size']); return DataSource::getUserPhoto($user->id, $args['size']);
} }
public function lastStoryPosted(User $user) public function resolveLastStoryPosted(User $user)
{ {
return DataSource::findLastStoryFor($user->id); return DataSource::findLastStoryFor($user->id);
} }