var dice = 3;
var sides = 6;
var query = `query RollDice($dice: Int!, $sides: Int) {
rollDice(numDice: $dice, numSides: $sides)
}`;
fetch('/graphql', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
body: JSON.stringify({
query,
variables: { dice, sides },
})
})
.then(r => r.json())
.then(data => console.log('data returned:', data));
Created
January 7, 2019 01:48
-
-
Save kurtisdunn/bc87df7f82de49893823ea6fae8c516a to your computer and use it in GitHub Desktop.
Simple client side GraphQL query with vars
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment