I have a following query:
query MyQuery($today: Date) {
allMovies(
filter: {
info: { endDate: { gte: $today }, startDate: { lte: $today } }
}
) {
edges {
node {
info {
startDate
endDate
}
}
}
}
I'm using ReactJS with GatsbyJS, can anyone explain me how to insert variable into graphql? I don't really understand how to pass and create $today to this query. Or maybe it is somehow possible to insert today date in proper format.
All dates are YYYY-MM-DD
In mysql I could insert variable directly/ there was a function CURDATE() :(
You have to pass the variables as a separate object in your call to the API. A example from graphql.org:
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));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With