Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
HELP.md
.gradle
/build/
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/

### STS ###
.apt_generated
Expand All @@ -10,17 +13,25 @@
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
/out/
out/
!**/src/main/**/out/
!**/src/test/**/out/

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
/.nb-gradle/

### VS Code ###
.vscode/
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 GraphQL Java
Copyright (c) 2024 GraphQL Java

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# Book details example
# Book details tutorial example


This is the source code for the "Getting started with GraphQL Java and Spring Boot" which
is available here: https://www.graphql-java.com/tutorials/getting-started-with-spring-boot/
This repository contains the source code for the tutorial "Getting started with GraphQL Java and Spring Boot" which is available here: https://www.graphql-java.com/tutorials/getting-started-with-spring-boot/
11 changes: 7 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
plugins {
id 'org.springframework.boot' version '2.7.1'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
id 'org.springframework.boot' version '3.2.1'
id 'io.spring.dependency-management' version '1.1.4'
}

group = 'com.graphql-java.tutorial'
group = 'com.graphqljava.tutorial'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'

java {
sourceCompatibility = '17'
}

repositories {
mavenCentral()
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 3 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
41 changes: 28 additions & 13 deletions gradlew

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 9 additions & 6 deletions gradlew.bat

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 5 additions & 17 deletions src/main/java/com/graphqljava/tutorial/bookDetails/Author.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,16 @@
import java.util.Arrays;
import java.util.List;

public class Author {
private String id;
private String firstName;
private String lastName;

public Author(String id, String firstName, String lastName) {
this.id = id;
this.firstName = firstName;
this.lastName = lastName;
}
record Author(String id, String firstName, String lastName) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Java 17 ftw


private static List<Author> authors = Arrays.asList(
new Author("author-1", "Joanne", "Rowling"),
new Author("author-2", "Herman", "Melville"),
new Author("author-3", "Anne", "Rice")
new Author("author-1", "Joanne", "Rowling"),
new Author("author-2", "Herman", "Melville"),
new Author("author-3", "Anne", "Rice")
);

public static Author getById(String id) {
return authors.stream().filter(author -> author.getId().equals(id)).findFirst().orElse(null);
return authors.stream().filter(author -> author.id().equals(id)).findFirst().orElse(null);
}

public String getId() {
return id;
}
}
29 changes: 5 additions & 24 deletions src/main/java/com/graphqljava/tutorial/bookDetails/Book.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,16 @@
import java.util.Arrays;
import java.util.List;

public class Book {

private String id;
private String name;
private int pageCount;
private String authorId;

public Book(String id, String name, int pageCount, String authorId) {
this.id = id;
this.name = name;
this.pageCount = pageCount;
this.authorId = authorId;
}
record Book(String id, String name, int pageCount, String authorId) {

private static List<Book> books = Arrays.asList(
new Book("book-1", "Harry Potter and the Philosopher's Stone", 223, "author-1"),
new Book("book-2", "Moby Dick", 635, "author-2"),
new Book("book-3", "Interview with the vampire", 371, "author-3")
new Book("book-1", "Harry Potter and the Philosopher's Stone", 223, "author-1"),
new Book("book-2", "Moby Dick", 635, "author-2"),
new Book("book-3", "Interview with the vampire", 371, "author-3")
);

public static Book getById(String id) {
return books.stream().filter(book -> book.getId().equals(id)).findFirst().orElse(null);
return books.stream().filter(book -> book.id().equals(id)).findFirst().orElse(null);
}

public String getId() {
return id;
}

public String getAuthorId() {
return authorId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@
import org.springframework.stereotype.Controller;

@Controller
public class BookController {
class BookController {

@QueryMapping
public Book bookById(@Argument String id) {
return Book.getById(id);
}

@SchemaMapping
public Author author(Book book) {
return Author.getById(book.getAuthorId());
return Author.getById(book.authorId());
}

}
1 change: 0 additions & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
spring.graphql.graphiql.enabled=true
spring.graphql.graphiql.path=/graphiql
2 changes: 1 addition & 1 deletion src/main/resources/graphql/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ type Author {
id: ID
firstName: String
lastName: String
}
}