42 lines
897 B
PHP
42 lines
897 B
PHP
|
<?php
|
||
|
|
||
|
use GraphQL\Type\Definition\Type;
|
||
|
use GraphQL\Type\Definition\ObjectType;
|
||
|
|
||
|
$blogPostFields = new ObjectType([
|
||
|
"name" => "Blog",
|
||
|
"fields" => [
|
||
|
"title" => Type::string(),
|
||
|
"content" => Type::string(),
|
||
|
"date" => Type::string(),
|
||
|
"id" => Type::string(),
|
||
|
"error" => Type::string(),
|
||
|
],
|
||
|
]);
|
||
|
|
||
|
function blogPost($id, $conn)
|
||
|
{
|
||
|
$id = $conn->real_escape_string($id);
|
||
|
$result = $conn->query("SELECT * FROM posts WHERE id=$id");
|
||
|
if ($result->num_rows > 0) {
|
||
|
$row = $result->fetch_assoc();
|
||
|
} else {
|
||
|
return [
|
||
|
"error" => "Post not found"
|
||
|
];
|
||
|
}
|
||
|
|
||
|
$title = $row["title"];
|
||
|
$content = $row["content"];
|
||
|
$date = $row["date"];
|
||
|
$id = $row["id"];
|
||
|
|
||
|
return [
|
||
|
"title" => $title,
|
||
|
"content" => $content,
|
||
|
"date" => $date,
|
||
|
"id" => $id,
|
||
|
"error" => ""
|
||
|
];
|
||
|
}
|