Skip to content

Instantly share code, notes, and snippets.

@annymosse
Forked from yusinto/updateCountry_fetch.js
Created March 29, 2020 02:26
Show Gist options
  • Save annymosse/cbee721edaace2107fc32fb04989318e to your computer and use it in GitHub Desktop.
Save annymosse/cbee721edaace2107fc32fb04989318e to your computer and use it in GitHub Desktop.
Graphql mutation with fetch
const updateCountryFetch = async (countryId, happinessFactor, population) => {
const query = JSON.stringify({
query: `mutation {
updateCountry(
id: "${countryId}"
happinessFactor: ${happinessFactor}
population: ${population}) { id }
}
`
});
const response = await fetch(graphCoolEndpoint, {
headers: {'content-type': 'application/json'},
method: 'POST',
body: query,
});
const responseJson = await response.json();
return responseJson.data;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment