json – GraphQL Return Only the Object and not Data/Query

I’m new to GraphQL and am having trouble parsing my GraphQL response into an array:

var url = "https://data.objkt.com/v2/graphql";
var XMLHttpRequest = require('xhr2');
var xhr = new XMLHttpRequest();
xhr.open("POST", url);
xhr.setRequestHeader("Content-Type", "application/json");

xhr.onreadystatechange = function () {

    if (xhr.readyState === 4) {
   
        console.log(xhr.status);
        console.log(xhr.responseText);

    }

};

const data = JSON.stringify({
  query: `{
    currency(distinct_on: fa_contract) {
    id
  }
  }`,
});

xhr.send(data);

The response I get back is:

{"data":{"currency":[{"id":65223}, {"id":2}, {"id":1}]}}

How can I get the response to only return the object (the ids inside the brackets) and not the “data” and “currency” parts so I can proceed to parse it into an array?

I tried using regex matches to extract the brackets but I know that’s not the proper/ideal way!

thank you

Read more here: Source link