f / graphql.js

A Simple and Isomorphic GraphQL Client for JavaScript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

headers not working?

alxx opened this issue · comments

The header option seems to be used in a weird way. Here's how I build my graphql object:

var graph = graphql("http://localhost:3000/", {
    headers: {
        'Authorization': 'abcdef'
    }
});

And here's the HTTP request that it produces:

OPTIONS / HTTP/1.1
Host: localhost:3000
Connection: keep-alive
Access-Control-Request-Method: POST
Origin: null
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36
Access-Control-Request-Headers: authorization
Accept: /
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9,ro;q=0.8,sv;q=0.7,zh-TW;q=0.6,zh;q=0.5

As you can see, the request is changed from POST to OPTIONS, with a number of consequences. Rather than being a header in its own right, my header appears inside the 'Access-Control-Request-Headers' header, and its value is lost. No POST request is ever being made.

Headers appeared correctly in the actual POST request. I'd forgotten about the preflight. Sorry I keep raising issues and closing them :)

@alxx, I have the same issue and I created this issue, #46 , without realizing that this was already created earlier and had been resolved. Can you please let me know how you were able to overcome this issue ? Any help will be well appreciated.

With Regards
Gagan