32 lines
806 B
PHP
32 lines
806 B
PHP
|
<?php
|
||
|
|
||
|
use GraphQL\Type\Definition\Type;
|
||
|
use GraphQL\Type\Definition\ObjectType;
|
||
|
|
||
|
include "lib/getGravatar.php";
|
||
|
$commentField = new ObjectType([
|
||
|
"name" => "Comment",
|
||
|
"fields" => [
|
||
|
"name" => Type::string(),
|
||
|
"comment" => Type::string(),
|
||
|
"gravatarURL" => Type::string(),
|
||
|
"id" => Type::int()
|
||
|
],
|
||
|
]);
|
||
|
|
||
|
function comments($article, $conn) {
|
||
|
$response = [];
|
||
|
$result = $conn->query("SELECT * FROM comments WHERE article='$article'");
|
||
|
while ($row = $result->fetch_assoc()) {
|
||
|
$commentElement = [
|
||
|
"name" => $row["name"],
|
||
|
"comment" => $row["comment"],
|
||
|
"gravatarURL" => get_gravatar($row["email"]),
|
||
|
"id" => $row["id"]
|
||
|
];
|
||
|
|
||
|
array_push($response, $commentElement);
|
||
|
}
|
||
|
return $response;
|
||
|
|
||
|
}
|