Skip to content

Commit 8ba9885

Browse files
committed
Added custom type Genres
1 parent 152c5b6 commit 8ba9885

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

schema/schema.js

+24
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,20 @@ const AuthorType = new GraphQLObjectType({
6161
})
6262
});
6363

64+
// Define a Genre type
65+
const GenreType = new GraphQLObjectType({
66+
name: 'Genre',
67+
fields: () => ({
68+
name: { type: GraphQLString },
69+
books: {
70+
type: new GraphQLList(BookType),
71+
resolve(parent, args) {
72+
return _.filter(books, { genre: parent.name })
73+
}
74+
}
75+
})
76+
})
77+
6478
// Define Root Queries
6579
// This defines how the user grapb data
6680
const RootQuery = new GraphQLObjectType({
@@ -99,6 +113,16 @@ const RootQuery = new GraphQLObjectType({
99113
resolve(parent, args) {
100114
return authors;
101115
}
116+
},
117+
genres: {
118+
type: new GraphQLList(GenreType),
119+
resolve(parent, args) {
120+
return _.uniqBy(books, 'genre').map(x => {
121+
return {
122+
name: x.genre
123+
}
124+
});
125+
}
102126
}
103127
}
104128
});

0 commit comments

Comments
 (0)