public function __construct()
{
// Option #1: using composition over inheritance to define type, see ImageType for inheritance example
$this->definition = new ObjectType(['name' => 'Comment', 'fields' => function () {
return ['id' => Types::id(), 'author' => Types::user(), 'parent' => Types::comment(), 'isAnonymous' => Types::boolean(), 'replies' => ['type' => Types::listOf(Types::comment()), 'args' => ['after' => Types::int(), 'limit' => ['type' => Types::int(), 'defaultValue' => 5]]], 'totalReplyCount' => Types::int(), Types::htmlField('body')];
}, 'resolveField' => function ($value, $args, $context, ResolveInfo $info) {
if (method_exists($this, $info->fieldName)) {
return $this->{$info->fieldName}($value, $args, $context, $info);
} else {
return $value->{$info->fieldName};
}
}]);
}