Last active
October 3, 2024 22:20
-
-
Save yusinto/30bba51b6f903c1b67e0383f4a288269 to your computer and use it in GitHub Desktop.
Graphql mutation with fetch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
Here is working for me