graphql-browser-client/js/continent.js

19 lines
No EOL
882 B
JavaScript

const continentCode = new URLSearchParams(window.location.search).get("code");
const countryList = document.getElementById("country-list");
fetch("https://countries.trevorblades.com/", {
"method": "POST",
"body": JSON.stringify(
{
query: "", // Fill in Query here
"operationName": "continent",
"variables": { "code": continentCode }
}), headers: { "Content-Type": "application/json" }
}).then(response => response.json()).then(({ data }) => {
document.getElementById("continent-heading").innerText = data.continent.name;
const countries = data.continent.countries;
for (const country of countries) {
const newListItem = document.createElement("li");
newListItem.innerHTML = `<a href="/country.html?code=${country.code}"> ${country.name} </a>`;
countryList.append(newListItem);
}
});