Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

Commit fb2a45b

Browse files
committed
docs(cookbook/graphql): Add updateHero mutation
1 parent 69c0bc6 commit fb2a45b

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

public/docs/_examples/heroes-graphql/ts/app/hero-detail.component.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import gql from 'graphql-tag';
1111

1212
import { Hero } from './hero';
1313
import { HeroService } from './hero.service';
14+
import { ApolloQueryResult } from 'apollo-client';
1415

1516
@Component({
1617
moduleId: module.id,
@@ -63,8 +64,23 @@ export class HeroDetailComponent implements OnInit {
6364

6465
// #docregion save
6566
save(): void {
66-
this.heroService.update(this.hero)
67-
.then(() => this.goBack());
67+
68+
this.apollo.mutate({
69+
mutation: gql`
70+
mutation updateHero($id: Int!, $name: String!) {
71+
updateHero(id: $id, name: $name) {
72+
id
73+
name
74+
}
75+
}
76+
`,
77+
variables: {
78+
id: this.hero.id,
79+
name: this.hero.name
80+
}
81+
}).subscribe((mutationResult: ApolloQueryResult) => {
82+
this.goBack();
83+
});
6884
}
6985
// #enddocregion save
7086

0 commit comments

Comments
 (0)