Skip to content

Commit f668300

Browse files
committed
Fixed minor bug in blog example (#114)
1 parent 141afc1 commit f668300

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

examples/01-blog/Blog/Type/CommentType.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ public function __construct()
3636
];
3737
},
3838
'resolveField' => function($value, $args, $context, ResolveInfo $info) {
39-
if (method_exists($this, $info->fieldName)) {
40-
return $this->{$info->fieldName}($value, $args, $context, $info);
39+
$method = 'resolve' . ucfirst($info->fieldName);
40+
if (method_exists($this, $method)) {
41+
return $this->{$method}($value, $args, $context, $info);
4142
} else {
4243
return $value->{$info->fieldName};
4344
}
@@ -46,29 +47,29 @@ public function __construct()
4647
parent::__construct($config);
4748
}
4849

49-
public function author(Comment $comment)
50+
public function resolveAuthor(Comment $comment)
5051
{
5152
if ($comment->isAnonymous) {
5253
return null;
5354
}
5455
return DataSource::findUser($comment->authorId);
5556
}
5657

57-
public function parent(Comment $comment)
58+
public function resolveParent(Comment $comment)
5859
{
5960
if ($comment->parentId) {
6061
return DataSource::findComment($comment->parentId);
6162
}
6263
return null;
6364
}
6465

65-
public function replies(Comment $comment, $args)
66+
public function resolveReplies(Comment $comment, $args)
6667
{
6768
$args += ['after' => null];
6869
return DataSource::findReplies($comment->id, $args['limit'], $args['after']);
6970
}
7071

71-
public function totalReplyCount(Comment $comment)
72+
public function resolveTotalReplyCount(Comment $comment)
7273
{
7374
return DataSource::countReplies($comment->id);
7475
}

examples/01-blog/Blog/Type/StoryType.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,9 @@ public function __construct()
7676
Types::node()
7777
],
7878
'resolveField' => function($value, $args, $context, ResolveInfo $info) {
79-
if (method_exists($this, $info->fieldName)) {
80-
return $this->{$info->fieldName}($value, $args, $context, $info);
79+
$method = 'resolve' . ucfirst($info->fieldName);
80+
if (method_exists($this, $method)) {
81+
return $this->{$method}($value, $args, $context, $info);
8182
} else {
8283
return $value->{$info->fieldName};
8384
}
@@ -86,12 +87,12 @@ public function __construct()
8687
parent::__construct($config);
8788
}
8889

89-
public function author(Story $story)
90+
public function resolveAuthor(Story $story)
9091
{
9192
return DataSource::findUser($story->authorId);
9293
}
9394

94-
public function affordances(Story $story, $args, AppContext $context)
95+
public function resolveAffordances(Story $story, $args, AppContext $context)
9596
{
9697
$isViewer = $context->viewer === DataSource::findUser($story->authorId);
9798
$isLiked = DataSource::isLikedBy($story->id, $context->viewer->id);
@@ -108,17 +109,17 @@ public function affordances(Story $story, $args, AppContext $context)
108109
return $affordances;
109110
}
110111

111-
public function hasViewerLiked(Story $story, $args, AppContext $context)
112+
public function resolveHasViewerLiked(Story $story, $args, AppContext $context)
112113
{
113114
return DataSource::isLikedBy($story->id, $context->viewer->id);
114115
}
115116

116-
public function totalCommentCount(Story $story)
117+
public function resolveTotalCommentCount(Story $story)
117118
{
118119
return DataSource::countComments($story->id);
119120
}
120121

121-
public function comments(Story $story, $args)
122+
public function resolveComments(Story $story, $args)
122123
{
123124
$args += ['after' => null];
124125
return DataSource::findComments($story->id, $args['limit'], $args['after']);

examples/01-blog/Blog/Type/UserType.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ public function __construct()
4545
Types::node()
4646
],
4747
'resolveField' => function($value, $args, $context, ResolveInfo $info) {
48-
if (method_exists($this, $info->fieldName)) {
49-
return $this->{$info->fieldName}($value, $args, $context, $info);
48+
$method = 'resolve' . ucfirst($info->fieldName);
49+
if (method_exists($this, $method)) {
50+
return $this->{$method}($value, $args, $context, $info);
5051
} else {
5152
return $value->{$info->fieldName};
5253
}
@@ -55,12 +56,12 @@ public function __construct()
5556
parent::__construct($config);
5657
}
5758

58-
public function photo(User $user, $args)
59+
public function resolvePhoto(User $user, $args)
5960
{
6061
return DataSource::getUserPhoto($user->id, $args['size']);
6162
}
6263

63-
public function lastStoryPosted(User $user)
64+
public function resolveLastStoryPosted(User $user)
6465
{
6566
return DataSource::findLastStoryFor($user->id);
6667
}

0 commit comments

Comments
 (0)