Skip to content

Commit c5f5fa3

Browse files
committed
feat: created relationship between PostData and User. Each Post now has a UserID
1 parent 9786a66 commit c5f5fa3

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

server/schema/schema.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ var hobbyData = [
1919
];
2020

2121
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',},
22+
{id: '1', comment: 'Building a Mind', userId: '1'},
23+
{id: '2', comment: 'GraphQL is Amazing', userId: '1'},
24+
{id: '3', comment: 'How to Change the World', userId: '19'},
25+
{id: '4', comment: 'How to Change the World', userId: '211'},
26+
{id: '5', comment: 'How to Change the World', userId: '1'},
2527
];
2628

2729
// create types
@@ -52,6 +54,12 @@ const PostType = new GraphQLObjectType({
5254
fields: () => ({
5355
id: {type: GraphQLID},
5456
comment: {type: GraphQLString},
57+
user: {
58+
type: UserType,
59+
resolve(parent, args){
60+
return _.find(userData, {id: parent.userId});
61+
}
62+
}
5563
})
5664
});
5765

0 commit comments

Comments
 (0)