Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot read property 'data' of undefined #73

Open
sarmadali20 opened this issue Jun 17, 2022 · 1 comment
Open

TypeError: Cannot read property 'data' of undefined #73

sarmadali20 opened this issue Jun 17, 2022 · 1 comment

Comments

@sarmadali20
Copy link

UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'data' of undefined
at RediQLCache.query (/rediqless/src/RediQL.js:82:29)

@IMingGarson
Copy link

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);
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants