Skip to content

Commit 0eeb7cf

Browse files
authored
Add custom style reference to Voyager GraphQL explorer
The commit adds a `stylePath` attribute to Voyager GraphQL explorer configuration. This enables the user to define a custom CSS file in the `voyager` section of `application.yaml`
1 parent cc742ef commit 0eeb7cf

File tree

9 files changed

+34
-1
lines changed

9 files changed

+34
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ graphql:
3131
hideDocs: false
3232
hideSettings: false
3333
cdn: unpkg
34+
stylePath: /style.css
3435
```
3536
3637
### Dependency

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public Mono<Rendering> voyager() {
2828
.modelAttribute("displayOptions", properties.getDisplayOptions())
2929
.modelAttribute("hideDocs", properties.isHideDocs())
3030
.modelAttribute("hideSettings", properties.isHideSettings())
31+
.modelAttribute("stylePath", properties.getStylePath())
3132
.build()
3233
);
3334
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ public String voyager(Model model) {
2525
.addAttribute("serverPath", serverPath)
2626
.addAttribute("displayOptions", properties.getDisplayOptions())
2727
.addAttribute("hideDocs", properties.isHideDocs())
28-
.addAttribute("hideSettings", properties.isHideSettings());
28+
.addAttribute("hideSettings", properties.isHideSettings())
29+
.addAttribute("stylePath", properties.getStylePath());
2930
return "voyager";
3031
}
3132

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public class VoyagerProperties {
3030

3131
private Cdn cdn = Cdn.JSDELIVR;
3232

33+
private String stylePath;
34+
3335
public boolean isEnabled() {
3436
return enabled;
3537
}
@@ -78,6 +80,14 @@ public void setCdn(Cdn cdn) {
7880
this.cdn = cdn;
7981
}
8082

83+
public String getStylePath() {
84+
return stylePath;
85+
}
86+
87+
public void setStylePath(String stylePath) {
88+
this.stylePath = stylePath;
89+
}
90+
8191
private static class DisplayOptions {
8292

8393
/**

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
th:href="|${cdnHost}/graphql-voyager/dist/voyager.css|"
1010
/>
1111
<script th:src="|${cdnHost}/graphql-voyager/dist/voyager.min.js|"></script>
12+
13+
<link th:if="${stylePath}" rel="stylesheet" th:href="|${stylePath}|"/>
1214
</head>
1315
<body>
1416
<div id="voyager">Loading...</div>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ spring:
1515
x-test: test
1616
plugins: EXPLORER
1717
stylePath: /style.css
18+
voyager:
19+
style-path: /style.css
1820
playground:
1921
settings:
2022
editor:
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
/*GraphiQL*/
12
.graphiql-logo-link {
23
--color-neutral: 24, 28%, 32%;
4+
}
5+
6+
/*Voyager*/
7+
.doc-navigation > .header {
8+
font-weight: bold;
9+
color: #600;
310
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ spring:
99
x-test: test
1010
plugins: EXPLORER
1111
stylePath: /style.css
12+
voyager:
13+
style-path: /style.css
1214
playground:
1315
settings:
1416
editor:
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
/*GraphiQL*/
12
.graphiql-logo-link {
23
--color-neutral: 24, 28%, 32%;
4+
}
5+
6+
/*Voyager*/
7+
.doc-navigation > .header {
8+
font-weight: bold;
9+
color: #600;
310
}

0 commit comments

Comments
 (0)