Skip to content

Instantly share code, notes, and snippets.

@jhlosin
Created September 5, 2018 06:33
Show Gist options
  • Save jhlosin/91275311cd485da266b18be581e73bd0 to your computer and use it in GitHub Desktop.
Save jhlosin/91275311cd485da266b18be581e73bd0 to your computer and use it in GitHub Desktop.
graphql mutation query with variables
const fetch = require('node-fetch')
async _updateMinerMutation (query, variables) {
const response = await fetch(process.env.GRAPHQL_ENDPOINT, {
headers: { 'Content-Type': 'application/json' },
method: 'POST',
body: JSON.stringify({query, variables}),
}).then(res => res.json()).then(res => console.log(res));
}
const query = `mutation ($id: ID!, $stat: String, $lastUpdated: DateTime, $lastGoodHashrate: DateTime) {
updateMiner(
where: {id: $id}
data: {
stat: $stat,
lastUpdated: $lastUpdated,
lastGoodHashrate: lastGoodHashrate
status: "online"
}
) { id }
}
`
const variables = {
id: miner.id,
stat,
lastUpdated: new Date()
lastGoodHashrate: new Date()
}
this._updateMinerMutation({query, variables})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment