Skip to content

Commit

Permalink
Fixed GraphQL Playground Tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
sadv1r authored Jun 25, 2023
1 parent 6142ab3 commit 48aa091
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 17 deletions.
21 changes: 16 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,18 +150,29 @@ graphql:
headers:
x-test: test
tabs:
- endpoint: http://localhost:8080/graphql
- name: GraphQL
endpoint: http://localhost:8080/graphql
query: |-
query($id: ID!) {
artifactRepository(id: $id) {
name
url
}
}
name: GraphQL
variables: '{"id": 1}'
responses:
- '{"data": null}'
variables: |-
{
"id": 1
}
responses:
- >
{
"data": {
"artifactRepositories": [{
"name": "test",
"url": "http://localhost:8080"
}]
}
}
headers:
x-test2: test2
cdn: unpkg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonUnwrapped;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.core.io.ClassPathResource;
import org.springframework.util.FileCopyUtils;
Expand Down Expand Up @@ -382,17 +381,17 @@ public void setTracingSupported(Boolean tracingSupported) {
}

@JsonInclude(JsonInclude.Include.NON_NULL)
private class Tab {
private static class Tab {

private String endpoint;

private String query;

private String name;

// private Object variables; TODO
private String variables;

// private Object responses; TODO
private List<String> responses;

private Map<String, String> headers;

Expand Down Expand Up @@ -420,6 +419,22 @@ public void setName(String name) {
this.name = name;
}

public String getVariables() {
return variables;
}

public void setVariables(String variables) {
this.variables = variables;
}

public List<String> getResponses() {
return responses;
}

public void setResponses(List<String> responses) {
this.responses = responses;
}

public Map<String, String> getHeaders() {
return headers;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ public RouterFunction<ServerResponse> reactivePlaygroundRouterFunction(Playgroun
@Value("${spring.graphql.path:/graphql}") String serverPath) {
RouterFunctions.Builder builder = RouterFunctions.route();
if (properties.isEnabled()) {
final HandlerFunction<ServerResponse> graphiql = e -> (Mono<ServerResponse>) (Mono<?>) RenderingResponse.create("playground")
final HandlerFunction<ServerResponse> handler = e -> (Mono<ServerResponse>) (Mono<?>) RenderingResponse.create("playground")
.modelAttribute("cdnHost", properties.getCdn().getHost())
.modelAttribute("serverPath", serverPath)
.modelAttribute("settings", properties.getSettings())
.modelAttribute("headers", properties.getHeaders())
.modelAttribute("tabs", properties.getTabs())
.build();
builder = builder.GET(properties.getPath(), graphiql);
builder = builder.GET(properties.getPath(), handler);
}
return builder.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ public class PlaygroundWebMvcAutoConfiguration {

@Bean
@Order(-1)
public RouterFunction<ServerResponse> graphiQlRouterFunction(PlaygroundProperties properties,
public RouterFunction<ServerResponse> playgroundRouterFunction(PlaygroundProperties properties,
@Value("${spring.graphql.path:/graphql}") String serverPath) {
RouterFunctions.Builder builder = RouterFunctions.route();
if (properties.isEnabled()) {
final HandlerFunction<ServerResponse> graphiql = e -> RenderingResponse.create("playground")
final HandlerFunction<ServerResponse> handler = e -> RenderingResponse.create("playground")
.modelAttribute("cdnHost", properties.getCdn().getHost())
.modelAttribute("serverPath", serverPath)
.modelAttribute("settings", properties.getSettings())
.modelAttribute("headers", properties.getHeaders())
.modelAttribute("tabs", properties.getTabs())
.build();
builder = builder.GET(properties.getPath(), graphiql);
builder = builder.GET(properties.getPath(), handler);
}
return builder.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
GraphQLPlayground.init(document.getElementById('root'), {
endpoint: '[(${serverPath})]',
settings: /*[[${settings}]]*/,
headers: /*[[${headers}]]*/
headers: /*[[${headers}]]*/,
tabs: /*[[${tabs}]]*/
})
})</script>
</body>
Expand Down
38 changes: 37 additions & 1 deletion samples/web-sample/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,40 @@ spring:
variables:
id: 1
headers:
x-test: test
x-test: test
playground:
settings:
editor:
cursor-shape: line
font-family: Consolas
font-size: 14
reuse-headers: true
theme: light
headers:
x-test: test
tabs:
- name: Query
endpoint: http://localhost:8080/graphql
query: |-
query($id: ID!) {
artifactRepository(id: $id) {
name
url
}
}
variables: |-
{
"id": 1
}
responses:
- >
{
"data": {
"artifactRepositories": [{
"name": "test",
"url": "http://localhost:8080"
}]
}
}
headers:
x-test2: test2
28 changes: 27 additions & 1 deletion samples/webflux-sample/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,30 @@ spring:
reuse-headers: true
theme: light
headers:
x-test: test
x-test: test
tabs:
- name: Query
endpoint: http://localhost:8080/graphql
query: |-
query($id: ID!) {
artifactRepository(id: $id) {
name
url
}
}
variables: |-
{
"id": 1
}
responses:
- >
{
"data": {
"artifactRepositories": [{
"name": "test",
"url": "http://localhost:8080"
}]
}
}
headers:
x-test2: test2

0 comments on commit 48aa091

Please sign in to comment.