GraphQL with RESTful returning empty response GraphQL with RESTful returning empty response express express

GraphQL with RESTful returning empty response


Your fetchResponseByURL function get empty string.

I think the main problem is that you are using wrong function to get the your JSON string, please try to install request-promise and use it to get your JSON string.

https://github.com/request/request-promise#readme

something like

var rp = require('request-promise');function fetchResponseByURL(relativeURL) {  return rp('https://api.myjson.com/bins/8lwqk')    .then((html) => {      const data = JSON.parse(html)      return data.merchant    })    .catch((err) => console.error(err));  // .catch(error => { console.log('request failed', error); });}


In this case using data.merchant solved my problem. But the above suggested solution i.e., use of JSON.parse(...) might not be the best practice because if there are no object in JSON, then expected response might be as follows:

{  "data": {    "merchant": null  }}

Instead of fields to be null.

{  "data": {    "merchant": {      "id": null // even though merchant is null in JSON,                  // I am getting a merchant object in response from GraphQL    }  }}

I have updated my GitHub: https://github.com/vishrantgupta/graphql with working code.