Skip to content

Commit 6a0970c

Browse files
authored
feat: add Spring WebMvc support for /graphiql application console (#247)
1 parent 49e7c40 commit 6a0970c

File tree

8 files changed

+60
-1
lines changed

8 files changed

+60
-1
lines changed

graphql-jpa-query-graphiql/pom.xml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,18 @@
22
<modelVersion>4.0.0</modelVersion>
33
<parent>
44
<groupId>com.introproventures</groupId>
5-
<artifactId>graphql-jpa-query</artifactId>
5+
<artifactId>graphql-jpa-query-build</artifactId>
66
<version>0.4.3-SNAPSHOT</version>
7+
<relativePath>../graphql-jpa-query-build</relativePath>
78
</parent>
89
<artifactId>graphql-jpa-query-graphiql</artifactId>
10+
11+
<dependencies>
12+
<dependency>
13+
<groupId>org.springframework.boot</groupId>
14+
<artifactId>spring-boot-starter-web</artifactId>
15+
<optional>true</optional>
16+
</dependency>
17+
</dependencies>
18+
919
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.introproventures.graphql.jpa.query.graphiql;
2+
3+
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
4+
import org.springframework.context.annotation.Bean;
5+
import org.springframework.context.annotation.Configuration;
6+
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
7+
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
8+
9+
@Configuration
10+
@ConditionalOnWebApplication
11+
public class WebMvcViewControllerConfigurer {
12+
13+
@Bean
14+
public WebMvcConfigurer graphqiQLRedirectToIndex() {
15+
return new WebMvcConfigurer() {
16+
@Override
17+
public void addViewControllers(ViewControllerRegistry registry) {
18+
registry.addRedirectViewController("/graphiql", "graphiql/index.html");
19+
}
20+
};
21+
}
22+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
2+
com.introproventures.graphql.jpa.query.graphiql.WebMvcViewControllerConfigurer

graphql-jpa-query-graphiql/src/main/resources/static/index.html renamed to graphql-jpa-query-graphiql/src/main/resources/static/graphiql/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<!DOCTYPE html>
99
<html>
1010
<head>
11+
<base href="./" />
1112
<style>
1213
body {
1314
height: 100%;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.introproventures.graphql.jpa.query.graphiql;
2+
3+
import org.junit.Test;
4+
import org.junit.runner.RunWith;
5+
import org.springframework.boot.autoconfigure.SpringBootApplication;
6+
import org.springframework.boot.test.context.SpringBootTest;
7+
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
8+
import org.springframework.test.context.junit4.SpringRunner;
9+
10+
@RunWith(SpringRunner.class)
11+
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
12+
public class WebMvcViewControllerConfigurerTest {
13+
14+
@SpringBootApplication
15+
static class Application {
16+
17+
}
18+
19+
@Test
20+
public void contextLoads() {
21+
// success
22+
}
23+
24+
}

0 commit comments

Comments
 (0)