File tree 4 files changed +30
-13
lines changed
src/main/java/com/techprimers/graphql/springbootgrapqlexample
4 files changed +30
-13
lines changed Original file line number Diff line number Diff line change 1
1
# Spring Boot with GraphQL Query Example
2
2
3
+ Update: Upgraded to Java 11 and Graph QL to 5+ version dependency
4
+
3
5
## Book Store
4
6
- ` /rest/books ` is the REST resource which can fetch Books information
5
7
- DataFetchers are Interfaces for RuntimeWiring of GraphQL with JpaRepository
6
8
7
9
## Sample GraphQL Scalar Queries
8
10
- Accessible under ` http://localhost:8091/rest/books `
9
11
- Usage for ` allBooks `
10
- `{
12
+ ```
13
+ {
11
14
allBooks {
12
15
isn
13
16
title
14
17
authors
15
18
publisher
16
19
}
17
- }`
20
+ }
21
+ ```
18
22
- Usage for ` book `
19
- `{
23
+ ```
24
+ {
20
25
book(id: "123") {
21
26
title
22
27
authors
23
28
publisher
24
- }`
29
+ }
30
+ ```
25
31
- Combination of both ` allBooks ` and ` book `
26
- `{
32
+ ```
33
+ {
27
34
allBooks {
28
35
title
29
36
authors
33
40
authors
34
41
publisher
35
42
}
36
- }`
43
+ }
44
+ ```
Original file line number Diff line number Diff line change 14
14
<parent >
15
15
<groupId >org.springframework.boot</groupId >
16
16
<artifactId >spring-boot-starter-parent</artifactId >
17
- <version >1.5.9 .RELEASE</version >
17
+ <version >2.3.0 .RELEASE</version >
18
18
<relativePath /> <!-- lookup parent from repository -->
19
19
</parent >
20
20
21
21
<properties >
22
22
<project .build.sourceEncoding>UTF-8</project .build.sourceEncoding>
23
23
<project .reporting.outputEncoding>UTF-8</project .reporting.outputEncoding>
24
- <java .version>1.8 </java .version>
24
+ <java .version>11 </java .version>
25
25
</properties >
26
26
27
27
<dependencies >
45
45
<optional >true</optional >
46
46
</dependency >
47
47
48
+ <!-- https://mvnrepository.com/artifact/com.graphql-java/graphql-spring-boot-starter -->
48
49
<dependency >
49
50
<groupId >com.graphql-java</groupId >
50
51
<artifactId >graphql-spring-boot-starter</artifactId >
51
- <version >3.6.0 </version >
52
+ <version >5.0.2 </version >
52
53
</dependency >
54
+
53
55
<dependency >
54
56
<groupId >com.graphql-java</groupId >
55
57
<artifactId >graphql-java-tools</artifactId >
56
- <version >3.2.0</version >
58
+ <version >5.2.4</version >
59
+ </dependency >
60
+
61
+ <dependency >
62
+ <groupId >javax.xml.bind</groupId >
63
+ <artifactId >jaxb-api</artifactId >
64
+ <version >2.3.0</version >
57
65
</dependency >
58
66
59
67
<dependency >
Original file line number Diff line number Diff line change 9
9
import javax .persistence .Id ;
10
10
import javax .persistence .Table ;
11
11
12
- @ Setter
13
- @ Getter
14
12
@ AllArgsConstructor
15
13
@ NoArgsConstructor
14
+ @ Setter
15
+ @ Getter
16
16
@ Table
17
17
@ Entity
18
18
public class Book {
@@ -23,4 +23,5 @@ public class Book {
23
23
private String publisher ;
24
24
private String [] authors ;
25
25
private String publishedDate ;
26
+
26
27
}
Original file line number Diff line number Diff line change @@ -18,6 +18,6 @@ public Book get(DataFetchingEnvironment dataFetchingEnvironment) {
18
18
19
19
String isn = dataFetchingEnvironment .getArgument ("id" );
20
20
21
- return bookRepository .findOne (isn );
21
+ return bookRepository .findById (isn ). get ( );
22
22
}
23
23
}
You can’t perform that action at this time.
0 commit comments