0

This is my code:

const result = await axios({
      url: "https://exampleurl.com",
      method: 'POST',
      headers: {
        Accept: 'application/json',
        'Content-Type': 'application/json',
      },
      data: {
        query: `query {
                  footer {
                    title
                }
              }`,
      },
    })

There are no variables required for this call.

So this gives me 400 which makes me think there is something wrong with my body payload? But I can't see anything wrong with it. Maybe I am blind.

I have also tried stringifying the data object like this:

JSON.stringify({
        query: `query {
                  footer {
                    title
                }
              }`,
      }),

But then I get this error:

"stack": "TypeError: Converting circular structure to JSON\n    -->
starting at object with constructor 'ClientRequest'\n    |     property
'socket' -> object with constructor 'Socket'\n    --- property
'_httpMessage' closes the circle\n    at JSON.stringify

I have checked out other similar posts but can't seem to fix this issue.

jingteng
  • 2,331
  • 4
  • 13
  • 16
  • Does this answer your question? [TypeError: Converting circular structure to JSON --> starting at object with constructor 'ClientRequest'](https://stackoverflow.com/questions/64735881/typeerror-converting-circular-structure-to-json-starting-at-object-with-con) – Matt U Sep 28 '21 at 17:50
  • The issue is not the client code but instead on the server side, check the duplicate post I shared. – Matt U Sep 28 '21 at 17:50
  • But that circular error I only get when I stringify my graphql query which I don't think I need to do based on other example posts. – jingteng Sep 28 '21 at 17:52
  • does this query work/was tested in the playground? – xadm Sep 28 '21 at 21:28
  • Yeah and it works in graphiql, I also tried it in postman to hit my local server and it also works – jingteng Sep 29 '21 at 07:56
  • exactly the same query? then compare axios network request (body+headers) with working one – xadm Sep 29 '21 at 09:48
  • yep I did and I made sure they were same too – jingteng Sep 29 '21 at 15:19
  • compare carefully ALL request details ... equal requests => both working requests – xadm Sep 29 '21 at 20:58
  • Just resolved the issue, it was not really related to my request at all. Will post the answer in a bit. – jingteng Sep 30 '21 at 12:44

1 Answers1

0

So it turns out, I was trying to log out result and because axios is such a big object, it was clashing with one of my custom logger. I logged result.data and I finally got 200 response.

jingteng
  • 2,331
  • 4
  • 13
  • 16