Last active
November 15, 2018 11:05
-
-
Save kamilkisiela/b50b711019a8efe77ffd396a08023c4b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Apollo } from 'apollo-angular'; | |
import gql from 'graphql-tag'; | |
interface Post { | |
id: string; | |
text: string; | |
} | |
interface PostQuery { | |
post: Post; | |
} | |
@Component({...}) | |
export class PostComponent { | |
@Input() postId: string; | |
post: Observable<Post>; | |
constructor(private apollo: Apollo) {} | |
ngOnInit() { | |
this.post = this.apollo.watchQuery<PostQuery>({ | |
query: gql` | |
query getPost ($id: String!) { | |
post(id: $id) { | |
id | |
text | |
} | |
} | |
`, | |
variables: { | |
id: this.postId | |
} | |
}) | |
.valueChanges | |
.pipe( | |
map(result => result.data.post) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment