Skip to content

Commit 25dc314

Browse files
committed
feat: created relationship of posts to users + now can query all posts a user made
1 parent c56a32e commit 25dc314

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

server/schema/schema.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const {GraphQLObjectType, GraphQLID, GraphQLString, GraphQLInt, GraphQLSchema, GraphQLBoolean} = require('graphql');
1+
const {GraphQLObjectType, GraphQLID, GraphQLString, GraphQLInt, GraphQLSchema, GraphQLBoolean, GraphQLList} = require('graphql');
22
var _ = require('lodash');
33

44
// dummy data
@@ -34,7 +34,14 @@ const UserType = new GraphQLObjectType({
3434
id: {type: GraphQLString},
3535
name: {type: GraphQLString},
3636
age: {type: GraphQLInt},
37-
profession: {type: GraphQLString}
37+
profession: {type: GraphQLString},
38+
39+
posts:{
40+
type: new GraphQLList(PostType),
41+
resolve(parent, args){
42+
return _.filter(postData, {userId: parent.id});
43+
}
44+
}
3845
})
3946
});
4047

0 commit comments

Comments
 (0)