mirror of
https://github.com/seigler/graphql-playground
synced 2025-07-27 09:36:09 +00:00
feat(server): add book-author connection
This commit is contained in:
parent
995213d554
commit
c3b89e918f
1 changed files with 10 additions and 4 deletions
|
@ -11,9 +11,9 @@ const {
|
|||
|
||||
// temp data
|
||||
const books = [
|
||||
{ name: 'Name of the Wind', genre: 'Fantasy', id: '1' },
|
||||
{ name: 'The Final Empire', genre: 'Fantasy', id: '2' },
|
||||
{ name: 'The Long Earth', genre: 'Sci-Fi', id: '3' }
|
||||
{ name: 'Name of the Wind', genre: 'Fantasy', id: '1', authorId: '1' },
|
||||
{ name: 'The Final Empire', genre: 'Fantasy', id: '2', authorId: '2' },
|
||||
{ name: 'The Long Earth', genre: 'Sci-Fi', id: '3', authorId: '3' }
|
||||
];
|
||||
const authors = [
|
||||
{ name: 'Patrick Rothfuss', age: 44, id: '1' },
|
||||
|
@ -26,7 +26,13 @@ const BookType = new GraphQLObjectType({
|
|||
fields: () => ({
|
||||
id: { type: GraphQLID },
|
||||
name: { type: GraphQLString },
|
||||
genre: { type: GraphQLString }
|
||||
genre: { type: GraphQLString },
|
||||
author: {
|
||||
type: AuthorType,
|
||||
resolve (parent, args) {
|
||||
return _.find(authors, { id: parent.authorId });
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue