mirror of
https://github.com/seigler/graphql-playground
synced 2025-07-27 01:26:10 +00:00
feat(server): queries to mongoDB
This commit is contained in:
parent
fae058cc68
commit
420a4739eb
1 changed files with 6 additions and 6 deletions
|
@ -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({});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue