BAEL-5304: adding graphql-spqr module
This commit is contained in:
parent
837cf3194a
commit
72b79f5023
51
graphql/graphql-spqr/pom.xml
Normal file
51
graphql/graphql-spqr/pom.xml
Normal file
@ -0,0 +1,51 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.baeldung.graphql</groupId>
|
||||
<artifactId>graphql-spqr</artifactId>
|
||||
<version>1.0</version>
|
||||
<name>graphql-java</name>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
<version>${spring-boot-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
<version>${spring-boot-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.leangen.graphql</groupId>
|
||||
<artifactId>graphql-spqr-spring-boot-starter</artifactId>
|
||||
<version>${graphql-spqr-spring-boot-starter-version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<version>2.6.2</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<spring-boot-version>2.6.2</spring-boot-version>
|
||||
<graphql-spqr-spring-boot-starter-version>0.0.6</graphql-spqr-spring-boot-starter-version>
|
||||
</properties>
|
||||
</project>
|
@ -0,0 +1,11 @@
|
||||
package com.baeldung;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class SpringBootApp {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(SpringBootApp.class, args);
|
||||
}
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package com.baeldung.spqr;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class Book {
|
||||
private Integer id;
|
||||
private String author;
|
||||
private String title;
|
||||
|
||||
public Book(Integer id, String author, String title) {
|
||||
this.id = id;
|
||||
this.author = author;
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public Book() {
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getAuthor() {
|
||||
return author;
|
||||
}
|
||||
|
||||
public void setAuthor(String author) {
|
||||
this.author = author;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o)
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
return false;
|
||||
Book book = (Book) o;
|
||||
return id.equals(book.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id);
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package com.baeldung.spqr;
|
||||
|
||||
import io.leangen.graphql.annotations.GraphQLArgument;
|
||||
import io.leangen.graphql.annotations.GraphQLMutation;
|
||||
import io.leangen.graphql.annotations.GraphQLQuery;
|
||||
import io.leangen.graphql.spqr.spring.annotations.GraphQLApi;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@Service
|
||||
@GraphQLApi
|
||||
public class BookService implements IBookService {
|
||||
|
||||
Set<Book> books = new HashSet<>();
|
||||
|
||||
@GraphQLQuery(name = "getBookWithTitle")
|
||||
public Book getBookWithTitle(@GraphQLArgument(name = "title") String title) {
|
||||
return books.stream()
|
||||
.filter(book -> book.getTitle()
|
||||
.equals(title))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
@GraphQLQuery(name = "getAllBooks", description = "Get all books")
|
||||
public List<Book> getAllBooks() {
|
||||
return books.stream()
|
||||
.toList();
|
||||
}
|
||||
|
||||
@GraphQLMutation(name = "addBook")
|
||||
public Book addBook(@GraphQLArgument(name = "newBook") Book book) {
|
||||
books.add(book);
|
||||
return book;
|
||||
}
|
||||
|
||||
@GraphQLMutation(name = "updateBook")
|
||||
public Book updateBook(@GraphQLArgument(name = "modifiedBook") Book book) {
|
||||
books.remove(book);
|
||||
books.add(book);
|
||||
return book;
|
||||
}
|
||||
|
||||
@GraphQLMutation(name = "deleteBook")
|
||||
public boolean deleteBook(@GraphQLArgument(name = "book") Book book) {
|
||||
return books.remove(book);
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package com.baeldung.spqr;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface IBookService {
|
||||
Book getBookWithTitle(String title);
|
||||
|
||||
List<Book> getAllBooks();
|
||||
|
||||
Book addBook(Book book);
|
||||
|
||||
Book updateBook(Book book);
|
||||
|
||||
boolean deleteBook(Book book);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user