From 773515909ba4b05e379af9a5472477f7930d96b0 Mon Sep 17 00:00:00 2001 From: sadv1r <5000487+sadv1r@users.noreply.github.com> Date: Fri, 22 Mar 2024 00:12:29 +0300 Subject: [PATCH] Add custom style support to GraphiQL interface The commit introduces a new property 'stylePath' to the GraphiQL configuration, allowing for custom style file paths to be specified --- .../GraphiQlWebFluxMvcAutoConfiguration.java | 1 + .../configuration/GraphiQlWebMvcAutoConfiguration.java | 1 + .../graphiql/configuration/GraphiqlProperties.java | 10 ++++++++++ .../src/main/resources/templates/graphiql.html | 2 ++ samples/web-sample/src/main/resources/application.yaml | 1 + samples/web-sample/src/main/resources/static/style.css | 3 +++ .../webflux-sample/src/main/resources/application.yaml | 1 + .../webflux-sample/src/main/resources/static/style.css | 3 +++ 8 files changed, 22 insertions(+) create mode 100644 samples/web-sample/src/main/resources/static/style.css create mode 100644 samples/webflux-sample/src/main/resources/static/style.css diff --git a/graphql-graphiql-spring-boot-starter/src/main/java/ru/sadv1r/spring/graphql/editor/graphiql/configuration/GraphiQlWebFluxMvcAutoConfiguration.java b/graphql-graphiql-spring-boot-starter/src/main/java/ru/sadv1r/spring/graphql/editor/graphiql/configuration/GraphiQlWebFluxMvcAutoConfiguration.java index e1bfd74..c5ac546 100644 --- a/graphql-graphiql-spring-boot-starter/src/main/java/ru/sadv1r/spring/graphql/editor/graphiql/configuration/GraphiQlWebFluxMvcAutoConfiguration.java +++ b/graphql-graphiql-spring-boot-starter/src/main/java/ru/sadv1r/spring/graphql/editor/graphiql/configuration/GraphiQlWebFluxMvcAutoConfiguration.java @@ -31,6 +31,7 @@ public RouterFunction 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); } diff --git a/graphql-graphiql-spring-boot-starter/src/main/java/ru/sadv1r/spring/graphql/editor/graphiql/configuration/GraphiQlWebMvcAutoConfiguration.java b/graphql-graphiql-spring-boot-starter/src/main/java/ru/sadv1r/spring/graphql/editor/graphiql/configuration/GraphiQlWebMvcAutoConfiguration.java index a8dbed5..960fcd2 100644 --- a/graphql-graphiql-spring-boot-starter/src/main/java/ru/sadv1r/spring/graphql/editor/graphiql/configuration/GraphiQlWebMvcAutoConfiguration.java +++ b/graphql-graphiql-spring-boot-starter/src/main/java/ru/sadv1r/spring/graphql/editor/graphiql/configuration/GraphiQlWebMvcAutoConfiguration.java @@ -29,6 +29,7 @@ public RouterFunction 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); } diff --git a/graphql-graphiql-spring-boot-starter/src/main/java/ru/sadv1r/spring/graphql/editor/graphiql/configuration/GraphiqlProperties.java b/graphql-graphiql-spring-boot-starter/src/main/java/ru/sadv1r/spring/graphql/editor/graphiql/configuration/GraphiqlProperties.java index dcbbb4a..9196a63 100644 --- a/graphql-graphiql-spring-boot-starter/src/main/java/ru/sadv1r/spring/graphql/editor/graphiql/configuration/GraphiqlProperties.java +++ b/graphql-graphiql-spring-boot-starter/src/main/java/ru/sadv1r/spring/graphql/editor/graphiql/configuration/GraphiqlProperties.java @@ -36,6 +36,8 @@ public class GraphiqlProperties { private Cdn cdn = Cdn.UNPKG; + private String stylePath; + public boolean isEnabled() { return enabled; } @@ -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; diff --git a/graphql-graphiql-spring-boot-starter/src/main/resources/templates/graphiql.html b/graphql-graphiql-spring-boot-starter/src/main/resources/templates/graphiql.html index 7f41b35..379cc34 100644 --- a/graphql-graphiql-spring-boot-starter/src/main/resources/templates/graphiql.html +++ b/graphql-graphiql-spring-boot-starter/src/main/resources/templates/graphiql.html @@ -25,6 +25,8 @@ crossorigin th:src="|${cdnHost}/@graphiql/plugin-explorer/dist/index.umd.js|"> + +
Loading...
diff --git a/samples/web-sample/src/main/resources/application.yaml b/samples/web-sample/src/main/resources/application.yaml index 0252165..e763631 100644 --- a/samples/web-sample/src/main/resources/application.yaml +++ b/samples/web-sample/src/main/resources/application.yaml @@ -14,6 +14,7 @@ spring: headers: x-test: test plugins: EXPLORER + stylePath: /style.css playground: settings: editor: diff --git a/samples/web-sample/src/main/resources/static/style.css b/samples/web-sample/src/main/resources/static/style.css new file mode 100644 index 0000000..a36271b --- /dev/null +++ b/samples/web-sample/src/main/resources/static/style.css @@ -0,0 +1,3 @@ +.graphiql-logo-link { + --color-neutral: 24, 28%, 32%; +} \ No newline at end of file diff --git a/samples/webflux-sample/src/main/resources/application.yaml b/samples/webflux-sample/src/main/resources/application.yaml index 1c81cf3..7805950 100644 --- a/samples/webflux-sample/src/main/resources/application.yaml +++ b/samples/webflux-sample/src/main/resources/application.yaml @@ -8,6 +8,7 @@ spring: headers: x-test: test plugins: EXPLORER + stylePath: /style.css playground: settings: editor: diff --git a/samples/webflux-sample/src/main/resources/static/style.css b/samples/webflux-sample/src/main/resources/static/style.css new file mode 100644 index 0000000..a36271b --- /dev/null +++ b/samples/webflux-sample/src/main/resources/static/style.css @@ -0,0 +1,3 @@ +.graphiql-logo-link { + --color-neutral: 24, 28%, 32%; +} \ No newline at end of file