Skip to content

GraphiQL separate module #204

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* {@link ConfigurationProperties properties} for Spring GraphQL.
*
* @author Brian Clozel
* @author Janne Valkealahti
* @since 1.0.0
*/
@ConfigurationProperties(prefix = "spring.graphql")
Expand Down Expand Up @@ -133,6 +134,11 @@ public static class GraphiQL {
*/
private boolean enabled = true;

/**
* GraphiQL logo string
*/
private String logo = "GraphiQL";

public String getPath() {
return this.path;
}
Expand All @@ -148,6 +154,14 @@ public boolean isEnabled() {
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}

public String getLogo() {
return logo;
}

public void setLogo(String logo) {
this.logo = logo;
}
}

public static class Websocket {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package org.springframework.graphql.boot;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;

import graphql.GraphQL;
Expand Down Expand Up @@ -65,6 +67,7 @@
* WebFlux.
*
* @author Brian Clozel
* @author Janne Valkealahti
* @since 1.0.0
*/
@Configuration(proxyBeanMethods = false)
Expand Down Expand Up @@ -108,9 +111,13 @@ public RouterFunction<ServerResponse> graphQlEndpoint(GraphQlHttpHandler handler
handler::handleRequest);

if (properties.getGraphiql().isEnabled()) {
Resource resource = resourceLoader.getResource("classpath:graphiql/index.html");
GraphiQlHandler graphiQlHandler = new GraphiQlHandler(graphQLPath, resource);
builder = builder.GET(properties.getGraphiql().getPath(), graphiQlHandler::handleRequest);
Resource htmlResource = resourceLoader.getResource("classpath:graphiql/index.html");
Resource jsResource = resourceLoader.getResource("classpath:graphiql/main.js");
Map<String, String> config = new HashMap<>();
config.put("LOGO", properties.getGraphiql().getLogo());
config.put("PATH", properties.getPath());
GraphiQlHandler graphiQLHandler = new GraphiQlHandler(htmlResource, jsResource, config);
builder = builder.GET(properties.getGraphiql().getPath() + "/**", graphiQLHandler::handleRequest);
}

if (properties.getSchema().getPrinter().isEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.springframework.graphql.boot;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -72,6 +73,7 @@
* Spring MVC.
*
* @author Brian Clozel
* @author Janne Valkealahti
* @since 1.0.0
*/
@Configuration(proxyBeanMethods = false)
Expand Down Expand Up @@ -117,9 +119,15 @@ public RouterFunction<ServerResponse> graphQlRouterFunction(GraphQlHttpHandler h
handler::handleRequest);

if (properties.getGraphiql().isEnabled()) {
Resource resource = resourceLoader.getResource("classpath:graphiql/index.html");
GraphiQlHandler graphiQLHandler = new GraphiQlHandler(graphQLPath, resource);
builder = builder.GET(properties.getGraphiql().getPath(), graphiQLHandler::handleRequest);
// TODO: should we disable graphiql automatically if optional graphiql module
// is not added to a classpath?
Resource htmlResource = resourceLoader.getResource("classpath:graphiql/index.html");
Resource jsResource = resourceLoader.getResource("classpath:graphiql/main.js");
Map<String, String> config = new HashMap<>();
config.put("LOGO", properties.getGraphiql().getLogo());
config.put("PATH", properties.getPath());
GraphiQlHandler graphiQLHandler = new GraphiQlHandler(htmlResource, jsResource, config);
builder = builder.GET(properties.getGraphiql().getPath() + "/**", graphiQLHandler::handleRequest);
}

if (properties.getSchema().getPrinter().isEnabled()) {
Expand Down
96 changes: 0 additions & 96 deletions graphql-spring-boot-starter/src/main/resources/graphiql/index.html

This file was deleted.

1 change: 1 addition & 0 deletions samples/webflux-websocket/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-webflux'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly project(':spring-graphql-graphiql')
testImplementation project(':spring-graphql-test')
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'io.projectreactor:reactor-test'
Expand Down
1 change: 1 addition & 0 deletions samples/webmvc-http/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ dependencies {
implementation 'com.querydsl:querydsl-core'
implementation 'com.querydsl:querydsl-jpa'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly project(':spring-graphql-graphiql')
runtimeOnly 'com.h2database:h2'
testImplementation project(':spring-graphql-test')
testImplementation 'org.springframework:spring-webflux'
Expand Down
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pluginManagement {

rootProject.name = 'spring-graphql'
include 'spring-graphql',
'spring-graphql-graphiql',
'spring-graphql-test',
'graphql-spring-boot-starter',
'samples:webmvc-http',
Expand Down
3 changes: 3 additions & 0 deletions spring-graphql-graphiql/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
build
dist
11 changes: 11 additions & 0 deletions spring-graphql-graphiql/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"printWidth": 80,
"tabWidth": 2,
"useTabs": false,
"semi": true,
"singleQuote": true,
"trailingComma": "none",
"bracketSpacing": false,
"arrowParens": "avoid",
"parser": "typescript"
}
8 changes: 8 additions & 0 deletions spring-graphql-graphiql/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
sourceMaps: true,
presets: [
require.resolve('@babel/preset-env'),
require.resolve('@babel/preset-react'),
require.resolve('@babel/preset-typescript'),
]
};
21 changes: 21 additions & 0 deletions spring-graphql-graphiql/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
plugins {
id 'java-library'
id "com.github.node-gradle.node" version "2.2.0"
}

java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

node {
version = '10.16.3'
npmVersion = '6.9.0'
download = true
}

jar.dependsOn 'npm_run_mavenbuild'

jar {
from 'dist' into 'graphiql'
}
23 changes: 23 additions & 0 deletions spring-graphql-graphiql/index.html.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<title>Spring GraphQL Explorer</title>
<script src="config.js"></script>
</head>

<body>
<style>
body {
padding: 0;
margin: 0;
min-height: 100vh;
}
#root {
height: 100vh;
}
</style>
<div id="root"></div>
</body>
</html>
Loading