GraphQL mutations are simply POST HTTP requests for the GraphQL endpoint. You can easily send it using any HTTP library such as request or axios .
For example, this mutation,
mutation ($id: Int!) { upvotePost(postId: $id) { id } }
and query variable,
$id = 1
is an HTTP POST request with a JSON payload
{ "query": "mutation ($id: Int!) { upvotePost(postId: $id) { id } } ", "variables": { "id": 1 } }
Note that query is your GraphQL query as a string.
Using axios as an example, you can send this to your server using something like this,
axios({ method: 'post', url: '/graphql', // payload is the payload above data: payload, });
dashmug
source share