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

Commit 69c0bc6

Browse files
committed
docs(cookbook/graphql): Add deleteHero mutation
1 parent 33b0bb8 commit 69c0bc6

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

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

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export class HeroesComponent implements OnInit {
4444
}
4545
}
4646
`,
47+
forceFetch: true
4748
}).subscribe((queryResult: ApolloQueryResult) => {
4849
this.heroes = queryResult.data.heroes;
4950
});
@@ -81,12 +82,23 @@ export class HeroesComponent implements OnInit {
8182

8283
// #docregion delete
8384
delete(hero: Hero): void {
84-
// this.heroService
85-
// .delete(hero.id)
86-
// .then(() => {
87-
// this.heroes = this.heroes.filter(h => h !== hero);
88-
// if (this.selectedHero === hero) { this.selectedHero = null; }
89-
// });
85+
86+
this.apollo.mutate({
87+
mutation: gql`
88+
mutation deleteHero($id: Int!) {
89+
deleteHero(id: $id) {
90+
id
91+
name
92+
}
93+
}
94+
`,
95+
variables: {
96+
id: hero.id
97+
}
98+
}).subscribe((mutationResult: ApolloQueryResult) => {
99+
this.heroes = this.heroes.filter(h => h !== hero);
100+
if (this.selectedHero === hero) { this.selectedHero = null; }
101+
});
90102
}
91103
// #enddocregion delete
92104

0 commit comments

Comments
 (0)