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

Commit 15f68ac

Browse files
committed
feat: upgrade embedded altair to 4.0.2
1 parent eff2209 commit 15f68ac

31 files changed

+99
-18
lines changed

example/src/main/resources/application.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ graphql:
2626
enabled: true
2727
cdn:
2828
enabled: false
29+
version: 4.0.2
2930
graphiql:
3031
enabled: true
3132
cdn:

graphql-spring-boot-autoconfigure/src/main/java/graphql/kickstart/autoconfigure/editor/altair/AltairController.java

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package graphql.kickstart.autoconfigure.editor.altair;
22

3+
import static java.lang.Integer.parseInt;
4+
import static java.util.Objects.nonNull;
5+
import static org.apache.commons.lang3.StringUtils.isNumeric;
6+
37
import com.fasterxml.jackson.core.JsonProcessingException;
48
import com.fasterxml.jackson.databind.ObjectMapper;
59
import graphql.kickstart.autoconfigure.editor.PropertyGroupReader;
@@ -13,6 +17,8 @@
1317
import javax.annotation.PostConstruct;
1418
import javax.servlet.http.HttpServletRequest;
1519
import javax.servlet.http.HttpServletResponse;
20+
import lombok.extern.slf4j.Slf4j;
21+
import lombok.val;
1622
import org.apache.commons.lang3.StringUtils;
1723
import org.apache.commons.text.StringSubstitutor;
1824
import org.springframework.beans.factory.annotation.Autowired;
@@ -25,10 +31,11 @@
2531
import org.springframework.web.bind.annotation.RequestParam;
2632

2733
/** @author Moncef AOUDIA */
34+
@Slf4j
2835
@Controller
2936
public class AltairController {
3037

31-
private static final String CDN_UNPKG = "//unpkg.com/";
38+
private static final String CDN_JSDELIVR_NET_NPM = "//cdn.jsdelivr.net/npm/";
3239
private static final String ALTAIR = "altair-static";
3340

3441
@Autowired private AltairProperties altairProperties;
@@ -95,14 +102,24 @@ private Map<String, String> getReplacements(
95102
replacements.put(
96103
"altairLogoUrl", getResourceUrl("assets/img/logo_350.svg", "assets/img/logo_350.svg"));
97104
replacements.put("altairCssUrl", getResourceUrl("styles.css", "styles.css"));
98-
replacements.put("altairMainJsUrl", getResourceUrl("main.js", "main.js"));
99-
replacements.put("altairPolyfillsJsUrl", getResourceUrl("polyfills.js", "polyfills.js"));
100-
replacements.put("altairRuntimeJsUrl", getResourceUrl("runtime.js", "runtime.js"));
105+
106+
val suffix = isJsSuffixAdded() ? "-es2018.js" : ".js";
107+
replacements.put("altairMainJsUrl", getResourceUrl("main-es2018.js", "main" + suffix));
108+
replacements.put("altairPolyfillsJsUrl", getResourceUrl("polyfills-es2018.js", "polyfills" + suffix));
109+
replacements.put("altairRuntimeJsUrl", getResourceUrl("runtime-es2018.js", "runtime" + suffix));
101110
replacements.put("props", props);
102111
replacements.put("headers", headers);
103112
return replacements;
104113
}
105114

115+
private boolean isJsSuffixAdded() {
116+
if (nonNull(altairProperties.getCdn().getVersion())) {
117+
String[] versionValues = altairProperties.getCdn().getVersion().split("\\.");
118+
return isNumeric(versionValues[0]) && parseInt(versionValues[0]) >= 4;
119+
}
120+
return false;
121+
}
122+
106123
private String getResourceUrl(String staticFileName, String cdnUrl) {
107124
if (altairProperties.getCdn().isEnabled() && StringUtils.isNotBlank(cdnUrl)) {
108125
return cdnUrl;
@@ -111,7 +128,7 @@ private String getResourceUrl(String staticFileName, String cdnUrl) {
111128
}
112129

113130
private String joinJsUnpkgPath(String library, String cdnVersion, String cdnFileName) {
114-
return CDN_UNPKG + library + "@" + cdnVersion + "/" + cdnFileName;
131+
return CDN_JSDELIVR_NET_NPM + library + "@" + cdnVersion + "/" + cdnFileName;
115132
}
116133

117134
private String constructGraphQlEndpoint(

graphql-spring-boot-autoconfigure/src/main/java/graphql/kickstart/autoconfigure/editor/altair/AltairProperties.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ static class Endpoint {
2525
static class Cdn {
2626

2727
private boolean enabled = false;
28-
private String version = "2.4.11";
28+
private String version = "4.0.2";
2929
}
3030
}

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

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

0 commit comments

Comments
 (0)