Skip to content

Commit

Permalink
Added GraphiQL Explorer Plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
sadv1r authored Oct 19, 2023
1 parent cb5ad9b commit 3a0f793
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public RouterFunction<ServerResponse> reactiveGraphiQlRouterFunction(GraphiqlPro
.modelAttribute("defaultEditorToolsVisibility", properties.getDefaultEditorToolsVisibility())
.modelAttribute("variables", properties.getVariables())
.modelAttribute("headers", properties.getHeaders())
.modelAttribute("plugins", properties.getPlugins())
.build();
builder = builder.GET(properties.getPath(), graphiql);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public RouterFunction<ServerResponse> graphiQlRouterFunction(GraphiqlProperties
.modelAttribute("defaultEditorToolsVisibility", properties.getDefaultEditorToolsVisibility())
.modelAttribute("variables", properties.getVariables())
.modelAttribute("headers", properties.getHeaders())
.modelAttribute("plugins", properties.getPlugins())
.build();
builder = builder.GET(properties.getPath(), graphiql);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.io.UncheckedIOException;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.Set;

/**
* Configuration properties for the GraphiQL GraphQL editor.
Expand All @@ -31,6 +32,8 @@ public class GraphiqlProperties {

private Map<String, String> headers;

private Set<Plugin> plugins = Set.of();

private Cdn cdn = Cdn.UNPKG;

public boolean isEnabled() {
Expand Down Expand Up @@ -81,6 +84,14 @@ public void setHeaders(Map<String, String> headers) {
this.headers = headers;
}

public Set<Plugin> getPlugins() {
return plugins;
}

public void setPlugins(Set<Plugin> plugins) {
this.plugins = plugins;
}

public Cdn getCdn() {
return cdn;
}
Expand Down Expand Up @@ -122,6 +133,13 @@ public Object getValue() {
}
}

public enum Plugin {
/**
* @see <a href="https://github.com/graphql/graphiql/tree/main/packages/graphiql-plugin-explorer">GraphiQL Explorer Plugin</a>
*/
EXPLORER
}

public enum Cdn {
JSDELIVR,
UNPKG;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@

<script th:src="|${cdnHost}/graphiql/graphiql.min.js|" type="application/javascript"></script>
<link rel="stylesheet" th:href="|${cdnHost}/graphiql/graphiql.min.css|"/>

<script th:if="${plugins.contains(T(ru.sadv1r.spring.graphql.editor.graphiql.configuration.GraphiqlProperties.Plugin).EXPLORER)}"
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|"/>
</head>
<body>
<div id="graphiql">Loading...</div>
Expand All @@ -38,6 +43,11 @@
variables: JSON.stringify([[${variables}]], undefined, 2),
// headers: '[[${headers}]]',
headers: JSON.stringify([[${headers}]], undefined, 2),
plugins: [
/*[# th:if="${plugins.contains(T(ru.sadv1r.spring.graphql.editor.graphiql.configuration.GraphiqlProperties.Plugin).EXPLORER)}"]*/
GraphiQLPluginExplorer.explorerPlugin(),
/*[/]*/
],
}),
);
</script>
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 @@ -13,6 +13,7 @@ spring:
id: 1
headers:
x-test: test
plugins: EXPLORER
playground:
settings:
editor:
Expand Down
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 @@ -7,6 +7,7 @@ spring:
id: 1
headers:
x-test: test
plugins: EXPLORER
playground:
settings:
editor:
Expand Down

0 comments on commit 3a0f793

Please sign in to comment.