GraphQL schema file added, fix of PostResolver
- graphqls was missing - author in Post is mandatory
This commit is contained in:
parent
689d301fed
commit
94aa14c43a
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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!
|
||||
}
|
Loading…
Reference in New Issue