load blog posts from graphql
This commit is contained in:
parent
bd9be3b0b5
commit
7e371dac06
1 changed files with 9 additions and 1 deletions
|
@ -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";
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue