-
Notifications
You must be signed in to change notification settings - Fork 326
Add support for two graphiql headers configurations #484
Conversation
if (headers) { | ||
var newHeaders = Object.assign({}, JSON.parse(props.headers), headers) | ||
props.headers = JSON.stringify(newHeaders, undefined, 2) | ||
} | ||
|
There was a problem hiding this comment.
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"
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.)
Kudos, SonarCloud Quality Gate passed! |
@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 newgraphiql.props.variables.headers
property. Although the existinggraphiql.headers
property is more Spring friendly since it allows you to configure it as nested properties, whereas thegraphiql.props.variables.headers
property requires a String JSON. That's why I went with this combined approach.fix #441