Skip to content

Commit

Permalink
Add custom style support to GraphiQL interface
Browse files Browse the repository at this point in the history
The commit introduces a new property 'stylePath' to the GraphiQL configuration, allowing for custom style file paths to be specified
  • Loading branch information
sadv1r committed Mar 21, 2024
1 parent d217017 commit a36aa44
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public RouterFunction<ServerResponse> reactiveGraphiQlRouterFunction(GraphiqlPro
.modelAttribute("variables", properties.getVariables())
.modelAttribute("headers", properties.getHeaders())
.modelAttribute("plugins", properties.getPlugins())
.modelAttribute("stylePath", properties.getStylePath())
.build();
builder = builder.GET(properties.getPath(), graphiql);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public RouterFunction<ServerResponse> graphiQlRouterFunction(GraphiqlProperties
.modelAttribute("variables", properties.getVariables())
.modelAttribute("headers", properties.getHeaders())
.modelAttribute("plugins", properties.getPlugins())
.modelAttribute("stylePath", properties.getStylePath())
.build();
builder = builder.GET(properties.getPath(), graphiql);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public class GraphiqlProperties {

private Cdn cdn = Cdn.UNPKG;

private String stylePath;

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

public String getStylePath() {
return stylePath;
}

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

private static String readIfPath(String query) {
if (query == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
crossorigin th:src="|${cdnHost}/@graphiql/plugin-explorer/dist/index.umd.js|"></script>
<link th:if="${plugins.contains(T(ru.sadv1r.spring.graphql.editor.graphiql.configuration.GraphiqlProperties.Plugin).EXPLORER)}"
rel="stylesheet" th:href="|${cdnHost}/@graphiql/plugin-explorer/dist/style.css|"/>

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

0 comments on commit a36aa44

Please sign in to comment.