mirror of
https://github.com/retailcrm/graphql-php.git
synced 2024-11-24 22:06:04 +03:00
Fixed minor bug in blog example (#114)
This commit is contained in:
parent
141afc1cf7
commit
f668300cd8
@ -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);
|
||||
}
|
||||
|
@ -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']);
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user