javascriptgraphql

No query string was present- GraphQL Javascript


I'm doing following query in Javascript and GraphQL:

const query2 = `
    query{
        ethereum(network: bsc) {
          address(address: {is: "ETHEREUMADDRESSGOSHERE"}) {
            balances {
              currency {
                symbol
                address
              }
              value
            }
          }
        }
      }
      `;


const url = "https://graphql.bitquery.io/";
const opts = {
    method: "POST",
    headers: {
        "Content-Type": "application/json",
      "X-API-KEY": "APIKEYGOESHERE"
    },
    body: JSON.stringify({
        query2
    })
};


fetch(url, opts)
    .then(res => res.json())
    .then(console.log)
    .catch(console.error);

When I run this, I get an error

No query string was present

in my console.

I have this query from this site: https://graphql.bitquery.io/ide

and I'm using the "All token of a BSC Address" query, in case you want to replicate it.

What is going wrong here?

I ran a similar query before and it worked just fine.

I was also googling this error, prior to posting that message and all i found in regards to it was the same error in python, but in my case I'm using Javascript so I can't really use those answers.


Solution

  • You can't rename the query variable query2. Replace both instances of "query2" with "query" and it will work.