Skip to content

Commit

Permalink
remove posts from new post
Browse files Browse the repository at this point in the history
  • Loading branch information
sarareisner committed Jun 20, 2017
1 parent 4bf1d89 commit c3b3e2b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
19 changes: 6 additions & 13 deletions src/app/posts/new-post/new-post.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import { ApolloQueryResult } from 'apollo-client';

import { GetPostsQuery, AddPostMutation, PostsInterface } from './new-post.graphql.ts';


@Component({
selector: 'new-post',
// moduleId:module.id,
templateUrl: './new-post.component.html',
styleUrls: ['./new-post.component.scss']
})
export class NewPostComponent implements OnInit {
public posts: ApolloQueryObservable<PostsInterface>;
public firstName: string;
public lastName: string;

Expand All @@ -37,16 +37,6 @@ export class NewPostComponent implements OnInit {
});
this.apollo = apollo;
}

ngOnInit() {
// Query users data with observable variables
this.posts = this.apollo.watchQuery<PostsInterface>({
query: GetPostsQuery,
})
// Return only users, not the whole ApolloQueryResult
.map(result => result.data.posts) as any;
}
//save new post
public save() {
this.apollo.mutate({
mutation: AddPostMutation,
Expand All @@ -55,14 +45,17 @@ export class NewPostComponent implements OnInit {
"title": this.title,
"content" :this.content
}
}
},
refetchQueries: [{
query: GetPostsQuery,
}],
})
.take(1)
.subscribe({
next: ({ data }) => {
console.log('got a new post', data);
// get new data
this.posts.refetch();
this.router.navigate(['/posts']);
}, error: (errors) => {
console.log('there was an error sending the query', errors);
}
Expand Down
1 change: 1 addition & 0 deletions src/app/posts/posts.graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface DeletePostInterface {
export interface PostsInterface {
posts: Array<{
title: string | null,
content: string | null
}> | null;
}

Expand Down

0 comments on commit c3b3e2b

Please sign in to comment.