@@ -16,7 +16,12 @@ var hobbyData = [
1616 { id : '3' , title : 'Swimming' , description : 'Get in the ware and learn to become the water' , } ,
1717 { id : '4' , title : 'Fencing' , description : 'A hobby for fency people' , } ,
1818 { id : '5' , title : 'Programming' , description : 'Wear hiking boots and explore the world' , } ,
19-
19+ ] ;
20+
21+ var postData = [
22+ { id : '1' , comment : 'Building a Mind' , } ,
23+ { id : '2' , comment : 'GraphQL is Amazing' , } ,
24+ { id : '3' , comment : 'How to Change the World' , } ,
2025] ;
2126
2227// create types
@@ -41,6 +46,15 @@ const HobbyType = new GraphQLObjectType({
4146 } )
4247} ) ;
4348
49+ const PostType = new GraphQLObjectType ( {
50+ name : 'Post' ,
51+ description : 'Post description' ,
52+ fields : ( ) => ( {
53+ id : { type : GraphQLID } ,
54+ comment : { type : GraphQLString } ,
55+ } )
56+ } ) ;
57+
4458// RootQuery
4559const RootQuery = new GraphQLObjectType ( {
4660 name : 'RootQueryType' ,
@@ -54,8 +68,6 @@ const RootQuery = new GraphQLObjectType({
5468
5569 return _ . find ( userData , { id : args . id } ) ;
5670
57- // we resolve with data
58- // get and return data from a datasource
5971 }
6072 } ,
6173
@@ -68,7 +80,19 @@ const RootQuery = new GraphQLObjectType({
6880 return _ . find ( hobbyData , { id : args . id } ) ;
6981
7082 }
71- }
83+ } ,
84+
85+ post :{
86+ type : PostType ,
87+ args : { id : { type : GraphQLID } } ,
88+
89+ resolve ( parent , args ) {
90+
91+ return _ . find ( postData , { id : args . id } ) ;
92+
93+ }
94+ } ,
95+
7296 }
7397} ) ;
7498
0 commit comments