feat(server): queries to mongoDB

This commit is contained in:
Joshua Seigler 2020-01-29 01:10:07 -05:00
parent fae058cc68
commit 420a4739eb

View file

@ -20,7 +20,7 @@ const BookType = new GraphQLObjectType({
author: {
type: AuthorType,
resolve (parent, args) {
// return _.find(authors, { id: parent.authorId });
return Author.findById(parent.authorId);
}
}
})
@ -35,7 +35,7 @@ const AuthorType = new GraphQLObjectType({
books: {
type: new GraphQLList(BookType),
resolve (parent, args) {
// return _.filter(books, { authorId: parent.id });
return Book.find({ authorId: parent.id });
}
}
})
@ -48,26 +48,26 @@ const RootQuery = new GraphQLObjectType({
type: BookType,
args: { id: { type: GraphQLID } },
resolve (parent, args) {
// return _.find(books, { id: args.id });
return Book.findById(args.id);
}
},
author: {
type: AuthorType,
args: { id: { type: GraphQLID } },
resolve (parent, args) {
// return _.find(authors, { id: args.id });
return Author.findById(args.id);
}
},
books: {
type: new GraphQLList(BookType),
resolve (parent, args) {
// return books;
return Book.find({});
}
},
authors: {
type: new GraphQLList(AuthorType),
resolve (parent, args) {
// return authors;
return Author.find({});
}
}
}