File tree Expand file tree Collapse file tree
src/main/java/com/techprimers/graphql/springbootgrapqlexample Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11# Spring Boot with GraphQL Query Example
22
3+ Update: Upgraded to Java 11 and Graph QL to 5+ version dependency
4+
35## Book Store
46- ` /rest/books ` is the REST resource which can fetch Books information
57- DataFetchers are Interfaces for RuntimeWiring of GraphQL with JpaRepository
68
79## Sample GraphQL Scalar Queries
810- Accessible under ` http://localhost:8091/rest/books `
911- Usage for ` allBooks `
10- `{
12+ ```
13+ {
1114 allBooks {
1215 isn
1316 title
1417 authors
1518 publisher
1619 }
17- }`
20+ }
21+ ```
1822- Usage for ` book `
19- `{
23+ ```
24+ {
2025 book(id: "123") {
2126 title
2227 authors
2328 publisher
24- }`
29+ }
30+ ```
2531- Combination of both ` allBooks ` and ` book `
26- `{
32+ ```
33+ {
2734 allBooks {
2835 title
2936 authors
3340 authors
3441 publisher
3542 }
36- }`
43+ }
44+ ```
Original file line number Diff line number Diff line change 1414 <parent >
1515 <groupId >org.springframework.boot</groupId >
1616 <artifactId >spring-boot-starter-parent</artifactId >
17- <version >1.5.9 .RELEASE</version >
17+ <version >2.3.0 .RELEASE</version >
1818 <relativePath /> <!-- lookup parent from repository -->
1919 </parent >
2020
2121 <properties >
2222 <project .build.sourceEncoding>UTF-8</project .build.sourceEncoding>
2323 <project .reporting.outputEncoding>UTF-8</project .reporting.outputEncoding>
24- <java .version>1.8 </java .version>
24+ <java .version>11 </java .version>
2525 </properties >
2626
2727 <dependencies >
4545 <optional >true</optional >
4646 </dependency >
4747
48+ <!-- https://mvnrepository.com/artifact/com.graphql-java/graphql-spring-boot-starter -->
4849 <dependency >
4950 <groupId >com.graphql-java</groupId >
5051 <artifactId >graphql-spring-boot-starter</artifactId >
51- <version >3.6.0 </version >
52+ <version >5.0.2 </version >
5253 </dependency >
54+
5355 <dependency >
5456 <groupId >com.graphql-java</groupId >
5557 <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 >
5765 </dependency >
5866
5967 <dependency >
Original file line number Diff line number Diff line change 99import javax .persistence .Id ;
1010import javax .persistence .Table ;
1111
12- @ Setter
13- @ Getter
1412@ AllArgsConstructor
1513@ NoArgsConstructor
14+ @ Setter
15+ @ Getter
1616@ Table
1717@ Entity
1818public class Book {
@@ -23,4 +23,5 @@ public class Book {
2323 private String publisher ;
2424 private String [] authors ;
2525 private String publishedDate ;
26+
2627}
Original file line number Diff line number Diff line change @@ -18,6 +18,6 @@ public Book get(DataFetchingEnvironment dataFetchingEnvironment) {
1818
1919 String isn = dataFetchingEnvironment .getArgument ("id" );
2020
21- return bookRepository .findOne (isn );
21+ return bookRepository .findById (isn ). get ( );
2222 }
2323}
You can’t perform that action at this time.
0 commit comments