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

Commit c3e572c

Browse files
committed
Add accept and content-type headers silently
1 parent 88ed986 commit c3e572c

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

graphiql-spring-boot-autoconfigure/src/main/java/graphql/kickstart/graphiql/boot/GraphiQLController.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,6 @@ private void loadProps() throws IOException {
6161
private void loadHeaders() {
6262
PropertyGroupReader propertyReader = new PropertyGroupReader(environment, "graphiql.headers.");
6363
headerProperties = propertyReader.load();
64-
addIfAbsent(headerProperties, "Accept");
65-
addIfAbsent(headerProperties, "Content-Type");
66-
}
67-
68-
private void addIfAbsent(Properties headerProperties, String header) {
69-
if (!headerProperties.containsKey(header)) {
70-
headerProperties.setProperty(header, MediaType.APPLICATION_JSON_VALUE);
71-
}
7264
}
7365

7466
public byte[] graphiql(String contextPath, @PathVariable Map<String, String> params, Object csrf) {

graphiql-spring-boot-autoconfigure/src/main/resources/graphiql.html

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,22 @@
101101

102102
var headers = ${headers}
103103

104+
function addRequiredHeadersIfAbsent() {
105+
if (!headers['Accept']) {
106+
headers['Accept'] = 'application/json'
107+
}
108+
if (!headers['Content-Type']) {
109+
headers['Content-Type'] = 'application/json'
110+
}
111+
}
112+
104113
function onEditHeaders(newHeaders) {
105114
try {
106115
headers = JSON.parse(newHeaders)
107116
} catch(e) {
108117
headers = {}
109118
}
119+
addRequiredHeadersIfAbsent()
110120
}
111121

112122
// Defines a GraphQL fetcher using the fetch API. You're not required to
@@ -162,7 +172,7 @@
162172
props.onEditVariables = onEditVariables
163173
props.onEditOperationName = onEditOperationName
164174
props.onEditHeaders = onEditHeaders
165-
props.headers = props.headers || {}
175+
props.headers = props.headers || '{}'
166176
if (headers) {
167177
var newHeaders = Object.assign({}, JSON.parse(props.headers), headers)
168178
props.headers = JSON.stringify(newHeaders, undefined, 2)

graphql-kickstart-spring-support/src/main/java/graphql/kickstart/spring/AbstractGraphQLController.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ public Object graphqlPOST(
7575
throw new ResponseStatusException(HttpStatus.UNPROCESSABLE_ENTITY, "Could not process GraphQL request");
7676
}
7777

78-
@GetMapping(value = "${graphql.url:graphql}",
79-
produces = MediaType.APPLICATION_JSON_VALUE)
78+
@GetMapping(value = "${graphql.url:graphql}", produces = MediaType.APPLICATION_JSON_VALUE)
8079
public Object graphqlGET(
8180
@Nullable @RequestParam("query") String query,
8281
@Nullable @RequestParam(value = "operationName", required = false) String operationName,

0 commit comments

Comments
 (0)