1- const { GraphQLObjectType, GraphQLID, GraphQLString, GraphQLInt, GraphQLSchema, buildSchema} = require ( 'graphql' ) ;
1+ const { GraphQLObjectType, GraphQLID, GraphQLString, GraphQLInt, GraphQLSchema, buildSchema, GraphQLBoolean } = require ( 'graphql' ) ;
22var _ = require ( 'lodash' ) ;
33
44// dummy data
55var userData = [
6- { id : '1' , name : 'Bond' , age : 36 } ,
7- { id : '13' , name : 'Anna' , age : 26 } ,
8- { id : '211' , name : 'Bella' , age : 16 } ,
9- { id : '19' , name : 'Gina' , age : 26 } ,
10- { id : '150' , name : 'Georgina' , age : 36 } ,
6+ { id : '1' , name : 'Bond' , age : 36 , profession : 'Programmer' , } ,
7+ { id : '13' , name : 'Anna' , age : 26 , profession : 'Baker' , } ,
8+ { id : '211' , name : 'Bella' , age : 16 , profession : 'Mechanic' , } ,
9+ { id : '19' , name : 'Gina' , age : 26 , profession : 'Painter' , } ,
10+ { id : '150' , name : 'Georgina' , age : 36 , profession : 'Teacher' } ,
11+ ] ;
12+
13+ var hobbyData = [
14+ { id : '1' , title : 'Programming' , description : 'Using computers to make the world a better place' , } ,
15+ { id : '2' , title : 'Rowing' , description : 'Sweat and feel better before eating donoughts' , } ,
16+ { id : '3' , title : 'Swimming' , description : 'Get in the ware and learn to become the water' , } ,
17+ { id : '4' , title : 'Fencing' , description : 'A hobby for fency people' , } ,
18+ { id : '5' , title : 'Programming' , description : 'Wear hiking boots and explore the world' , } ,
19+
1120] ;
1221
1322// create types
@@ -18,6 +27,17 @@ const UserType = new GraphQLObjectType({
1827 id : { type : GraphQLString } ,
1928 name : { type : GraphQLString } ,
2029 age : { type : GraphQLInt } ,
30+ profession : { type : GraphQLString }
31+ } )
32+ } ) ;
33+
34+ const HobbyType = new GraphQLObjectType ( {
35+ name : 'Hobby' ,
36+ description : 'Hobby Description' ,
37+ fields : ( ) => ( {
38+ id : { type : GraphQLID } ,
39+ title : { type : GraphQLString } ,
40+ description : { type : GraphQLString }
2141 } )
2242} ) ;
2343
@@ -31,17 +51,23 @@ const RootQuery = new GraphQLObjectType({
3151 args : { id : { type : GraphQLString } } ,
3252
3353 resolve ( parent , args ) {
34- let user = {
35- id : '345' ,
36- age : 34 ,
37- name : 'Paul'
38- }
39-
40- return user ;
54+
55+ return _ . find ( userData , { id : args . id } ) ;
4156
4257 // we resolve with data
4358 // get and return data from a datasource
4459 }
60+ } ,
61+
62+ hobby :{
63+ type : HobbyType ,
64+ args : { id : { type : GraphQLID } } ,
65+
66+ resolve ( parent , args ) {
67+
68+ return _ . find ( hobbyData , { id : args . id } ) ;
69+
70+ }
4571 }
4672 }
4773} ) ;
0 commit comments