This repository was archived by the owner on Dec 4, 2017. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +21
-8
lines changed
public/docs/_examples/heroes-graphql/ts/app Expand file tree Collapse file tree 1 file changed +21
-8
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,10 @@ type Mutation {
21
21
updateHero (
22
22
heroId: Int!
23
23
): Hero
24
+
25
+ addHero (
26
+ heroName: String!
27
+ ): Hero
24
28
}
25
29
26
30
# we need to tell the server which types represent the root query
@@ -55,14 +59,23 @@ const resolveFunctions = {
55
59
}
56
60
} ,
57
61
Mutation : {
58
- // updateHero(root: any, params: any) {
59
- // const post = find(posts, { id: params.postId });
60
- // if (!post) {
61
- // throw new Error(`Couldn't find post with id ${params.postId}`);
62
- // }
63
- // post.votes += 1;
64
- // return post;
65
- // }
62
+ updateHero ( root : any , params : any ) {
63
+ let hero = find ( heroes , { id : params . heroId } ) ;
64
+ if ( ! hero ) {
65
+ throw new Error ( `Couldn't find post with id ${ params . heroId } ` ) ;
66
+ }
67
+ hero = params . heroId ;
68
+ return hero ;
69
+ } ,
70
+ addHero ( root : any , params : any ) {
71
+ const maxId = Math . max ( ...heroes . map ( ( hero ) => { return hero . id } ) ) ;
72
+ const newHero = {
73
+ name : params . heroName ,
74
+ id : maxId + 1
75
+ } ;
76
+ heroes . push ( newHero ) ;
77
+ return ( newHero ) ;
78
+ }
66
79
}
67
80
}
68
81
You can’t perform that action at this time.
0 commit comments