Created
September 5, 2018 06:33
-
-
Save jhlosin/91275311cd485da266b18be581e73bd0 to your computer and use it in GitHub Desktop.
graphql mutation query with variables
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 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