feat(server): add book-author connection

This commit is contained in:
Joshua Seigler 2020-01-28 23:44:11 -05:00
parent 995213d554
commit c3b89e918f

View file

@ -11,9 +11,9 @@ const {
// temp data // temp data
const books = [ const books = [
{ name: 'Name of the Wind', genre: 'Fantasy', id: '1' }, { name: 'Name of the Wind', genre: 'Fantasy', id: '1', authorId: '1' },
{ name: 'The Final Empire', genre: 'Fantasy', id: '2' }, { name: 'The Final Empire', genre: 'Fantasy', id: '2', authorId: '2' },
{ name: 'The Long Earth', genre: 'Sci-Fi', id: '3' } { name: 'The Long Earth', genre: 'Sci-Fi', id: '3', authorId: '3' }
]; ];
const authors = [ const authors = [
{ name: 'Patrick Rothfuss', age: 44, id: '1' }, { name: 'Patrick Rothfuss', age: 44, id: '1' },
@ -26,7 +26,13 @@ const BookType = new GraphQLObjectType({
fields: () => ({ fields: () => ({
id: { type: GraphQLID }, id: { type: GraphQLID },
name: { type: GraphQLString }, name: { type: GraphQLString },
genre: { type: GraphQLString } genre: { type: GraphQLString },
author: {
type: AuthorType,
resolve (parent, args) {
return _.find(authors, { id: parent.authorId });
}
}
}) })
}); });