diff --git a/spring-boot-modules/spring-boot-libraries/src/main/java/com/baeldung/graphql/PostResolver.java b/spring-boot-modules/spring-boot-libraries/src/main/java/com/baeldung/graphql/PostResolver.java index dbfde330ea..329d1f469a 100644 --- a/spring-boot-modules/spring-boot-libraries/src/main/java/com/baeldung/graphql/PostResolver.java +++ b/spring-boot-modules/spring-boot-libraries/src/main/java/com/baeldung/graphql/PostResolver.java @@ -1,7 +1,5 @@ package com.baeldung.graphql; -import java.util.Optional; - import com.coxautodev.graphql.tools.GraphQLResolver; public class PostResolver implements GraphQLResolver { @@ -11,7 +9,7 @@ public class PostResolver implements GraphQLResolver { this.authorDao = authorDao; } - public Optional getAuthor(Post post) { - return authorDao.getAuthor(post.getAuthorId()); + public Author getAuthor(Post post) { + return authorDao.getAuthor(post.getAuthorId()).orElseThrow(RuntimeException::new); } } diff --git a/spring-boot-modules/spring-boot-libraries/src/main/resources/graphql/post.graphqls b/spring-boot-modules/spring-boot-libraries/src/main/resources/graphql/post.graphqls new file mode 100644 index 0000000000..0e42f7255c --- /dev/null +++ b/spring-boot-modules/spring-boot-libraries/src/main/resources/graphql/post.graphqls @@ -0,0 +1,24 @@ +type Post { + id: ID! + title: String! + text: String! + category: String + author: Author! +} + +type Author { + id: ID! + name: String! + thumbnail: String + posts: [Post]! +} + +# The Root Query for the application +type Query { + recentPosts(count: Int, offset: Int): [Post]! +} + +# The Root Mutation for the application +type Mutation { + writePost(title: String!, text: String!, category: String, author: String!) : Post! +}