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

Commit d0f37d4

Browse files
authored
Merge pull request #222 from Sparow199/develop
refactor(Altair): Upgrade Altair starter to v2.1.4
2 parents 078b2c4 + dd1b80c commit d0f37d4

File tree

5 files changed

+30
-10
lines changed

5 files changed

+30
-10
lines changed

altair-spring-boot-autoconfigure/src/main/java/com/oembedler/moon/altair/boot/AltairController.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,21 @@ public class AltairController {
4949
@Value("${altair.cdn.enabled:false}")
5050
private Boolean altairCdnEnabled;
5151

52-
@Value("${altair.cdn.version:2.1.1}")
52+
@Value("${altair.cdn.version:2.1.4}")
5353
private String altairCdnVersion;
5454

5555
@Autowired
5656
private Environment environment;
5757

5858
private String template;
5959
private String props;
60+
private String headers;
6061

6162
@PostConstruct
6263
public void onceConstructed() throws IOException {
6364
loadTemplate();
6465
loadProps();
66+
loadHeaders();
6567
}
6668

6769
private void loadTemplate() throws IOException {
@@ -74,6 +76,15 @@ private void loadProps() throws IOException {
7476
props = new PropsLoader(environment).load();
7577
}
7678

79+
private void loadHeaders() throws JsonProcessingException {
80+
PropertyGroupReader propertyReader = new PropertyGroupReader(environment, "graphiql.headers.");
81+
Properties headerProperties = propertyReader.load();
82+
addIfAbsent(headerProperties, "Accept");
83+
addIfAbsent(headerProperties, "Content-Type");
84+
this.headers = new ObjectMapper().writeValueAsString(headerProperties);
85+
}
86+
87+
7788
private void addIfAbsent(Properties headerProperties, String header) {
7889
if (!headerProperties.containsKey(header)) {
7990
headerProperties.setProperty(header, MediaType.APPLICATION_JSON_VALUE);
@@ -99,14 +110,15 @@ private Map<String, String> getReplacements(String graphqlEndpoint, String subsc
99110
replacements.put("subscriptionsEndpoint", subscriptionsEndpoint);
100111
replacements.put("pageTitle", pageTitle);
101112
replacements.put("pageFavicon", getResourceUrl("favicon.ico", "favicon.ico"));
102-
replacements.put("altairBaseUrl", getResourceUrl("/vendor/altair/",
113+
replacements.put("altairBaseUrl", getResourceUrl(String.join(staticBasePath, "/vendor/altair/"),
103114
joinJsUnpkgPath(ALTAIR, altairCdnVersion, "build/dist/")));
104115
replacements.put("altairLogoUrl", getResourceUrl("assets/img/logo_350.svg", "assets/img/logo_350.svg"));
105116
replacements.put("altairCssUrl", getResourceUrl("styles.css", "styles.css"));
106117
replacements.put("altairMainJsUrl", getResourceUrl("main.js", "main.js"));
107118
replacements.put("altairPolyfillsJsUrl", getResourceUrl("polyfills.js", "polyfills.js"));
108119
replacements.put("altairRuntimeJsUrl", getResourceUrl("runtime.js", "runtime.js"));
109120
replacements.put("props", props);
121+
replacements.put("headers", headers);
110122
return replacements;
111123
}
112124

altair-spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
},
4343
{
4444
"name": "altair.cdn.version",
45-
"defaultValue": "2.1.1",
45+
"defaultValue": "2.1.4",
4646
"type": "java.lang.String"
4747
},
4848
{
@@ -54,6 +54,11 @@
5454
"name": "altair.props.resources.variables",
5555
"defaultValue": null,
5656
"type": "java.lang.String"
57+
},
58+
{
59+
"name": "altair.headers.Authorization",
60+
"defaultValue": null,
61+
"type": "java.lang.String"
5762
}
5863
]
5964
}

altair-spring-boot-autoconfigure/src/main/resources/altair.html

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@
1313

1414
<body>
1515
<script>
16-
var properties = '${props}';
16+
var properties = JSON.parse(`${props}`);
1717

18-
window.__ALTAIR_ENDPOINT_URL__ = '${graphqlEndpoint}';
19-
window.__ALTAIR_SUBSCRIPTIONS_ENDPOINT__ = '${subscriptionsEndpoint}';
20-
window.__ALTAIR_INITIAL_QUERY__ = properties.defaultQuery;
21-
window.__ALTAIR_INITIAL_VARIABLES__ = properties.variables;
18+
window.__ALTAIR_ENDPOINT_URL__ = `${graphqlEndpoint}`;
19+
window.__ALTAIR_SUBSCRIPTIONS_ENDPOINT__ = `${subscriptionsEndpoint}`;
20+
window.__ALTAIR_INITIAL_QUERY__ = `${properties.defaultQuery}`;
21+
window.__ALTAIR_INITIAL_VARIABLES__ = `${properties.variables}`;
22+
window.__ALTAIR_INITIAL_HEADERS__ = JSON.parse(`${headers}`);
2223

2324
</script>
2425
<app-root>
@@ -29,6 +30,8 @@
2930
}
3031

3132

33+
34+
3235
</style>
3336
<div class="loading-screen styled">
3437
<div class="loading-screen-inner">

altair-spring-boot-autoconfigure/src/main/resources/static/vendor/altair/main.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

altair-spring-boot-autoconfigure/src/main/resources/static/vendor/altair/styles.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)