Skip to content

Instantly share code, notes, and snippets.

@kamilkisiela
Last active November 15, 2018 11:05
Show Gist options
  • Save kamilkisiela/b50b711019a8efe77ffd396a08023c4b to your computer and use it in GitHub Desktop.
Save kamilkisiela/b50b711019a8efe77ffd396a08023c4b to your computer and use it in GitHub Desktop.
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