GraphQL schema file added, fix of PostResolver

- graphqls was missing
- author in Post is mandatory
This commit is contained in:
Tomas Skalicky 2020-11-21 09:51:59 +01:00
parent 689d301fed
commit 94aa14c43a
2 changed files with 26 additions and 4 deletions

View File

@ -1,7 +1,5 @@
package com.baeldung.graphql;
import java.util.Optional;
import com.coxautodev.graphql.tools.GraphQLResolver;
public class PostResolver implements GraphQLResolver<Post> {
@ -11,7 +9,7 @@ public class PostResolver implements GraphQLResolver<Post> {
this.authorDao = authorDao;
}
public Optional<Author> getAuthor(Post post) {
return authorDao.getAuthor(post.getAuthorId());
public Author getAuthor(Post post) {
return authorDao.getAuthor(post.getAuthorId()).orElseThrow(RuntimeException::new);
}
}

View File

@ -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!
}