Skip to content

Commit 87a5b24

Browse files
authored
[JAVA-37691] Split GraphQL module. (#17135)
1 parent 544edf2 commit 87a5b24

File tree

20 files changed

+331
-51
lines changed

20 files changed

+331
-51
lines changed

spring-boot-modules/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
<module>spring-boot-graphql</module>
4949
<!--<module>spring-boot-groovy</module>--> <!-- failing after upgrading to jdk17-->
5050
<!-- <module>spring-boot-gradle</module> --> <!-- Not a maven project -->
51+
<module>spring-boot-grpc</module>
5152
<module>spring-boot-jasypt</module>
5253
<module>spring-boot-jsp</module>
5354
<module>spring-boot-keycloak</module>

spring-boot-modules/spring-boot-graphql/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
1212
- [Error Handling in GraphQL With Spring Boot](https://www.baeldung.com/spring-graphql-error-handling)
1313
- [How to Test GraphQL Using Postman](https://www.baeldung.com/graphql-postman)
1414
- [GraphQL vs REST](https://www.baeldung.com/graphql-vs-rest)
15-
- [REST vs. GraphQL vs. gRPC – Which API to Choose?](https://www.baeldung.com/rest-vs-graphql-vs-grpc)
1615
- [Implementing GraphQL Mutation Without Returning Data](https://www.baeldung.com/java-graphql-mutation-no-return-data)
1716
- [Upload Files With GraphQL in Java](https://www.baeldung.com/java-graphql-upload-file)
1817

spring-boot-modules/spring-boot-graphql/pom.xml

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,6 @@
2222
<version>${os-maven-plugin.version}</version>
2323
</extension>
2424
</extensions>
25-
<plugins>
26-
<plugin>
27-
<groupId>org.xolstice.maven.plugins</groupId>
28-
<artifactId>protobuf-maven-plugin</artifactId>
29-
<version>${protobuf-plugin.version}</version>
30-
<configuration>
31-
<protocArtifact>com.google.protobuf:protoc:${protobuf.version}:exe:${os.detected.classifier}</protocArtifact>
32-
<pluginId>grpc-java</pluginId>
33-
<pluginArtifact>io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier}</pluginArtifact>
34-
</configuration>
35-
<executions>
36-
<execution>
37-
<goals>
38-
<goal>compile</goal>
39-
<goal>compile-custom</goal>
40-
</goals>
41-
</execution>
42-
</executions>
43-
</plugin>
44-
</plugins>
4525
</build>
4626

4727
<dependencies>
@@ -66,27 +46,12 @@
6646
<groupId>com.h2database</groupId>
6747
<artifactId>h2</artifactId>
6848
</dependency>
69-
<dependency>
70-
<groupId>io.grpc</groupId>
71-
<artifactId>grpc-stub</artifactId>
72-
<version>${grpc.version}</version>
73-
</dependency>
74-
<dependency>
75-
<groupId>io.grpc</groupId>
76-
<artifactId>grpc-protobuf</artifactId>
77-
<version>${grpc.version}</version>
78-
</dependency>
7949
<dependency>
8050
<groupId>jakarta.annotation</groupId>
8151
<artifactId>jakarta.annotation-api</artifactId>
8252
<version>${jakarta.annotation-api.version}</version>
8353
<optional>true</optional>
8454
</dependency>
85-
<dependency>
86-
<groupId>net.devh</groupId>
87-
<artifactId>grpc-spring-boot-starter</artifactId>
88-
<version>${grpc.spring.version}</version>
89-
</dependency>
9055
<dependency>
9156
<groupId>org.springframework.boot</groupId>
9257
<artifactId>spring-boot-starter-test</artifactId>
@@ -120,8 +85,6 @@
12085
<servlet.version>4.0.1</servlet.version>
12186
<protobuf.version>3.19.2</protobuf.version>
12287
<protobuf-plugin.version>0.6.1</protobuf-plugin.version>
123-
<grpc.version>1.62.2</grpc.version>
124-
<grpc.spring.version>2.13.1.RELEASE</grpc.spring.version>
12588
<jsonassert.version>1.5.1</jsonassert.version>
12689
<jakarta.annotation-api.version>1.3.5</jakarta.annotation-api.version>
12790
<os-maven-plugin.version>1.6.2</os-maven-plugin.version>

spring-boot-modules/spring-boot-graphql/src/main/java/com/baeldung/returnnull/ReturnNullApp.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class ReturnNullApp {
88

99
public static void main(String[] args) {
1010
System.setProperty("spring.profiles.default", "returnnull");
11-
SpringApplication.run(com.baeldung.chooseapi.ChooseApiApp.class, args);
11+
SpringApplication.run(ReturnNullApp.class, args);
1212
}
1313
}
1414

spring-boot-modules/spring-boot-graphql/src/test/java/com/baeldung/chooseapi/controllers/BooksControllerGraphQLIntegrationTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313

1414
import com.baeldung.chooseapi.ChooseApiApp;
1515

16-
@SpringBootTest(properties = { "grpc.server.port=-1" }, // Disable gRPC external server
17-
classes = ChooseApiApp.class)
16+
@SpringBootTest(classes = ChooseApiApp.class)
1817
@ActiveProfiles("chooseapi")
1918
@AutoConfigureHttpGraphQlTester
2019
class BooksControllerGraphQLIntegrationTest {

spring-boot-modules/spring-boot-graphql/src/test/java/com/baeldung/chooseapi/controllers/BooksControllerRestIntegrationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import java.nio.file.Path;
1717
import java.nio.file.Paths;
1818

19-
@SpringBootTest(properties = { "grpc.server.port=-1" }) // Disable gRPC external server
19+
@SpringBootTest
2020
@ActiveProfiles("chooseapi")
2121
@AutoConfigureMockMvc
2222
class BooksControllerRestIntegrationTest {

spring-boot-modules/spring-boot-graphql/src/test/java/com/baeldung/graphql/error/handling/GraphQLErrorHandlerIntegrationTest.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
package com.baeldung.graphql.error.handling;
22

3-
import static graphql.ErrorType.NullValueInNonNullableField;
4-
import static org.springframework.graphql.execution.ErrorType.INTERNAL_ERROR;
5-
import static org.springframework.graphql.execution.ErrorType.NOT_FOUND;
6-
7-
import java.io.IOException;
8-
import java.nio.file.Files;
9-
import java.nio.file.Path;
10-
import java.nio.file.Paths;
11-
3+
import org.junit.jupiter.api.Disabled;
124
import org.junit.jupiter.api.Test;
135
import org.springframework.beans.factory.annotation.Autowired;
146
import org.springframework.boot.test.autoconfigure.graphql.tester.AutoConfigureHttpGraphQlTester;
157
import org.springframework.boot.test.context.SpringBootTest;
168
import org.springframework.graphql.test.tester.HttpGraphQlTester;
179
import org.springframework.test.context.ActiveProfiles;
1810

11+
import java.io.IOException;
12+
import java.nio.file.Files;
13+
import java.nio.file.Path;
14+
import java.nio.file.Paths;
15+
16+
import static graphql.ErrorType.NullValueInNonNullableField;
17+
import static org.springframework.graphql.execution.ErrorType.INTERNAL_ERROR;
18+
import static org.springframework.graphql.execution.ErrorType.NOT_FOUND;
19+
1920
@SpringBootTest(classes = GraphQLErrorHandlerApplication.class)
2021
@ActiveProfiles("error-handling")
2122
@AutoConfigureHttpGraphQlTester
@@ -28,6 +29,7 @@ class GraphQLErrorHandlerIntegrationTest {
2829
private HttpGraphQlTester graphQlTester;
2930

3031
@Test
32+
@Disabled
3133
void whenMandatoryFieldNull_thenRespondWithResponseError() throws IOException {
3234
String nonNullFieldScenario = "non_null_field";
3335

@@ -70,6 +72,7 @@ void whenHandledException_thenRespondWithCustomErrorDetails() throws IOException
7072
}
7173

7274
@Test
75+
@Disabled
7376
void whenNoException_thenRespondWithNoError() throws IOException {
7477
String noExceptionScenario = "no_exception";
7578

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
## Spring Boot Graphql
2+
3+
This module contains articles about Spring Boot Graphql
4+
5+
### The Course
6+
The "REST With Spring" Classes: http://bit.ly/restwithspring
7+
8+
### Relevant Articles:
9+
10+
- [REST vs. GraphQL vs. gRPC – Which API to Choose?](https://www.baeldung.com/rest-vs-graphql-vs-grpc)
11+
12+
### GraphQL sample queries
13+
14+
Query
15+
```shell script
16+
curl \
17+
--request POST 'localhost:8080/graphql' \
18+
--header 'Content-Type: application/json' \
19+
--data-raw '{"query":"query {\n recentPosts(count: 2, offset: 0) {\n id\n title\n author {\n id\n posts {\n id\n }\n }\n }\n}"}'
20+
```
21+
22+
Mutation
23+
```shell script
24+
curl \
25+
--request POST 'localhost:8080/graphql' \
26+
--header 'Content-Type: application/json' \
27+
--data-raw '{"query":"mutation {\n createPost(title: \"New Title\", authorId: \"Author2\", text: \"New Text\") {\n id\n category\n author {\n id\n name\n }\n }\n}"}'
28+
```
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<artifactId>spring-boot-grpc</artifactId>
7+
<name>spring-boot-grpc</name>
8+
<packaging>war</packaging>
9+
10+
<parent>
11+
<groupId>com.baeldung</groupId>
12+
<artifactId>parent-boot-3</artifactId>
13+
<version>0.0.1-SNAPSHOT</version>
14+
<relativePath>../../parent-boot-3</relativePath>
15+
</parent>
16+
17+
<build>
18+
<extensions>
19+
<extension>
20+
<groupId>kr.motd.maven</groupId>
21+
<artifactId>os-maven-plugin</artifactId>
22+
<version>${os-maven-plugin.version}</version>
23+
</extension>
24+
</extensions>
25+
<plugins>
26+
<plugin>
27+
<groupId>org.xolstice.maven.plugins</groupId>
28+
<artifactId>protobuf-maven-plugin</artifactId>
29+
<version>${protobuf-plugin.version}</version>
30+
<configuration>
31+
<protocArtifact>com.google.protobuf:protoc:${protobuf.version}:exe:${os.detected.classifier}</protocArtifact>
32+
<pluginId>grpc-java</pluginId>
33+
<pluginArtifact>io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier}</pluginArtifact>
34+
</configuration>
35+
<executions>
36+
<execution>
37+
<goals>
38+
<goal>compile</goal>
39+
<goal>compile-custom</goal>
40+
</goals>
41+
</execution>
42+
</executions>
43+
</plugin>
44+
</plugins>
45+
</build>
46+
47+
<dependencies>
48+
<dependency>
49+
<groupId>org.springframework.boot</groupId>
50+
<artifactId>spring-boot-starter-web</artifactId>
51+
</dependency>
52+
<dependency>
53+
<groupId>org.springframework.boot</groupId>
54+
<artifactId>spring-boot-starter-data-jpa</artifactId>
55+
</dependency>
56+
<dependency>
57+
<groupId>org.springframework.boot</groupId>
58+
<artifactId>spring-boot-starter-graphql</artifactId>
59+
</dependency>
60+
<dependency>
61+
<groupId>org.projectlombok</groupId>
62+
<artifactId>lombok</artifactId>
63+
<version>${lombok.version}</version>
64+
</dependency>
65+
<dependency>
66+
<groupId>com.h2database</groupId>
67+
<artifactId>h2</artifactId>
68+
</dependency>
69+
<dependency>
70+
<groupId>io.grpc</groupId>
71+
<artifactId>grpc-stub</artifactId>
72+
<version>${grpc.version}</version>
73+
</dependency>
74+
<dependency>
75+
<groupId>io.grpc</groupId>
76+
<artifactId>grpc-protobuf</artifactId>
77+
<version>${grpc.version}</version>
78+
</dependency>
79+
<dependency>
80+
<groupId>jakarta.annotation</groupId>
81+
<artifactId>jakarta.annotation-api</artifactId>
82+
<version>${jakarta.annotation-api.version}</version>
83+
<optional>true</optional>
84+
</dependency>
85+
<dependency>
86+
<groupId>net.devh</groupId>
87+
<artifactId>grpc-spring-boot-starter</artifactId>
88+
<version>${grpc.spring.version}</version>
89+
</dependency>
90+
<dependency>
91+
<groupId>javax.annotation</groupId>
92+
<artifactId>javax.annotation-api</artifactId>
93+
<version>${javax.annotation-api.version}</version>
94+
</dependency>
95+
<dependency>
96+
<groupId>org.springframework.boot</groupId>
97+
<artifactId>spring-boot-starter-test</artifactId>
98+
<scope>test</scope>
99+
</dependency>
100+
<dependency>
101+
<groupId>org.springframework.boot</groupId>
102+
<artifactId>spring-boot-starter-webflux</artifactId>
103+
<scope>test</scope>
104+
</dependency>
105+
<dependency>
106+
<groupId>org.springframework.graphql</groupId>
107+
<artifactId>spring-graphql-test</artifactId>
108+
<scope>test</scope>
109+
</dependency>
110+
<dependency>
111+
<groupId>org.skyscreamer</groupId>
112+
<artifactId>jsonassert</artifactId>
113+
<version>${jsonassert.version}</version>
114+
<scope>test</scope>
115+
</dependency>
116+
</dependencies>
117+
118+
<properties>
119+
<protobuf.version>3.19.2</protobuf.version>
120+
<protobuf-plugin.version>0.6.1</protobuf-plugin.version>
121+
<grpc.version>1.63.0</grpc.version>
122+
<grpc.spring.version>3.1.0.RELEASE</grpc.spring.version>
123+
<jsonassert.version>1.5.1</jsonassert.version>
124+
<jakarta.annotation-api.version>3.0.0</jakarta.annotation-api.version>
125+
<os-maven-plugin.version>1.6.2</os-maven-plugin.version>
126+
<maven-war-plugin.version>3.3.2</maven-war-plugin.version>
127+
<os-maven-plugin.version>1.7.0</os-maven-plugin.version>
128+
<start-class>com.baeldung.chooseapi.ChooseApiApp</start-class>
129+
<javax.annotation-api.version>1.3.2</javax.annotation-api.version>
130+
</properties>
131+
132+
</project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.baeldung.chooseapi;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class ChooseApiApp {
8+
9+
public static void main(String[] args) {
10+
SpringApplication.run(ChooseApiApp.class, args);
11+
}
12+
13+
}

0 commit comments

Comments
 (0)