diff --git a/server/schema/schema.js b/server/schema/schema.js index 3a90c94..d125a0c 100644 --- a/server/schema/schema.js +++ b/server/schema/schema.js @@ -4,6 +4,8 @@ const _ = require('lodash'); const { GraphQLObjectType, GraphQLString, + GraphQLID, + GraphQLInt, GraphQLSchema } = graphql; @@ -13,25 +15,46 @@ const books = [ { name: 'The Final Empire', genre: 'Fantasy', id: '2' }, { name: 'The Long Earth', genre: 'Sci-Fi', id: '3' } ]; +const authors = [ + { name: 'Patrick Rothfuss', age: 44, id: '1' }, + { name: 'Brandon Sanderson', age: 42, id: '2' }, + { name: 'Terry Pratchett', age: 66, id: '3' } +]; const BookType = new GraphQLObjectType({ name: 'Book', fields: () => ({ - id: { type: GraphQLString }, + id: { type: GraphQLID }, name: { type: GraphQLString }, genre: { type: GraphQLString } }) }); +const AuthorType = new GraphQLObjectType({ + name: 'Author', + fields: () => ({ + id: { type: GraphQLID }, + name: { type: GraphQLString }, + age: { type: GraphQLInt } + }) +}); + const RootQuery = new GraphQLObjectType({ name: 'RootQueryType', fields: { book: { type: BookType, - args: { id: { type: GraphQLString } }, + args: { id: { type: GraphQLID } }, resolve (parent, { id }) { return _.find(books, { id }); } + }, + author: { + type: AuthorType, + args: { id: { type: GraphQLID } }, + resolve (parent, { id }) { + return _.find(authors, { id }); + } } } });