Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- onSave(): void {
- let variables = {};
- let mutation = {};
- let msg = "";
- if (this.model.id) {
- // update
- variables = {
- id: this.model.id,
- name: this.model.name,
- genre: this.model.genre,
- authorId: this.model.authorId
- };
- mutation = updateBookMutation;
- msg = "Book updated";
- } else {
- // create
- variables = {
- name: this.model.name,
- genre: this.model.genre,
- authorId: this.model.authorId
- };
- mutation = addBookMutation;
- msg = "Book Added";
- }
- this.apollo.mutate({
- mutation: mutation,
- variables:variables,
- refetchQueries: [{
- query: getBooksQuery
- }]
- }).pipe(
- map ( results => mutation === updateBookMutation ? results.data['updateBook'] : results.data['addBook'] )
- ).subscribe( ({ id, name }) => {
- console.log(`${msg}:\n -Id (${id}) \n -Name (${name})`);
- });
- this.reset();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement