Skip to content

Commit 62a55f8

Browse files
committed
correção e finalização projeto
1 parent 82814a7 commit 62a55f8

File tree

7 files changed

+105
-32
lines changed

7 files changed

+105
-32
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,4 @@ build/
3434
mvnw
3535
.mvn*
3636
*.cmd
37+
.DS_Store

README.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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+
```

pom.xml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,13 @@
3030
</dependency>
3131
<dependency>
3232
<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>
3535
</dependency>
3636
<dependency>
3737
<groupId>com.graphql-java</groupId>
3838
<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>
4540
</dependency>
4641

4742
<dependency>

src/main/java/com/br/study/model/Book.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,18 @@
1414

1515
@Entity
1616
@Table(name = "book")
17-
@Getter @Setter @NoArgsConstructor @AllArgsConstructor
17+
@Getter
18+
@Setter
19+
@NoArgsConstructor
20+
@AllArgsConstructor
1821
public class Book {
1922

2023
@Id
21-
@GeneratedValue(strategy = GenerationType.IDENTITY)
24+
@GeneratedValue(strategy = GenerationType.IDENTITY)
2225
private Long id;
23-
26+
2427
private String title;
25-
28+
2629
@ManyToOne
2730
private User userOwner;
2831

src/main/java/com/br/study/model/User.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,19 @@
1717

1818
@Entity
1919
@Table(name = "user")
20-
@Getter @Setter @NoArgsConstructor @AllArgsConstructor
20+
@Getter
21+
@Setter
22+
@NoArgsConstructor
23+
@AllArgsConstructor
2124
public class User {
2225

2326
@Id
24-
@GeneratedValue(strategy = GenerationType.IDENTITY)
27+
@GeneratedValue(strategy = GenerationType.IDENTITY)
2528
private Long id;
26-
29+
2730
private String name;
2831
private String email;
29-
32+
3033
@OneToMany(mappedBy = "userOwner", fetch = FetchType.EAGER)
3134
private List<Book> books;
3235
}

src/main/java/com/br/study/service/BookService.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@
1212
public class BookService {
1313

1414
@Autowired
15-
private BookRepository bookRepository;
15+
private BookRepository bookRepository;
1616

17-
@Autowired
18-
private UserService userService;
17+
@Autowired
18+
private UserService userService;
1919

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+
}
2424

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+
}
2828

2929
}

src/main/java/com/br/study/service/UserService.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ public class UserService {
1313

1414
@Autowired
1515
private UserRepository userRepository;
16-
16+
1717
public User create(User user) {
18-
return this.userRepository.save(user);
19-
}
18+
return this.userRepository.save(user);
19+
}
2020

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+
}
2424
}

0 commit comments

Comments
 (0)