Open sarmadali20 opened 2 years ago
In this module, it requires you to add graphql query to POST body.
I used node-fetch
module and this is my setup:
app.get('/', async (req, res) => {
const query = {
// see here I explicitly declare a data field
data: {
"query": "{\n HarryPotter\n {\n title\n author\n ISBN\n }\n }",
"variables": null
}
};
const response = await fetch(`http://localhost:4000/rediql`, {
method: 'post',
body: JSON.stringify(query),
headers: {'Content-Type': 'application/json'}
});
const data = await response.json();
res.send(data);
});
You can also try to send such query to normal endpoint /graphql
, but you need to modify the query a little bit.
app.get('/', async (req, res) => {
const query = {
// see here I omit the data field
"query": "{\n HarryPotter\n {\n title\n author\n ISBN\n }\n }",
"variables": null
};
const response = await fetch(`http://localhost:4000/graphql`, {
method: 'post',
body: JSON.stringify(query),
headers: {'Content-Type': 'application/json'}
});
const data = await response.json();
res.send(data);
});
UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'data' of undefined at RediQLCache.query (/rediqless/src/RediQL.js:82:29)