Skip to content

Commit

Permalink
Add custom style reference to Voyager GraphQL explorer
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
sadv1r authored Mar 21, 2024
1 parent cc742ef commit 0eeb7cf
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ graphql:
hideDocs: false
hideSettings: false
cdn: unpkg
stylePath: /style.css
```
### Dependency
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public Mono<Rendering> voyager() {
.modelAttribute("displayOptions", properties.getDisplayOptions())
.modelAttribute("hideDocs", properties.isHideDocs())
.modelAttribute("hideSettings", properties.isHideSettings())
.modelAttribute("stylePath", properties.getStylePath())
.build()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public String voyager(Model model) {
.addAttribute("serverPath", serverPath)
.addAttribute("displayOptions", properties.getDisplayOptions())
.addAttribute("hideDocs", properties.isHideDocs())
.addAttribute("hideSettings", properties.isHideSettings());
.addAttribute("hideSettings", properties.isHideSettings())
.addAttribute("stylePath", properties.getStylePath());
return "voyager";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public class VoyagerProperties {

private Cdn cdn = Cdn.JSDELIVR;

private String stylePath;

public boolean isEnabled() {
return enabled;
}
Expand Down Expand Up @@ -78,6 +80,14 @@ public void setCdn(Cdn cdn) {
this.cdn = cdn;
}

public String getStylePath() {
return stylePath;
}

public void setStylePath(String stylePath) {
this.stylePath = stylePath;
}

private static class DisplayOptions {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
th:href="|${cdnHost}/graphql-voyager/dist/voyager.css|"
/>
<script th:src="|${cdnHost}/graphql-voyager/dist/voyager.min.js|"></script>

<link th:if="${stylePath}" rel="stylesheet" th:href="|${stylePath}|"/>
</head>
<body>
<div id="voyager">Loading...</div>
Expand Down
2 changes: 2 additions & 0 deletions samples/web-sample/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ spring:
x-test: test
plugins: EXPLORER
stylePath: /style.css
voyager:
style-path: /style.css
playground:
settings:
editor:
Expand Down
7 changes: 7 additions & 0 deletions samples/web-sample/src/main/resources/static/style.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/*GraphiQL*/
.graphiql-logo-link {
--color-neutral: 24, 28%, 32%;
}

/*Voyager*/
.doc-navigation > .header {
font-weight: bold;
color: #600;
}
2 changes: 2 additions & 0 deletions samples/webflux-sample/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ spring:
x-test: test
plugins: EXPLORER
stylePath: /style.css
voyager:
style-path: /style.css
playground:
settings:
editor:
Expand Down
7 changes: 7 additions & 0 deletions samples/webflux-sample/src/main/resources/static/style.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/*GraphiQL*/
.graphiql-logo-link {
--color-neutral: 24, 28%, 32%;
}

/*Voyager*/
.doc-navigation > .header {
font-weight: bold;
color: #600;
}

0 comments on commit 0eeb7cf

Please sign in to comment.