-
Notifications
You must be signed in to change notification settings - Fork 154
Expand file tree
/
Copy pathindex.html
More file actions
55 lines (48 loc) · 1.31 KB
/
index.html
File metadata and controls
55 lines (48 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Hygraph + Vanilla JS (Fetch API)</title>
</head>
<body>
<ul id="products"></ul>
<script>
fetch(
'https://api-eu-central-1.hygraph.com/v2/ck8sn5tnf01gc01z89dbc7s0o/master',
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
},
body: JSON.stringify({
query: `
query {
products {
id
name
price
}
}
`,
}),
}
)
.then((res) => {
if (!res.ok) return Promise.reject(response);
return res.json();
})
.then((res) => {
const { products } = res.data;
const productsList = document.querySelector('ul#products');
products.map((product) => {
const li = document.createElement('li');
li.textContent = product.name;
productsList.appendChild(li);
});
});
</script>
</body>
</html>