File tree 7 files changed +105
-32
lines changed
src/main/java/com/br/study 7 files changed +105
-32
lines changed Original file line number Diff line number Diff line change 34
34
mvnw
35
35
.mvn *
36
36
* .cmd
37
+ .DS_Store
Original file line number Diff line number Diff line change
1
+ #
2
+
3
+ [ ![ GitHub stars] ( https://img.shields.io/github/stars/netodeolino/study-graphql )] ( https://github.com/netodeolino/study-graphql/stargazers )
4
+ [ ![ GitHub issues] ( https://img.shields.io/github/issues/netodeolino/study-graphql )] ( https://github.com/netodeolino/study-graphql/issues )
5
+ [ ![ GitHub forks] ( https://img.shields.io/github/forks/netodeolino/study-graphql )] ( https://github.com/netodeolino/study-graphql/network )
6
+
7
+ <p align =" center " >
8
+ <h2 align =" center " >Spring Boot - GraphQL Study</h2 >
9
+ </p >
10
+
11
+
12
+ ### Info
13
+
14
+ 1 . Schema
15
+ ```
16
+ http://localhost:8080/graphql/schema.json
17
+ ```
18
+ 2 . GraphQL endpoint
19
+ ```
20
+ http://localhost:8080/graphql
21
+ ```
22
+
23
+ #### Create User
24
+ ``` graphql
25
+ mutation {
26
+ createUser (user : {
27
+ name : " Neto" ,
28
+ email : " neto@email.com"
29
+ }) {
30
+ name ,
31
+ email
32
+ }
33
+ }
34
+ ```
35
+
36
+ #### Create Book
37
+ ``` graphql
38
+ mutation {
39
+ createBook (email : " neto@email.com" , book : {
40
+ title : " GraphQL For You"
41
+ }) {
42
+ title
43
+ }
44
+ }
45
+ ```
46
+
47
+ #### Find User
48
+ ``` graphql
49
+ query {
50
+ findUser (email : " neto@email.com" ) {
51
+ email
52
+ name
53
+ books {
54
+ title
55
+ }
56
+ }
57
+ }
58
+ ```
59
+
60
+ #### Find Book
61
+ ``` graphql
62
+ query {
63
+ findBook (title : " GraphQL For You" ) {
64
+ title
65
+ userOwner {
66
+ name ,
67
+ email
68
+ }
69
+ }
70
+ }
71
+ ```
Original file line number Diff line number Diff line change 30
30
</dependency >
31
31
<dependency >
32
32
<groupId >com.graphql-java</groupId >
33
- <artifactId >graphql-java </artifactId >
34
- <version >6.0 </version >
33
+ <artifactId >graphql-spring-boot-starter </artifactId >
34
+ <version >5.0.2 </version >
35
35
</dependency >
36
36
<dependency >
37
37
<groupId >com.graphql-java</groupId >
38
38
<artifactId >graphql-java-tools</artifactId >
39
- <version >4.3.0</version >
40
- </dependency >
41
- <dependency >
42
- <groupId >com.graphql-java</groupId >
43
- <artifactId >graphql-java-servlet</artifactId >
44
- <version >4.7.0</version >
39
+ <version >5.2.4</version >
45
40
</dependency >
46
41
47
42
<dependency >
Original file line number Diff line number Diff line change 14
14
15
15
@ Entity
16
16
@ Table (name = "book" )
17
- @ Getter @ Setter @ NoArgsConstructor @ AllArgsConstructor
17
+ @ Getter
18
+ @ Setter
19
+ @ NoArgsConstructor
20
+ @ AllArgsConstructor
18
21
public class Book {
19
22
20
23
@ Id
21
- @ GeneratedValue (strategy = GenerationType .IDENTITY )
24
+ @ GeneratedValue (strategy = GenerationType .IDENTITY )
22
25
private Long id ;
23
-
26
+
24
27
private String title ;
25
-
28
+
26
29
@ ManyToOne
27
30
private User userOwner ;
28
31
Original file line number Diff line number Diff line change 17
17
18
18
@ Entity
19
19
@ Table (name = "user" )
20
- @ Getter @ Setter @ NoArgsConstructor @ AllArgsConstructor
20
+ @ Getter
21
+ @ Setter
22
+ @ NoArgsConstructor
23
+ @ AllArgsConstructor
21
24
public class User {
22
25
23
26
@ Id
24
- @ GeneratedValue (strategy = GenerationType .IDENTITY )
27
+ @ GeneratedValue (strategy = GenerationType .IDENTITY )
25
28
private Long id ;
26
-
29
+
27
30
private String name ;
28
31
private String email ;
29
-
32
+
30
33
@ OneToMany (mappedBy = "userOwner" , fetch = FetchType .EAGER )
31
34
private List <Book > books ;
32
35
}
Original file line number Diff line number Diff line change 12
12
public class BookService {
13
13
14
14
@ Autowired
15
- private BookRepository bookRepository ;
15
+ private BookRepository bookRepository ;
16
16
17
- @ Autowired
18
- private UserService userService ;
17
+ @ Autowired
18
+ private UserService userService ;
19
19
20
- public Book create (Book book , String email ){
21
- book .setUserOwner (this .userService .findUserByEmail (email ).get ());
22
- return this .bookRepository .save (book );
23
- }
20
+ public Book create (Book book , String email ) {
21
+ book .setUserOwner (this .userService .findUserByEmail (email ).get ());
22
+ return this .bookRepository .save (book );
23
+ }
24
24
25
- public Optional <Book > findBook (String title ) {
26
- return this .bookRepository .findByTitle (title );
27
- }
25
+ public Optional <Book > findBook (String title ) {
26
+ return this .bookRepository .findByTitle (title );
27
+ }
28
28
29
29
}
Original file line number Diff line number Diff line change @@ -13,12 +13,12 @@ public class UserService {
13
13
14
14
@ Autowired
15
15
private UserRepository userRepository ;
16
-
16
+
17
17
public User create (User user ) {
18
- return this .userRepository .save (user );
19
- }
18
+ return this .userRepository .save (user );
19
+ }
20
20
21
- public Optional <User > findUserByEmail (String email ) {
22
- return this .userRepository .findByEmail (email );
23
- }
21
+ public Optional <User > findUserByEmail (String email ) {
22
+ return this .userRepository .findByEmail (email );
23
+ }
24
24
}
You can’t perform that action at this time.
0 commit comments