Skip to content
This repository was archived by the owner on Dec 19, 2023. It is now read-only.

Add support for two graphiql headers configurations #484

Merged
merged 9 commits into from
Dec 19, 2020

Conversation

oliemansm
Copy link
Member

@BlasiusSecundus this combines the two header configurations. Instead I could also apply breaking change and remove support for the old graphiql.headers configuration option, requiring people to use the new graphiql.props.variables.headers property. Although the existing graphiql.headers property is more Spring friendly since it allows you to configure it as nested properties, whereas the graphiql.props.variables.headers property requires a String JSON. That's why I went with this combined approach.

fix #441

@oliemansm oliemansm added this to the 8.1.0 milestone Nov 28, 2020
if (headers) {
var newHeaders = Object.assign({}, JSON.parse(props.headers), headers)
props.headers = JSON.stringify(newHeaders, undefined, 2)
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

calling onEditHeaders(props.headers) seems to be necessary here, otherwise the headers are not sent with the request (until the onEditHeaders event is triggered)

Also, two additonal headers are appearing on the "Request headers" tab: "Accept": "application/json" and "Content-Type": "application/json"

Copy link
Member Author

@oliemansm oliemansm Nov 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those two additional headers are added by the GraphiQLController atm because otherwise it would send the request as just plain text:

Accept: */*
Content-Type: text/plain;charset=UTF-8

According to GraphQL Specification it should use Content-Type application/json in that case.

I could add them "silently" though, so instead of adding them in the headers tab too, only add them if there absent.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the "silent" solution is better in this case, since these headers are/should be always the same. (And the user still has the option to customize them by adding them manually.)

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication

@oliemansm oliemansm merged commit 30b258a into master Dec 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Upgrade Graphiql to enable headers
2 participants