Skip to content

Commit 9264c86

Browse files
authored
Add support for custom HTTP headers in Voyager configuration
1 parent a8ff1b2 commit 9264c86

File tree

6 files changed

+23
-2
lines changed

6 files changed

+23
-2
lines changed

graphql-voyager-spring-boot-starter/src/main/java/ru/sadv1r/spring/graphql/editor/voyager/configuration/VoyagerProperties.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import org.springframework.boot.context.properties.ConfigurationProperties;
44
import org.springframework.boot.context.properties.NestedConfigurationProperty;
55

6+
import java.util.Map;
7+
68
/**
79
* Configuration properties for the Voyager GraphQL editor.
810
*
@@ -28,6 +30,8 @@ public class VoyagerProperties {
2830
*/
2931
private boolean hideSettings = false;
3032

33+
private Map<String, String> headers = Map.of();
34+
3135
private Cdn cdn = Cdn.JSDELIVR;
3236

3337
private String stylePath;
@@ -88,6 +92,14 @@ public void setStylePath(String stylePath) {
8892
this.stylePath = stylePath;
8993
}
9094

95+
public Map<String, String> getHeaders() {
96+
return headers;
97+
}
98+
99+
public void setHeaders(Map<String, String> headers) {
100+
this.headers = headers;
101+
}
102+
91103
private static class DisplayOptions {
92104

93105
/**

graphql-voyager-spring-boot-starter/src/main/java/ru/sadv1r/spring/graphql/editor/voyager/configuration/VoyagerWebFluxAutoConfiguration.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public RouterFunction<RenderingResponse> reactiveVoyagerRouterFunction(VoyagerPr
3232
.modelAttribute("displayOptions", properties.getDisplayOptions())
3333
.modelAttribute("hideDocs", properties.isHideDocs())
3434
.modelAttribute("hideSettings", properties.isHideSettings())
35+
.modelAttribute("headers", properties.getHeaders())
3536
.modelAttribute("stylePath", properties.getStylePath())
3637
.build();
3738

graphql-voyager-spring-boot-starter/src/main/java/ru/sadv1r/spring/graphql/editor/voyager/configuration/VoyagerWebMvcAutoConfiguration.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public RouterFunction<ServerResponse> voyagerRouterFunction(VoyagerProperties pr
2929
.modelAttribute("displayOptions", properties.getDisplayOptions())
3030
.modelAttribute("hideDocs", properties.isHideDocs())
3131
.modelAttribute("hideSettings", properties.isHideSettings())
32+
.modelAttribute("headers", properties.getHeaders())
3233
.modelAttribute("stylePath", properties.getStylePath())
3334
.build();
3435

graphql-voyager-spring-boot-starter/src/main/resources/templates/voyager.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,11 @@
3131
{
3232
method: 'post',
3333
headers: {
34-
Accept: 'application/json',
35-
'Content-Type': 'application/json',
34+
...{
35+
Accept: 'application/json',
36+
'Content-Type': 'application/json',
37+
},
38+
...[[${headers}]],
3639
},
3740
body: JSON.stringify({ query }),
3841
credentials: 'omit',

samples/web-sample/src/main/resources/application.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,6 @@ spring:
1616
plugins: EXPLORER
1717
stylePath: /style.css
1818
voyager:
19+
headers:
20+
x-test: test
1921
style-path: /style.css

samples/webflux-sample/src/main/resources/application.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ spring:
1010
plugins: EXPLORER
1111
stylePath: /style.css
1212
voyager:
13+
headers:
14+
x-test: test
1315
style-path: /style.css

0 commit comments

Comments
 (0)