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
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion example/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,14 @@ altair:
graphiql:
enabled: true
cdn:
enabled: true
enabled: false
version: 0.17.5
headers:
Test: TestHeader
props:
variables:
headerEditorEnabled: true
headers: '{ "Authorization": "SomeValue" }'
voyager:
enabled: true
cdn:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,12 @@
props.onEditVariables = onEditVariables
props.onEditOperationName = onEditOperationName
props.onEditHeaders = onEditHeaders
props.headers = props.headers || {}
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.)

console.debug(props)
// Render <GraphiQL /> into the body.
ReactDOM.render(
React.createElement(GraphiQL, props),
Expand Down