File tree 1 file changed +24
-0
lines changed
1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -61,6 +61,20 @@ const AuthorType = new GraphQLObjectType({
61
61
} )
62
62
} ) ;
63
63
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
+
64
78
// Define Root Queries
65
79
// This defines how the user grapb data
66
80
const RootQuery = new GraphQLObjectType ( {
@@ -99,6 +113,16 @@ const RootQuery = new GraphQLObjectType({
99
113
resolve ( parent , args ) {
100
114
return authors ;
101
115
}
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
+ }
102
126
}
103
127
}
104
128
} ) ;
You can’t perform that action at this time.
0 commit comments