graphql / graphql-playground

🎮 GraphQL IDE for better development workflows (GraphQL Subscriptions, interactive docs & collaboration)
MIT License
8.75k stars 731 forks source link

Pass HTTP headers on websocket subscription (AppSync, Subscriptions) #853

Open 0xdevalias opened 5 years ago

0xdevalias commented 5 years ago

This issue pertains to the following package(s):

What OS and OS version are you experiencing the issue(s) on?

macOS Mojave 10.14

What version of graphql-playground(-electron/-middleware) are you experiencing the issue(s) on?

1.7.0

What is the expected behavior?

When I have an AWS AppSync GraphQL API protected by an API_KEY (set in the x-api-key http header), the subscription should connect to the websocket properly.

What is the actual behavior?

An error is received, being unable to connect:

{
  "error": "Could not connect to websocket endpoint wss://REDACTED.appsync-api.ap-southeast-2.amazonaws.com/graphql. Please check if the endpoint url is correct."
}

I believe this is occurring because the API key isn't sent, and thus it receives a 401 unauthorized response.

What steps may we take to reproduce the behavior?

Create an AWS AppSync GraphQL API protected with an API_KEY and try and subscribe to it.

ianidi commented 4 years ago

I can confirm I'm having the same problem

Gnork commented 4 years ago

I can also confirm this problem. I would like the headers in the HTTP Headers UI section to be sent via the subscription websocket connection. I need this for Authorization using a Bearer token.

Edit: for example the GraphQL client lib for Python can do this:

sample_transport = WebsocketsTransport(
    url='wss://SERVER_URL:SERVER_PORT/graphql',
    headers={'Authorization': 'token'}
)

Source

c10b10 commented 3 years ago

I can confirm having this problem as well.