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: { author: {
type: AuthorType, type: AuthorType,
resolve (parent, args) { resolve (parent, args) {
// return _.find(authors, { id: parent.authorId }); return Author.findById(parent.authorId);
} }
} }
}) })
@ -35,7 +35,7 @@ const AuthorType = new GraphQLObjectType({
books: { books: {
type: new GraphQLList(BookType), type: new GraphQLList(BookType),
resolve (parent, args) { 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, type: BookType,
args: { id: { type: GraphQLID } }, args: { id: { type: GraphQLID } },
resolve (parent, args) { resolve (parent, args) {
// return _.find(books, { id: args.id }); return Book.findById(args.id);
} }
}, },
author: { author: {
type: AuthorType, type: AuthorType,
args: { id: { type: GraphQLID } }, args: { id: { type: GraphQLID } },
resolve (parent, args) { resolve (parent, args) {
// return _.find(authors, { id: args.id }); return Author.findById(args.id);
} }
}, },
books: { books: {
type: new GraphQLList(BookType), type: new GraphQLList(BookType),
resolve (parent, args) { resolve (parent, args) {
// return books; return Book.find({});
} }
}, },
authors: { authors: {
type: new GraphQLList(AuthorType), type: new GraphQLList(AuthorType),
resolve (parent, args) { resolve (parent, args) {
// return authors; return Author.find({});
} }
} }
} }