load blog posts from graphql

This commit is contained in:
Jonas Leder 2022-03-08 11:14:23 +01:00
parent bd9be3b0b5
commit 7e371dac06
No known key found for this signature in database
GPG key ID: 8A53DD45A7D7B44B

View file

@ -26,7 +26,15 @@ async function loadPost() {
if(id == null) { if(id == null) {
content.innerHTML = "<h1>404 - Post not found</h1>"; content.innerHTML = "<h1>404 - Post not found</h1>";
} else { } else {
let post = await (await fetch("/API/getPost.php?id=" + id)).json(); var graphql = JSON.stringify({
query: 'query {blogPost(id: "' + id + '") {content title}}',
variables: {}
})
var requestOptions = {
method: 'POST',
body: graphql,
};
let post = (await (await fetch("http://localhost:1234/API/graphql.php", requestOptions)).json()).data.blogPost;
content.innerHTML = post["content"]; content.innerHTML = post["content"];
document.title = post["title"] + " - Jonas Leder"; document.title = post["title"] + " - Jonas Leder";