Skip to content

Instantly share code, notes, and snippets.

@yusinto
Last active August 4, 2021 19:13
Show Gist options
  • Save yusinto/d8506184efb73b7214be9beaa4d150c1 to your computer and use it in GitHub Desktop.
Save yusinto/d8506184efb73b7214be9beaa4d150c1 to your computer and use it in GitHub Desktop.
Graphql mutation using graphql-request
const updateCountryGraphqlRequest = async (countryId, happinessFactor, population) => {
const query = `
mutation updateCountry ($countryId: ID!, $happinessFactor: Int!, $population: Int!) {
updateCountry(id: $countryId, happinessFactor: $happinessFactor, population: $population) { id }
}
`;
const variables = {
countryId,
happinessFactor,
population,
};
const data = await graphqlRequest.request(query, variables);
return data;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment