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

Commit 6c42392

Browse files
authored
Merge pull request #201 from Sparow199/develop
GraphiQL && Voyager with full CDNs dependencies fetching
2 parents 1f93410 + 62eff09 commit 6c42392

File tree

20 files changed

+2184
-3214
lines changed

20 files changed

+2184
-3214
lines changed

example/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ repositories {
3838
dependencies{
3939
compile(project(":graphql-spring-boot-starter"))
4040
compile(project(":graphiql-spring-boot-starter"))
41-
41+
compile(project(":voyager-spring-boot-starter"))
42+
4243
compile("org.springframework.boot:spring-boot-starter-web:$LIB_SPRING_BOOT_VER")
4344
compile("org.springframework.boot:spring-boot-starter-actuator:$LIB_SPRING_BOOT_VER")
4445
}

example/src/main/resources/application.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@ graphql:
1717
actuator-metrics: true
1818
graphiql:
1919
enabled: true
20+
voyager:
21+
enabled: true

graphiql-spring-boot-autoconfigure/src/main/java/com/oembedler/moon/graphiql/boot/GraphiQLController.java

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@
3131
@Controller
3232
public class GraphiQLController {
3333

34-
private static final String CDNJS_CLOUDFLARE_COM_AJAX_LIBS_GRAPHIQL = "//cdnjs.cloudflare.com/ajax/libs/graphiql/";
34+
private static final String CDNJS_CLOUDFLARE_COM_AJAX_LIBS = "//cdnjs.cloudflare.com/ajax/libs/";
35+
private static final String CDN_JSDELIVR_NET_NPM = "//cdn.jsdelivr.net/npm/";
36+
private static final String GRAPHIQL = "graphiql";
3537

3638
@Value("${graphiql.endpoint.graphql:/graphql}")
3739
private String graphqlEndpoint;
@@ -48,7 +50,7 @@ public class GraphiQLController {
4850
@Value("${graphiql.cdn.enabled:false}")
4951
private Boolean graphiqlCdnEnabled;
5052

51-
@Value("${graphiql.cdn.version:0.11.11}")
53+
@Value("${graphiql.cdn.version:0.13.0}")
5254
private String graphiqlCdnVersion;
5355

5456
@Value("${graphiql.subscriptions.timeout:30}")
@@ -112,19 +114,47 @@ private Map<String, String> getReplacements(String graphqlEndpoint, String subsc
112114
replacements.put("subscriptionsEndpoint", subscriptionsEndpoint);
113115
replacements.put("staticBasePath", staticBasePath);
114116
replacements.put("pageTitle", pageTitle);
115-
replacements.put("graphiqlCssUrl", graphiqlUrl(staticBasePath, "graphiql.min.css"));
116-
replacements.put("graphiqlJsUrl", graphiqlUrl(staticBasePath, "graphiql.min.js"));
117+
replacements.put("es6PromiseJsUrl", getResourceUrl(staticBasePath, "es6-promise.auto.min.js",
118+
joinCdnjsPath("es6-promise", "4.1.1", "es6-promise.auto.min.js")));
119+
replacements.put("fetchJsUrl", getResourceUrl(staticBasePath, "fetch.min.js",
120+
joinCdnjsPath("fetch", "2.0.4", "fetch.min.js")));
121+
replacements.put("reactJsUrl", getResourceUrl(staticBasePath, "react.min.js",
122+
joinCdnjsPath("react", "16.8.3", "umd/react.production.min.js")));
123+
replacements.put("reactDomJsUrl", getResourceUrl(staticBasePath, "react-dom.min.js",
124+
joinCdnjsPath("react-dom", "16.8.3", "umd/react-dom.production.min.js")));
125+
replacements.put("graphiqlCssUrl", getResourceUrl(staticBasePath, "graphiql.min.css",
126+
joinJsDelivrPath(GRAPHIQL, graphiqlCdnVersion, "graphiql.css")));
127+
replacements.put("graphiqlJsUrl", getResourceUrl(staticBasePath, "graphiql.min.js",
128+
joinJsDelivrPath(GRAPHIQL, graphiqlCdnVersion, "graphiql.min.js")));
129+
replacements.put("subscriptionsTransportWsBrowserClientUrl", getResourceUrl(staticBasePath,
130+
"subscriptions-transport-ws-browser-client.js",
131+
joinJsDelivrPath("subscriptions-transport-ws", "0.9.15", "browser/client.js")));
132+
replacements.put("graphiqlSubscriptionsFetcherBrowserClientUrl", getResourceUrl(staticBasePath,
133+
"graphiql-subscriptions-fetcher-browser-client.js",
134+
joinJsDelivrPath("graphiql-subscriptions-fetcher", "0.0.2", "browser/client.js")));
117135
replacements.put("props", props);
118136
replacements.put("headers", headers);
119137
replacements.put("subscriptionClientTimeout", String.valueOf(subscriptionsTimeout));
120138
return replacements;
121139
}
122140

123-
private String graphiqlUrl(String staticBasePath, String filename) {
124-
if (graphiqlCdnEnabled && StringUtils.isNotBlank(graphiqlCdnVersion)) {
125-
return CDNJS_CLOUDFLARE_COM_AJAX_LIBS_GRAPHIQL + graphiqlCdnVersion + "/" + filename;
141+
private String getResourceUrl(String staticBasePath, String staticFileName, String cdnUrl) {
142+
if (graphiqlCdnEnabled && StringUtils.isNotBlank(cdnUrl)) {
143+
return cdnUrl;
126144
}
127-
return staticBasePath + "vendor/" + filename;
145+
return joinStaticPath(staticBasePath, staticFileName);
146+
}
147+
148+
private String joinStaticPath(String staticBasePath, String staticFileName) {
149+
return staticBasePath + "vendor/" + staticFileName;
150+
}
151+
152+
private String joinCdnjsPath(String library, String cdnVersion, String cdnFileName) {
153+
return CDNJS_CLOUDFLARE_COM_AJAX_LIBS + library + "/" + cdnVersion + "/" + cdnFileName;
154+
}
155+
156+
private String joinJsDelivrPath(String library, String cdnVersion, String cdnFileName) {
157+
return CDN_JSDELIVR_NET_NPM + library + "@" + cdnVersion + "/" + cdnFileName;
128158
}
129159

130160
private String constructGraphQlEndpoint(HttpServletRequest request, @RequestParam Map<String, String> params) {

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,18 @@
2222
justify-content: center;
2323
text-align: center;
2424
}
25+
2526
</style>
2627

27-
<script src="${staticBasePath}vendor/es6-promise.auto.min.js"></script>
28-
<script src="${staticBasePath}vendor/fetch.min.js"></script>
29-
<script src="${staticBasePath}vendor/react.min.js"></script>
30-
<script src="${staticBasePath}vendor/react-dom.min.js"></script>
28+
<script src="${es6PromiseJsUrl}"></script>
29+
<script src="${fetchJsUrl}"></script>
30+
<script src="${reactJsUrl}"></script>
31+
<script src="${reactDomJsUrl}"></script>
3132

3233
<link rel="stylesheet" href="${graphiqlCssUrl}"/>
3334
<script src="${graphiqlJsUrl}"></script>
34-
<script src="${staticBasePath}vendor/subscriptions-transport-ws-browser-client-0.8.3.js"></script>
35-
<script src="${staticBasePath}vendor/graphiql-subscriptions-fetcher-browser-client-0.0.2.js"></script>
35+
<script src="${subscriptionsTransportWsBrowserClientUrl}"></script>
36+
<script src="${graphiqlSubscriptionsFetcherBrowserClientUrl}"></script>
3637
</head>
3738
<body>
3839
<div id="splash">
@@ -146,6 +147,7 @@
146147
React.createElement(GraphiQL, props),
147148
document.body
148149
);
150+
149151
</script>
150152
</body>
151153
</html>

graphiql-spring-boot-autoconfigure/src/main/resources/static/vendor/es6-promise.auto.min.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.

graphiql-spring-boot-autoconfigure/src/main/resources/static/vendor/graphiql.min.css

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

graphiql-spring-boot-autoconfigure/src/main/resources/static/vendor/graphiql.min.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.

graphiql-spring-boot-autoconfigure/src/main/resources/static/vendor/react-dom.min.js

Lines changed: 215 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

graphiql-spring-boot-autoconfigure/src/main/resources/static/vendor/react.min.js

Lines changed: 28 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)