Skip to content
This repository was archived by the owner on Dec 19, 2023. It is now read-only.

Commit dc3f483

Browse files
feat(#212): GraphQL Playground settings are now configurable
1 parent fd1c312 commit dc3f483

14 files changed

+171
-4
lines changed
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
11
package com.oembedler.moon.playground.boot;
22

3+
import com.fasterxml.jackson.databind.ObjectMapper;
4+
import com.oembedler.moon.playground.boot.settings.PlaygroundSettingsProperties;
35
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
46
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
57
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
8+
import org.springframework.boot.context.properties.EnableConfigurationProperties;
69
import org.springframework.context.annotation.Bean;
710
import org.springframework.context.annotation.Configuration;
811
import org.springframework.web.servlet.DispatcherServlet;
912

1013
@Configuration
1114
@ConditionalOnWebApplication
1215
@ConditionalOnClass(DispatcherServlet.class)
16+
@EnableConfigurationProperties(PlaygroundSettingsProperties.class)
1317
public class PlaygroundAutoConfiguration {
1418

1519
@Bean
1620
@ConditionalOnProperty(value = "playground.enabled", havingValue = "true", matchIfMissing = true)
17-
PlaygroundController altairController() {
18-
return new PlaygroundController();
21+
PlaygroundController playgroundController(final PlaygroundSettingsProperties playgroundSettingsProperties,
22+
final ObjectMapper objectMapper) {
23+
return new PlaygroundController(playgroundSettingsProperties, objectMapper);
1924
}
2025
}

playground-spring-boot-autoconfigure/src/main/java/com/oembedler/moon/playground/boot/PlaygroundController.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
package com.oembedler.moon.playground.boot;
22

3+
import com.fasterxml.jackson.databind.ObjectMapper;
4+
import com.oembedler.moon.playground.boot.settings.PlaygroundSettingsProperties;
5+
import lombok.RequiredArgsConstructor;
36
import org.springframework.beans.factory.annotation.Value;
47
import org.springframework.stereotype.Controller;
58
import org.springframework.ui.Model;
69
import org.springframework.web.bind.annotation.GetMapping;
710

811
@Controller
12+
@RequiredArgsConstructor
913
public class PlaygroundController {
1014

1115
private static final String CDN_ROOT = "https://cdn.jsdelivr.net/npm/graphql-playground-react";
@@ -39,6 +43,10 @@ public class PlaygroundController {
3943
@Value("${playground.pageTitle:Playground}")
4044
private String pageTitle;
4145

46+
private final PlaygroundSettingsProperties settingsProperties;
47+
48+
private final ObjectMapper objectMapper;
49+
4250
@GetMapping("${playground.mapping:/playground}")
4351
public String playground(final Model model) {
4452
if (cdnEnabled) {
@@ -49,6 +57,7 @@ public String playground(final Model model) {
4957
model.addAttribute("graphqlEndpoint", graphqlEndpoint);
5058
model.addAttribute("subscriptionsEndpoint", subscriptionsEndpoint);
5159
model.addAttribute("pageTitle", pageTitle);
60+
model.addAttribute("settings", objectMapper.valueToTree(settingsProperties));
5261
return "playground";
5362
}
5463

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.oembedler.moon.playground.boot.settings;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
5+
public enum PlaygroundEditorCursorShape {
6+
@JsonProperty("line")
7+
LINE,
8+
@JsonProperty("block")
9+
BLOCK,
10+
@JsonProperty("underline")
11+
UNDERLINE
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.oembedler.moon.playground.boot.settings;
2+
3+
import com.fasterxml.jackson.annotation.JsonInclude;
4+
import lombok.Data;
5+
6+
@Data
7+
@JsonInclude(JsonInclude.Include.NON_NULL)
8+
public class PlaygroundEditorSettings {
9+
10+
private PlaygroundEditorCursorShape cursorShape;
11+
private String fontFamily;
12+
private Integer fontSize;
13+
private PlaygroundEditorTheme theme;
14+
private Boolean reuseHeaders;
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.oembedler.moon.playground.boot.settings;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
5+
public enum PlaygroundEditorTheme {
6+
@JsonProperty("light")
7+
LIGHT,
8+
@JsonProperty("dark")
9+
DARK
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.oembedler.moon.playground.boot.settings;
2+
3+
import com.fasterxml.jackson.annotation.JsonInclude;
4+
import lombok.Data;
5+
6+
@Data
7+
@JsonInclude(JsonInclude.Include.NON_NULL)
8+
public class PlaygroundPrettierSettings {
9+
10+
private Integer printWidth;
11+
private Integer tabWidth;
12+
private Boolean useTabs;
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.oembedler.moon.playground.boot.settings;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
5+
public enum PlaygroundRequestIncludeCredentials {
6+
@JsonProperty("omit")
7+
OMIT,
8+
@JsonProperty("include")
9+
INCLUDE,
10+
@JsonProperty("same-origin")
11+
SAME_ORIGIN
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.oembedler.moon.playground.boot.settings;
2+
3+
import com.fasterxml.jackson.annotation.JsonInclude;
4+
import lombok.Data;
5+
6+
@Data
7+
@JsonInclude(JsonInclude.Include.NON_NULL)
8+
public class PlaygroundRequestSettings {
9+
10+
private PlaygroundRequestIncludeCredentials credentials;
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.oembedler.moon.playground.boot.settings;
2+
3+
import com.fasterxml.jackson.annotation.JsonInclude;
4+
import lombok.Data;
5+
6+
@Data
7+
@JsonInclude(JsonInclude.Include.NON_NULL)
8+
public class PlaygroundSchemaPollingSettings {
9+
10+
private Boolean enable;
11+
private String endpointFilter;
12+
private Integer interval;
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.oembedler.moon.playground.boot.settings;
2+
3+
import com.fasterxml.jackson.annotation.JsonInclude;
4+
import com.fasterxml.jackson.annotation.JsonUnwrapped;
5+
import lombok.Data;
6+
7+
@Data
8+
@JsonInclude(JsonInclude.Include.NON_NULL)
9+
public class PlaygroundSchemaSettings {
10+
11+
private Boolean disableComments;
12+
13+
@JsonUnwrapped(prefix = "polling.")
14+
private PlaygroundSchemaPollingSettings polling;
15+
}

0 commit comments

Comments
 (0)